"Multidimensional spaces are completely out of style these days, unlike genetics problems" — thought physicist Woll and changed his subject of study to bioinformatics. Analysing results of sequencing he faced the following problem concerning DNA sequences. We will further think of a DNA sequence as an arbitrary string of uppercase letters "A", "C", "G" and "T" (of course, this is a simplified interpretation).Let w be a long DNA sequence and s1, s2, ..., sm — collection of short DNA sequences. Let us say that the collection filters w iff w can be covered with the sequences from the collection. Certainly, substrings corresponding to the different positions of the string may intersect or even cover each other. More formally: denote by |w| the length of w, let symbols of w be numbered from 1 to |w|. Then for each position i in w there exist pair of indices l, r (1 ≤ l ≤ i ≤ r ≤ |w|) such that the substring w[l ... r] equals one of the elements s1, s2, ..., sm of the collection.Woll wants to calculate the number of DNA sequences of a given length filtered by a given collection, but he doesn't know how to deal with it. Help him! Your task is to find the number of different DNA sequences of length n filtered by the collection {si}.Answer may appear very large, so output it modulo 1000000009.

First line contains two integer numbers n and m (1 ≤ n ≤ 1000, 1 ≤ m ≤ 10) — the length of the string and the number of sequences in the collection correspondently.  Next m lines contain the collection sequences si, one per line. Each si is a nonempty string of length not greater than 10. All the strings consist of uppercase letters "A", "C", "G", "T". The collection may contain identical strings.

Output should contain a single integer — the number of strings filtered by the collection modulo 1000000009 (109 + 9).

NoteIn the first sample, a string has to be filtered by "A". Clearly, there is only one such string: "AA".In the second sample, there exist exactly two different strings satisfying the condition (see the pictures below).

program cf86c;
const
  mode=1000000009;
type
  dtnote=record
    son:array[1..4]of longint;
    cnt,fai,p,fl:longint;
    ch:longint;
  end;
var
  i,j,k,n,tot,m,kk,h,u:longint;
  ANS:INT64;
  ss:string;
  dt:array[0..1000]of dtnote;
  dl:array[0..1000]of longint;
  f:array[0..1000,0..100,0..10]of INT64;
function ha(c:char):longint;
begin
  if c='A' then exit(1);
  if c='C' then exit(2);
  if c='G' then exit(3);
  if c='T' then exit(4);
end;

procedure dtinsert;
var u,i,c:longint;
begin
  u:=1;
  for i:=1 to length(ss) do begin
    c:=ha(ss[i]);
    if dt[u].son[c]=0 then begin
      inc(tot);
      fillchar(dt[tot],sizeof(dt[tot]),0);
      dt[tot].p:=u;
      dt[u].son[c]:=tot;
      dt[tot].ch:=c;
      dt[tot].fl:=i;
    end;
    u:=dt[u].son[c];
  end;
  dt[u].cnt:=length(ss);;
end;

procedure setac;
var
  i,u,j,x:longint;
begin
  for j:=1 to 4 do dt[0].son[j]:=1;
  dt[1].fai:=0;

  dl[1]:=1;
  dl[0]:=1;
  for i:=1 to tot do begin
    x:=dl[i];
    for j:=1 to 4 do
      if dt[x].son[j]<>0 then begin
        inc(dl[0]);
        dl[dl[0]]:=dt[x].son[j];
      end;
    if i=1 then continue;

    u:=dt[dt[x].p].fai;
    while dt[u].son[dt[x].ch]=0 do u:=dt[u].fai;

    dt[x].fai:=dt[u].son[dt[x].ch];
    if dt[dt[x].fai].cnt>dt[x].cnt then
      dt[x].cnt:=dt[dt[x].fai].cnt;
  end;
end;

begin
  fillchar(dt[0],sizeof(dt[0]),0);
  dt[0].fl:=-100;
  fillchar(dt[1],sizeof(dt[1]),0);
  tot:=1;
  readln(n,m);
  for i:=1 to m do begin
    readln(ss);
    dtinsert;
  end;
  setac;
  f[0,1,0]:=1;
  for i:=0 to n-1 do
    for j:=1 to tot do
      for k:=0 to dt[j].fl do
        for h:=1 to 4 do begin
          u:=j;
          while dt[u].son[h]=0 do u:=dt[u].fai;
          kk:=k-(dt[j].fl-dt[u].fl);
          if (kk<0)or(u=0) then continue;
          u:=dt[u].son[h];
          if dt[u].fl-dt[u].cnt<=kk then kk:=dt[u].fl;
          f[i+1,u,kk]:=(f[i+1,u,kk]+f[i,j,k])mod mode;
        end;
  ans:=0;
  for i:=1 to tot do
    ans:=(ans+f[n,i,dt[i].fl])mod mode;
  writeln(ans);
end.

program cf86c;
const
  mode=1000000009;
type
  dtnote=record
    son:array[1..4]of longint;
    cnt,fai,p,fl,ch:longint;
  end;
var
  i,j,n,m,k,tot,kk,h,u:longint;
  ss:string;
  ans:int64;
  dt:array[0..100]of dtnote;
  dl:array[0..100]of longint;
  f:array[0..1000,0..100,0..10]of longint;
function haa(c:char):longint;
begin
  if c='A' then exit(1);
  if c='C' then exit(2);
  if c='T' then exit(3);
  if c='G' then exit(4);
end;

procedure dtinsert;
var
  u,c,i:longint;
begin
  u:=1;
  for i:=1 to length(ss) do begin
    c:=haa(ss[i]);
    if dt[u].son[c]=0 then begin
      inc(tot);
      fillchar(dt[tot],sizeof(dt[tot]),0);
      dt[tot].fl:=i;
      dt[tot].ch:=c;
      dt[u].son[c]:=tot;
      dt[tot].p:=u;
    end;
    u:=dt[u].son[c];
  end;
  dt[u].cnt:=length(ss);
end;

procedure setac;
var u,i,j,x:longint;
begin
  for j:=1 to 4 do dt[0].son[j]:=1;
  dt[1].fai:=0;
  dl[0]:=1;
  dl[1]:=1;
  for i:=1 to tot do begin
    x:=dl[i];
    for j:=1 to 4 do
      if dt[x].son[j]<>0 then begin
        inc(dl[0]);
        dl[dl[0]]:=dt[x].son[j];
      end;
    if i=1 then continue;

    u:=dt[dt[x].p].fai;
    while dt[u].son[dt[x].ch]=0 do u:=dt[u].fai;
    u:=dt[u].son[dt[x].ch];
    dt[x].fai:=u;
    if dt[u].cnt>dt[x].cnt then dt[x].cnt:=dt[u].cnt;
  end;
end;

begin
  fillchar(dt[0],sizeof(dt[0]),0);
  fillchar(dt[1],sizeof(dt[1]),0);
  tot:=1;
  readln(n,m);
  for i:=1 to m do begin
    readln(ss);
    dtinsert;
  end;

  setac;
  //fillchar(f,sizeof(f),0);
  f[0,1,0]:=1;

  for i:=0 to n-1 do
    for j:=1 to tot do
      for k:=0 to dt[j].fl do
        for h:=1 to 4 do begin
          u:=j;
          while dt[u].son[h]=0 do u:=dt[u].fai;
          kk:=k-(dt[j].fl-dt[u].fl);
          if (kk<0)or(u=0) then continue;
          u:=dt[u].son[h];
          if dt[u].fl-dt[u].cnt<=kk then kk:=dt[u].fl;
          f[i+1,u,kk]:=(f[i+1,u,kk]+f[i,j,k])mod mode;

        end;

  ans:=0;
  for i:=1 to tot do
    ans:=(ans+f[n,i,dt[i].fl])mod mode;
  writeln(ans);
end.

uses math;
const md = 1000000009;
  DEBAG_ON = false;
  DEBAG_ON_1 = false;
var
s:string;
jj,tt,j,p,ne,aa,i,n,m,size:longint;
next,go:array[0..1000,0..4]of longint;
eend,len,pred,link,pch:array[0..1000]of longint;

st:array[0..1000]of string;

ans:array[0..1001,0..11,0..101]of longint;

procedure add(s:string);
var t,i,x:longint;
 begin
  t:=1;
  for i:=1 to length(s) do
    begin
     if s[i]='A' then x:=0;
     if s[i]='C' then x:=1;
     if s[i]='G' then x:=2;
     if s[i]='T' then x:=3;

     if next[t,x]=0 then
       begin
        size:=size+1;
        if DEBAG_ON then
        st[size]:=st[t]+s[i];
        next[t,x]:=size;
        pch[size]:=x;
        pred[size]:=t;
       end;

     t:=next[t,x];
    end;

  len[t]:=length(s);
  eend[t]:=1;
 end;

function fgo(x,y:longint):longint; forward;

function flink(x:longint):longint;
 begin
  if link[x]=0 then
    if (x=1)or(pred[x]=1) then link[x]:=1
                          else link[x]:=fgo(flink(pred[x]),pch[x]);

  flink:=link[x];
 end;

function fgo(x,y:longint):longint;
 begin
  if go[x,y]=0 then
     if next[x,y]>1 then go[x,y]:=next[x,y]
      else if x=1 then go[x,y]:=1 else go[x,y]:=fgo(flink(x),y);

  fgo:=go[x,y];
 end;

function leng(x:longint):longint;
 begin
  if x=1 then leng:=0
  else leng:=max(len[x],leng(flink(x)));
 end;

 begin
  readln(n,m);
  size:=1;
  for i:=1 to m do
    begin
     readln(s);
     add(s);
    end;

  if DEBAG_ON then
    begin
     for i:=1 to size do
       writeln(i,' ',st[i],' ',flink(i),' ',leng(i),' ',len[i]);
    end;

  ans[1,0,1]:=1;

  for i:=1 to n do
    begin
     for j:=0 to min(10,i) do
       begin
        for p:=1 to size do
          begin
           if ans[i,j,p]=0 then continue;

           if DEBAG_ON_1 then
           writeln(i,' ',j,' ',p,' ',ans[i,j,p]);
            for ne:=0 to 3 do
               begin
                tt:=fgo(p,ne);
                jj:=j+1;
                if (leng(tt)>=jj) then jj:=0;

                if DEBAG_ON_1 then
                writeln('>>> symb:',ne,', new pos:',tt,' length:',len[tt],' count:',jj);

                ans[i+1,jj,tt]:=(ans[i+1,jj,tt]+ans[i,j,p])mod md;
               end;
          end;
       end;
    end;
  aa:=0;
  for i:=1 to size do
    aa:=(aa+ans[n+1,0,i])mod md;

  writeln(aa);
 end.

const bigp=1000000009;

type autoac=^pear;
     pear=record
            flag,depth,num,ti:longint;
            back,father:autoac;
            child:array[1..4] of autoac;
          end;

var root,p,q:autoac;
    m,n,i,j,k,tt,ls,rc,fc,sc,ans:longint;
    f:array[0..1010,0..300,0..15] of longint;
    u:array[0..10000] of autoac;
    s:string;
    ch:char;

procedure doit(p:autoac;s:longint);
  var i,j,c1,c2:longint;
      q:autoac;
  begin
    if (s=0) or (p<>root) then
      begin
        for i:=1 to 4 do
          begin
            c1:=p^.ti;
            q:=p;
            while (q<>root) and (q^.child[i]=nil) do q:=q^.back;
            if q^.child[i]<>nil then
              q:=q^.child[i];
            c2:=q^.ti;
            for j:=0 to 10 do
              if f[s,c1,j]>0 then
                begin
                  if (q^.flag=1) and (q^.depth>j) then
                    f[s+1,c2,0]:=(f[s+1,c2,0]+f[s,c1,j]) mod bigp
                  else
                    f[s+1,c2,j+1]:=(f[s+1,c2,j+1]+f[s,c1,j]) mod bigp;
                end;
          end;
      end;
    for i:=1 to 4 do
      if p^.child[i]<>nil then
        doit(p^.child[i],s);
  end;

procedure solve(p:autoac);
  var i:longint;
  begin
    if p^.flag=1 then
      ans:=(ans+f[n,p^.ti,0]) mod bigp;
    for i:=1 to 4 do
      if p^.child[i]<>nil then
        solve(p^.child[i]);
  end;

begin
  new(root);
  root^.father:=root;
  root^.back:=root;
  root^.num:=0;
  root^.ti:=1;
  root^.depth:=0;
  root^.flag:=0;
  for i:=1 to 4 do
    root^.child[i]:=nil;
  readln(n,m);
  tt:=1;
  for i:=1 to m do
    begin
      readln(s);
      p:=root;
      ls:=length(s);
      for j:=1 to ls do
        begin
          ch:=s[j];
          if ch='A' then sc:=1;
          if ch='C' then sc:=2;
          if ch='G' then sc:=3;
          if ch='T' then sc:=4;
          if p^.child[sc]=nil then
            begin
              new(q);
              q^.father:=p;
              q^.back:=nil;
              for k:=1 to 4 do
                q^.child[k]:=nil;
              inc(tt);
              q^.ti:=tt;
              q^.num:=sc;
              q^.flag:=0;
              p^.child[sc]:=q;
              p:=q;
            end
          else
            p:=p^.child[sc];
        end;
      p^.flag:=1;
      p^.depth:=ls;
    end;
  rc:=1;
  fc:=1;
  u[rc]:=root;
  while rc<=fc do
    begin
      if u[rc]<>root then
        begin
          p:=u[rc]^.father^.back;
          sc:=u[rc]^.num;
          while (p<>root) and (p^.child[sc]=nil) do p:=p^.back;
          if (p^.child[sc]<>nil) and (p^.child[sc]<>u[rc]) then p:=p^.child[sc];
          u[rc]^.back:=p;
          p:=u[rc];
          if p^.flag=0 then
            begin
              q:=p^.back;
              while (q<>root) and (q^.flag=0) do q:=q^.back;
              if q^.flag=1 then
                begin
                  p^.flag:=1;
                  p^.depth:=q^.depth;
                end;
            end;
        end;
      for i:=1 to 4 do
        if u[rc]^.child[i]<>nil then
          begin
            inc(fc);
            u[fc]:=u[rc]^.child[i];
          end;
      inc(rc);
    end;
  fillchar(f,sizeof(f),0);
  f[0,1,0]:=1;
  for i:=0 to n-1 do
    doit(root,i);
  ans:=0;
  solve(root);
  writeln(ans);
end.

program xj;

  const
    mo=1000000009;

  var
    son:array[0..1000,1..4]of longint;
    flag:array[0..1000]of boolean;
    f:array[0..1000,0..120,0..12]of int64;
    q,next,list,dep,max:array[0..1000]of longint;
    i,j,k,n,m,tot,x,y,nn,l1,l2,now,nex,kk:longint;
    st:string;
    ans:int64;

  procedure insert;
    var
      now,ii:longint;
    begin
      now:=0;
      for ii:=1 to nn do
        begin
          if son[now][list[ii]]=0
            then begin inc(tot);dep[tot]:=dep[now]+1;son[now][list[ii]]:=tot; end;
          now:=son[now][list[ii]];
        end;
      flag[now]:=true;
          max[now]:=nn;
    end;

  procedure get_ac;
  begin
   l1:=1;l2:=1;
   q[1]:=0;next[0]:=-1;
   while l1<=l2 do
    begin
     now:=q[l1];
     x:=now;
     while x<>-1 do
       begin
         if max[x]>max[now]
           then max[now]:=max[x];
         x:=next[x];
       end;
     for k:=1 to 4 do
       begin
         nex:=son[now][k];
         if nex<>0
           then
             begin
               inc(l2);q[l2]:=nex;
               x:=next[now];
               while (x<>-1)and(son[x][k]=0) do  x:=next[x];
               if x<>-1
                 then next[nex]:=son[x,k]
                 else next[nex]:=0;
             end
           else
             begin
               x:=next[now];
               while (x<>-1)and(son[x][k]=0) do
                 x:=next[x];
               if x=-1 then son[now][k]:=0
                       else son[now][k]:=son[x][k];
             end;
       end;
     inc(l1);
    end;
  end;

  procedure run_ac;
    var
      now:longint;
    begin
      fillchar(f,sizeof(f),0);
      f[0,0,0]:=1;
      for i:=0 to n-1 do
        for j:=0 to tot do
          for k:=0 to 9 do
            if f[i][j][k]>0
              then
                begin
                  for kk:=1 to 4 do
                    begin
                      nex:=son[j][kk];
                      if nex<>0
                        then
                          begin
                            if max[nex]>=k+1
                              then f[i+1][nex][0]:=(f[i+1][nex][0]+f[i][j][k]) mod mo
                              else if k+1<10 then f[i+1][nex][k+1]:=(f[i+1][nex][k+1]+f[i][j][k]) mod mo;
                          end;
                    end;
                end;
    end;

  begin
    readln(n,m);
    tot:=0;
    fillchar(flag,sizeof(flag),false);
        fillchar(max,sizeof(max),0);
    dep[0]:=0;
    for i:=1 to m do
      begin
        readln(st);
        nn:=length(st);
        for j:=1 to nn do
          case st[j] of
            'A':list[j]:=1;
            'C':list[j]:=2;
            'G':list[j]:=3;
            'T':list[j]:=4;
          end;
        insert;
      end;
    get_ac;
    run_ac;
    ans:=0;
    for i:=0 to tot do
      if f[n][i][0]>0
        then ans:=(ans+f[n][i][0]) mod mo;
    writeln(ans);
  end.

{$M 10000000}
const
  ABC='ACGT';
  base=1000000009;
var
  kolnum:longint;
  s:string;
  nexto,j,n,m,kb,i,x,o:longint;
  pow,link,pred,predch:array[0..555]of longint;
  leaf:array[0..555]of boolean;
  next:array[0..555,0..5]of longint;
  f:array[0..1111,0..11,0..111]of longint;
  procedure recl(x:longint);
    var
      i,ch:longint;
    begin
      if (link[x]<>-1)then exit;
      if (pred[x]=0)then begin
        link[x]:=0;
        exit;
      end;
      ch:=predch[x];
      i:=pred[x];
      if (link[i]=-1)then recl(i);
      i:=link[i];
      while (i>0)and(next[i][ch]=-1)do begin
        if (link[i]=-1)then recl(i);
        i:=link[i];
      end;
      if (next[i][ch]=-1)
        then i:=0
        else i:=next[i][ch];
      link[x]:=i;
    end;
  function next_bor(x,ch:longint):longint;
    begin
      while (x>0)and(next[x][ch]=-1)do x:=link[x];
      next_bor:=next[x][ch];
    end;
  function rec(i,k,x:longint):longint;
    var
      si,sk,sx,tt,nextx,ch,res:longint;
    begin
      if (f[i][k][x]<>-1)then begin
        rec:=f[i][k][x];
        exit;
      end;
      si:=i;sk:=k;sx:=x;
      if (pow[x]<k)then begin
        f[si][sk][sx]:=0;
        rec:=0;
        exit;
      end;
      tt:=x;
      while (tt>0)and(pow[tt]>=k)do begin
        if (leaf[tt])then begin
          k:=0;
          break;
        end;
        tt:=link[tt];
      end;
      if (i=n+1)and(k=0)then begin
        f[si][sk][sx]:=1;
        rec:=1;
        exit;
      end;
      if (i=n+1)then begin
        f[si][sk][sx]:=0;
        rec:=0;
        exit;
      end;
      res:=0;
      for ch:=1 to 4 do begin
        nextx:=next_bor(x,ch);
        if (nextx<0)then continue;
        res:=res+rec(i+1,k+1,nextx);
        if (res>=base)then dec(res,base);
      end;
      f[si][sk][sx]:=res;
      rec:=res;
      exit;
    end;
begin
  //assign(input,'input.txt');reset(input);
  //assign(output,'output.txt');rewrite(output);
  readln(n,m);
  kb:=0;
  fillchar(next,sizeof(next),$FF);
  fillchar(link,sizeof(link),$FF);
  fillchar(leaf,sizeof(leaf),false);
  link[0]:=0;
  pow[0]:=0;
  for i:=1 to m do begin
    readln(s);
    if (length(s)>n)then continue;
    x:=0;
    for j:=1 to length(s)do begin
      o:=pos(s[j],ABC);
      if (next[x][o]=-1)then begin
        inc(kb);
        next[x][o]:=kb;
      end;
      nexto:=next[x][o];
      pred[nexto]:=x;
      predch[nexto]:=o;
      pow[nexto]:=pow[x]+1;
      x:=nexto;
    end;
    leaf[x]:=true;
  end;
  for i:=0 to kb do recl(i);
  fillchar(f,sizeof(f),$FF);
  writeln(rec(1,0,0));
end.

uses math;
const cmod = 1000000009;

type Ttrie = ^kdl;
kdl = record
v:longint;
a:array['A'..'Z'] of TTrie;
kt:boolean;
l:longint;
st:string;
End;

const maxn=1010;
maxnode=1010;
var f1,f2:text;
A:array[1..maxn] of longint;
TNil:TTrie;
st:string;
Root:TTrie;
Next:array[1..maxn,'A'..'Z'] of longint;
F:array[0..maxn,0..20,1..maxnode] of longint;
Vis:array[0..maxn,0..20,1..maxnode] of boolean;
T:array[1..maxnode] of Ttrie;
Q:array[1..maxn] of TTrie;
fr,re:longint;
spt,m:longint;
res:longint;
n,i:longint;

Procedure init(var u:TTrie);
var ch:char;
begin
        new(u);
        for ch:='A' to 'Z' do
          u^.a[ch]:=nil;
        inc(spt);
        u^.v:=spt;
        u^.kt:=false;
        u^.l:=0;
        u^.st:='';
        T[spt]:=u;
end;

Function Search(st:string):longint;
var p:TTrie;
i:longint;
begin
        p:=root;
        for i:=1 to length(st) do
          if p^.a[st[i]]<>nil then p:=p^.a[st[i]] else exit(-1);
        Search:=p^.v;
end;

Procedure BFS;
var p:TTrie;
ch:char;
x:longint;
j:longint;
st:string;
u:TTrie;
begin

        fr:=0;re:=1;
        Q[1]:=Root;
        REpeat
          inc(Fr);
          u:=Q[Fr];
          For j:=2 to length(u^.st)+1 do
            begin
              x:=search(copy(u^.st,j,length(u^.st)-j+1));
              if x<>-1 then
              Begin
                if T[x]^.kt then
                Begin
                  u^.kt:=true;
                  u^.l:=max(u^.l,T[x]^.l);
                End;
              End;
            End;
        for ch:='A' to 'Z' do
        Begin
          Next[u^.v,ch]:=1;
          For j:=2 to length(u^.st)+1 do
            begin
              x:=search(copy(u^.st,j,length(u^.st)-j+1)+ch);
              if x<>-1 then
              Begin
                Next[u^.v,ch]:=x;
                break;
              End;
            End;
        End;
        for ch:='A' to 'Z' do
          if u^.a[ch]<>nil then
          Begin
            Next[u^.v,ch]:=u^.A[ch]^.v;
            inc(RE);
            Q[Re]:=u^.a[ch];
          End;
      Until Fr>=re;
end;

Procedure Push;
var j:longint;
p:TTrie;
u:longint;
begin
        p:=root;
          For j:=1 to length(st) do
          begin
            if p^.a[st[j]]=nil then Begin
            init(p^.a[st[j]]);
            p^.a[st[j]]^.st:=p^.st+st[j]; End;
            p:=p^.a[st[j]]
          end;
        p^.kt:=true;
        p^.l:=length(st);
end;

Function Rec(i,k,j:longint):longint; {den i con k , nut j}
var ch:char;
p:TTrie;
begin
        if (i=n) and (k=0) then F[i,k,j]:=1;
        if (i=n) then
        exit(longint(k=0));
        if k>10 then exit(0);
        if Vis[i,k,j] then exit(F[i,k,j]);
        Vis[i,k,j]:=true;
        for ch:='A' to 'Z' do
        begin
          if Next[j,ch]<>0 then
          Begin
            p:=T[Next[j,ch]];
            if p^.kt then
            Begin
              if k+1<=p^.l then
              F[i,k,j]:=(F[i,k,j]+Rec(i+1,0,Next[j,ch])) mod cmod
              else
              F[i,k,j]:=(F[i,k,j]+Rec(i+1,k+1,next[j,ch])) mod cmod;
            end
            else
            if Next[j,ch]<>1 then
            F[i,k,j]:=(F[i,k,j]+Rec(i+1,k+1,Next[j,ch])) mod cmod;
          End;
        End;
        Rec:=F[i,k,j];

end;

Procedure DP;
var i,j:longint;
ch:char;
begin
        fillchar(vis,sizeof(vis),false);
        writeln(f2,Rec(0,0,1));
end;

begin
        assign(f1,'');reset(f1);
        assign(f2,'');rewrite(f2);
        readln(f1,n,m);
        Init(root);
        for i:=1 to m do
        Begin
          readln(F1,st);
          push;
        End;
        BFS;
        DP;
        close(f1);
        close(f2);
end.

{$mode objfpc}
const pm=1000000009;

function trans(const ch:char):longint;
begin case ch of
		'A':	exit(0);
		'C':	exit(1);
		'G':	exit(2);
		'T':	exit(3);
	end;
end;

type
	dfa=	object
			ep,root:longint;
			b:array[0..10010] of record
								next:array[0..3] of longint;
								depth,fail:longint;
								flag:boolean;
							end;
			q:array[0..10010] of longint;
			function Create(x:longint):longint;
			procedure init();
			procedure ins(const s:string);
			procedure build();
		end;

	function dfa.Create(x:longint):longint;
	begin inc(ep); fillchar(b[ep].next,sizeof(b[ep].next),255);
		b[ep].depth:=x; b[ep].fail:=-1; b[ep].flag:=false; exit(ep);
	end;

	procedure dfa.init();
	begin ep:=0; root:=Create(0); end;

	procedure dfa.ins(const s:string);
	var cur,i,x:longint;
	begin cur:=root;
		for i:=1 to length(s) do
		begin x:=trans(s[i]);
			if b[cur].next[x]=-1 then b[cur].next[x]:=Create(b[cur].depth+1);
			cur:=b[cur].next[x];
		end;
		b[cur].flag:=true;
	end;

	procedure dfa.build();
	var head,tail,cur,i:longint;
	begin head:=1; tail:=2; q[head]:=root; b[root].fail:=-1;
		while head<tail do
		begin cur:=q[head]; inc(head);
			for i:=0 to 3 do
			begin if b[cur].next[i]<>-1 then begin q[tail]:=b[cur].next[i]; inc(tail); end;
				if b[cur].fail=-1 then
					if b[cur].next[i]=-1 then
						b[cur].next[i]:=root
					else  b[b[cur].next[i]].fail:=root
				else  if b[cur].next[i]=-1 then
						b[cur].next[i]:=b[b[cur].fail].next[i]
					else  b[b[cur].next[i]].fail:=b[b[cur].fail].next[i];
			end;
		end;
	end;

var
ac:dfa;
ss:string;
dp:array[0..1010,0..110,0..11] of longint;

procedure lemon();
var n,m,i,node,L,k,x,y,ans:longint;
    ff:boolean;
begin readln(n,m);
	ac.init();
	for i:=1 to m do begin readln(ss); ac.ins(ss); end;
	//dp[n][node][L]	length(n) string having suffix(node) and the first L letters of the suffix have been covered
	ac.build();
	with ac do
	begin dp[0][1][0]:=1;
		for i:=0 to n-1 do
			for node:=1 to ep do
				for L:=0 to 10 do
					if dp[i,node,L]>0 then
						for k:=0 to 3 do
						begin //writeln(i,' ',node,' ',L,' ',k,' ',b[node].next[k]);
							y:=b[node].next[k]; if y=-1 then continue;
							ff:=false;
							while y<>-1 do
							begin if (b[y].flag)and(b[y].depth>=L+1) then
								begin ff:=true;
									break;
								end;
								y:=b[y].fail;
							end;
							y:=b[node].next[k];
							if ff then
							begin inc(dp[i+1,y,0],dp[i,node,L]);
								if dp[i+1,y,0]>=pm then dec(dp[i+1,y,0],pm);
							 end
							else begin
								inc(dp[i+1,y,L+1],dp[i,node,L]);
								if dp[i+1,y,L+1]>=pm then dec(dp[i+1,y,L+1],pm);
							end;
						end;
	end;
	ans:=0;
	for i:=1 to ac.ep do ans:=(ans+dp[n,i,0]) mod pm;
	writeln(ans);
end;

begin
{$ifndef ONLINE_JUDGE}
	assign(input,'86C.in');
	reset(input);
{$endif}
lemon();
end.

{$R+,S+,Q+,I+,O-}
{R-,S-,Q-,I-,O+}
const md = round(1e9+9);
      let: string = 'ACGT';
var
  ans,ii,jj,kk,max,km,nn,m,n,i,j,t,q,k: longint;
  dd: boolean;
  sw,s: array [0..110] of string;
  ss,st: string;
  a: array [0..110,'A'..'Z'] of longint;
  fn: array [0..110,0..110] of longint;
  maxw,pv,de,len: array [0..110] of longint;
  pc: array [0..110] of char;
  f: array [0..1010,0..110,0..11] of longint;
begin
//  assign(input,'in'); reset(input);
//  assign(output,'out'); rewrite(output);
  readln(nn,m);
  fillchar(a,sizeof(a),0);
  fillchar(maxw,sizeof(maxw),0);
  n:=1;
  de[1]:=0;
  for i:=1 to m do
  begin
    readln(s[i]);
    len[i]:=length(s[i]);
    t:=1;
    for j:=1 to len[i] do
    begin
      if a[t,s[i,j]] = 0 then
      begin
        inc(n);
        pv[n]:=t;
        pc[n]:=s[i,j];
        de[n]:=de[t]+1;
        a[t,s[i,j]]:=n;
      end;
      t:=a[t,s[i,j]];
    end;
    maxw[t]:=len[i];
  end;
  sw[1]:='';
  for i:=2 to n do sw[i]:=sw[pv[i]]+pc[i];
  dd:=True;
  while dd do
  begin
    dd:=False;
    for i:=1 to n do
      if maxw[i] > 0 then
        for j:=1 to n do
          if length(sw[j]) > length(sw[i]) then
            if Copy(sw[j],length(sw[j])-length(sw[i])+1,length(sw[i])) = sw[i] then
              if maxw[i] > maxw[j] then
              begin
                maxw[j]:=maxw[i];
                dd:=True;
              end;
  end;
  for i:=1 to n do
    for q:=1 to 4 do
    begin
      st:='';
      t:=i;
      while t > 1 do
      begin
        st:=pc[t]+st;
        t:=pv[t];
      end;
      st:=st+let[q];
      max:=0; km:=1;
      for ii:=2 to n do
      begin
        ss:=''; t:=ii;
        while t > 1 do
        begin
          ss:=pc[t]+ss;
          t:=pv[t];
        end;
        if length(ss) > length(st) then continue;
        if Copy(st,length(st)-length(ss)+1,length(ss)) = ss then
          if length(ss) > max then
          begin
            max:=length(ss);
            km:=ii;
          end;
      end;
      fn[i,q]:=km;
    end;
  fillchar(f,sizeof(f),0);
  f[0,1,0]:=1;
  for i:=0 to nn-1 do
    for j:=1 to n do
      for k:=0 to de[j] do
        if f[i,j,k] > 0 then
          for q:=1 to 4 do
          begin
            ii:=i+1;
            jj:=fn[j,q];
            kk:=k+1;
            if maxw[jj] >= k+1 then kk:=0;
            inc(f[ii,jj,kk],f[i,j,k]);
            if f[ii,jj,kk] >= md then dec(f[ii,jj,kk],md);
          end;
  ans:=0;
  for i:=1 to n do ans:=(ans+f[nn,i,0]) mod md;
  writeln(ans);
  close(input);
  close(output);
end.

const mode=1000000009;
var tot,n,m,now:longint;
trie1,trie2:array[0..1000,1..4]of longint;
fail,q,danger:array[0..100]of longint;
f:array[0..1000,0..100,0..10]of longint;
function getmax(a,b:longint):longint;
begin
  if a>b then getmax:=a else getmax:=b;
end;
procedure insert(x:longint);
begin
  if trie1[now,x]=0 then
  begin
    inc(tot);
    trie1[now,x]:=tot;
    now:=tot;
  end else now:=trie1[now,x];
end;
procedure init;
var i,j:longint;
st:string;
begin
  tot:=1;
  readln(n,m);
  for i:=1 to m do
  begin
    readln(st);
    now:=1;
    for j:=1 to length(st) do
    begin
      if st[j]='A' then insert(1);
      if st[j]='C' then insert(2);
      if st[j]='G' then insert(3);
      if st[j]='T' then insert(4);
    end;
    danger[now]:=length(st);
  end;
end;
procedure build;
var head,tail,i,x:longint;
begin
  trie2:=trie1;tail:=0;
  for i:=1 to 4 do
  begin
    if trie2[1,i]=0 then trie2[1,i]:=1
    else
    begin
      inc(tail);
      q[tail]:=trie2[1,i];
      fail[trie2[1,i]]:=1;
    end;
  end;
  head:=1;
  repeat
    x:=q[head];
    danger[x]:=getmax(danger[x],danger[fail[x]]);
    for i:=1 to 4 do
    begin
      if trie2[x,i]=0 then trie2[x,i]:=trie2[fail[x],i]
      else
      begin
        inc(tail);
        q[tail]:=trie2[x,i];
        fail[trie2[x,i]]:=trie2[fail[x],i];
      end;
    end;
    inc(head);
  until head>tail;
end;
procedure work;
var i,j,k,ans,v:longint;
begin
  f[0,1,0]:=1;
  for i:=0 to n-1 do
    for j:=1 to tot do
      for v:=0 to 9 do
      begin
        if f[i,j,v]=0 then continue;
        for k:=1 to 4 do
        begin
          if trie2[j,k]=1 then continue;
          if danger[trie2[j,k]]>v then f[i+1,trie2[j,k],0]:=(f[i+1,trie2[j,k],0]+f[i,j,v])mod mode
          else f[i+1,trie2[j,k],v+1]:=(f[i+1,trie2[j,k],v+1]+f[i,j,v])mod mode;
        end;
      end;
  ans:=0;
  for i:=1 to tot do
    ans:=(ans+f[n,i,0])mod mode;
  writeln(ans);
end;
begin
  init;
  build;
  work;
end.

program cf86c;
const
  mode=1000000007;
type
  dtnote=record
    son:array[1..4]of longint;
    cnt,fai,p,fl:longint;
    ch:longint;
  end;
var
  ans,i,j,k,n,tot,m,kk,h,u:longint;
  ss:string;
  dt:array[0..1000]of dtnote;
  dl:array[0..1000]of longint;
  f:array[0..1000,0..100,0..10]of longint;
function ha(c:char):longint;
begin
  if c='A' then exit(1);
  if c='C' then exit(2);
  if c='G' then exit(3);
  if c='T' then exit(4);
end;

procedure dtinsert;
var u,i,c:longint;
begin
  u:=1;
  for i:=1 to length(ss) do begin
    c:=ha(ss[i]);
    if dt[u].son[c]=0 then begin
      inc(tot);
      fillchar(dt[tot],sizeof(dt[tot]),0);
      dt[tot].p:=u;
      dt[u].son[c]:=tot;
      dt[tot].ch:=c;
      dt[tot].fl:=i;
    end;
    u:=dt[u].son[c];
  end;
  dt[u].cnt:=length(ss);;
end;

procedure setac;
var
  i,u,j,x:longint;
begin
  for j:=1 to 4 do dt[0].son[j]:=1;
  dt[1].fai:=0;

  dl[1]:=1;
  dl[0]:=1;
  for i:=1 to tot do begin
    x:=dl[i];
    for j:=1 to 4 do
      if dt[x].son[j]<>0 then begin
        inc(dl[0]);
        dl[dl[0]]:=dt[x].son[j];
      end;
    if i=1 then continue;

    u:=dt[dt[x].p].fai;
    while dt[u].son[dt[x].ch]=0 do u:=dt[u].fai;

    dt[x].fai:=dt[u].son[dt[x].ch];
    if dt[dt[x].fai].cnt>dt[x].cnt then
      dt[x].cnt:=dt[dt[x].fai].cnt;
  end;
end;

begin
  fillchar(dt[0],sizeof(dt[0]),0);
  dt[0].fl:=-1;
  fillchar(dt[1],sizeof(dt[1]),0);
  tot:=1;
  readln(n,m);
  for i:=1 to m do begin
    readln(ss);
    dtinsert;
  end;
  setac;
  f[0,1,0]:=1;
  for i:=0 to n-1 do
    for j:=1 to tot do
      for k:=0 to dt[j].fl do
        for h:=1 to 4 do begin
          u:=j;
          while dt[u].son[h]=0 do u:=dt[u].fai;
          kk:=k-(dt[j].fl-dt[u].fl);
          if kk<0 then continue;
          u:=dt[u].son[h];
          if dt[u].fl-dt[u].cnt<=kk then kk:=dt[u].fl;
          f[i+1,u,kk]:=(f[i+1,u,kk]+f[i,j,k])mod mode;
        end;
  ans:=0;
  for i:=1 to tot do
    ans:=(ans+f[n,i,dt[i].fl])mod mode;
  writeln(ans);
end.

uses math;
const md = 1000000009;
var
s:string;
jj,tt,j,p,ne,aa,i,n,m,size:longint;
next,go:array[0..1000,0..4]of longint;
eend,len,pred,link,pch:array[0..1000]of longint;

//st:array[0..1000]of string;

ans:array[0..1001,0..11,0..101]of longint;

procedure add(s:string);
var t,i,x:longint;
 begin
  t:=1;
  for i:=1 to length(s) do
    begin
     if s[i]='A' then x:=0;
     if s[i]='C' then x:=1;
     if s[i]='G' then x:=2;
     if s[i]='T' then x:=3;

     if next[t,x]=0 then
       begin
        size:=size+1;
//        st[size]:=st[t]+s[i];
        next[t,x]:=size;
        len[size]:=len[t]+1;
        pch[size]:=x;
        pred[size]:=t;
       end;

     t:=next[t,x];
    end;

  eend[t]:=1;
 end;

function fgo(x,y:longint):longint; forward;

function flink(x:longint):longint;
 begin
  if link[x]=0 then
    if (x=1)or(pred[x]=1) then link[x]:=1
                          else link[x]:=fgo(flink(pred[x]),pch[x]);

  flink:=link[x];
 end;

function fgo(x,y:longint):longint;
 begin
  if go[x,y]=0 then
     if next[x,y]>1 then go[x,y]:=next[x,y]
      else if x=1 then go[x,y]:=1 else go[x,y]:=fgo(flink(x),y);

  fgo:=go[x,y];
 end;

 begin
  readln(n,m);
  size:=1;
  for i:=1 to m do
    begin
     readln(s);
     add(s);
    end;
{
  for i:=1 to size do
    writeln(i,' ',st[i],' ',flink(i));
}
  ans[1,0,1]:=1;

  for i:=1 to n do
    begin
     for j:=0 to min(10,i) do
       begin
        for p:=1 to size do
          begin
            for ne:=0 to 3 do
               begin
                tt:=fgo(p,ne);
                jj:=j+1;
                if (len[tt]>=jj)and(eend[tt]=1) then jj:=0;
//                writeln('>>> ',ne,' ',tt,' ',len[tt],' ',jj);

                ans[i+1,jj,tt]:=(ans[i+1,jj,tt]+ans[i,j,p])mod md;
               end;
          end;
       end;
    end;

  aa:=0;
  for i:=1 to size do
    aa:=(aa+ans[n+1,0,i])mod md;

  writeln(aa);
 end.

program Genetic_engineering;
const mo=1000000009;
var n,m,i,j,k,z,now,size,l,r,len,ans:longint;
    c:array['A'..'T']of integer;
    danger,danger2:array[-1..100]of boolean;
    a:array[-1..100,1..4]of integer;
    q,point:array[0..100]of integer;
    f:array[0..1000,0..100]of longint;
    word:string;
//===========================================================================
procedure ins_Trie;
var i:longint;
begin
  now:=0;
  for i:=1 to length(word) do
    begin
      if a[now,c[word[i]]]=0 then
        begin
          inc(size);
          a[now,c[word[i]]]:=size;
        end;
      now:=a[now,c[word[i]]];
    end;
  danger[now]:=true;
end;
//===========================================================================
procedure init;
begin
  size:=0;
  readln(n,m);
  for i:=1 to m do
    begin
      readln(word);
      ins_Trie;
    end;
end;
//===========================================================================
procedure Set_AC_Machine;
begin
  q[0]:=0;l:=0;r:=0;
  point[0]:=-1;danger2:=danger;
  while l<=r do
    begin
      now:=q[l];
      for i:=1 to 4 do
        if a[now,i]>0 then
          begin
            k:=point[now];
            while (k<>-1) and (a[k,i]=0) do k:=point[k];
            point[a[now,i]]:=a[k,i];
            if danger2[now] then
            danger2[a[now,i]]:=danger2[a[now,i]] or danger2[a[k,i]];
            //danger[a[now,i]]:=danger[a[now,i]] or danger[a[k,i]];
            inc(r);
            q[r]:=a[now,i];
          end;
      inc(l);
    end;
end;
//===========================================================================
procedure DP;
begin
  f[0,0]:=1;
  for z:=1 to n do
    for i:=0 to size do
      if f[z-1,i]<>0 then
        for j:=1 to 4 do
          begin
            if (a[i,j]=0) and (not danger2[i]) then continue;
            k:=i;
            while (k<>-1) and (a[k,j]=0) do k:=point[k];
            k:=a[k,j];if k=0 then continue;
            f[z,k]:=(f[z,k]+f[z-1,i]) mod mo;
          end;
end;
//===========================================================================
begin
  danger[-1]:=true;
  c['A']:=1;c['C']:=2;c['G']:=3;c['T']:=4;
  init;
  Set_AC_machine;
  DP;
  for i:=0 to size do
    if danger2[i] then
      ans:=(ans+f[n,i]) mod mo;
  writeln(ans);
end.

program Genetic_engineering;
const mo=1000000009;
var n,m,i,j,k,z,now,size,l,r,len,ans:longint;
    c:array['A'..'T']of integer;
    danger:array[-1..100]of boolean;
    a:array[-1..100,1..4]of integer;
    q,point:array[0..100]of integer;
    f:array[0..1000,0..100]of longint;
    s:array[1..10]of string;
    word:string;
//===========================================================================
procedure ins_Trie;
var i:longint;
begin
  now:=0;
  for i:=1 to length(word) do
    begin
      if a[now,c[word[i]]]=0 then
        begin
          inc(size);
          a[now,c[word[i]]]:=size;
        end;
      now:=a[now,c[word[i]]];
    end;
  danger[now]:=true;
end;
//===========================================================================
procedure init;
begin
  size:=0;
  readln(n,m);
  for i:=1 to m do
    begin
      readln(word);
      s[i]:=word;
      ins_Trie;
    end;
end;
//===========================================================================
procedure Set_AC_Machine;
begin
  q[0]:=0;l:=0;r:=0;
  point[0]:=-1;
  while l<=r do
    begin
      now:=q[l];
      for i:=1 to 4 do
        if a[now,i]>0 then
          begin
            k:=point[now];
            while (k<>-1) and (a[k,i]=0) do k:=point[k];
            point[a[now,i]]:=a[k,i];
            inc(r);
            q[r]:=a[now,i];
          end;
      inc(l);
    end;
end;
//===========================================================================
procedure Work(x,y:longint);
var i:longint;
    flag:boolean;
begin
  if not danger[x] then flag:=false else flag:=true;
  now:=x;
  for i:=1 to length(s[y]) do
    begin
      if a[now,c[s[y,i]]]=0 then exit;
      if danger[now] then flag:=true;
      now:=a[now,c[s[y,i]]];
    end;
  if flag then danger[now]:=true;
end;
//===========================================================================
procedure DP;
begin
  f[0,0]:=1;
  for z:=1 to n do
    for i:=0 to size do
      if f[z-1,i]<>0 then
        for j:=1 to 4 do
          begin
            if (a[i,j]=0) and (not danger[i]) then continue;
            k:=i;
            while (k<>-1) and (a[k,j]=0) do k:=point[k];
            k:=a[k,j];if k=0 then continue;
            f[z,k]:=(f[z,k]+f[z-1,i]) mod mo;
          end;
end;
//===========================================================================
begin
  danger[-1]:=true;
  c['A']:=1;c['C']:=2;c['G']:=3;c['T']:=4;
  init;
  Set_AC_machine;
  for i:=1 to size do
    for j:=1 to m do Work(i,j);
  DP;
  for i:=0 to size do
    if danger[i] then
      ans:=(ans+f[n,i]) mod mo;
  writeln(ans);
end.

program Genetic_engineering;
const mo=1000000009;
var n,m,i,j,k,z,now,size,l,r,len,ans:longint;
    c:array['A'..'T']of integer;
    danger:array[-1..100]of boolean;
    a:array[-1..100,1..4]of integer;
    q,point:array[0..100]of integer;
    f:array[0..1000,0..100]of longint;
    s:array[1..10]of string;
    word:string;
//===========================================================================
procedure ins_Trie;
var i:longint;
begin
  now:=0;
  for i:=1 to length(word) do
    begin
      if a[now,c[word[i]]]=0 then
        begin
          inc(size);
          a[now,c[word[i]]]:=size;
        end;
      now:=a[now,c[word[i]]];
    end;
  danger[now]:=true;
end;
//===========================================================================
procedure init;
begin
  size:=0;
  readln(n,m);
  for i:=1 to m do
    begin
      readln(word);
      s[i]:=word;
      ins_Trie;
    end;
end;
//===========================================================================
procedure Set_AC_Machine;
begin
  q[0]:=0;l:=0;r:=0;
  point[0]:=-1;
  while l<=r do
    begin
      now:=q[l];
      for i:=1 to 4 do
        if a[now,i]>0 then
          begin
            k:=point[now];
            while (k<>-1) and (a[k,i]=0) do k:=point[k];
            point[a[now,i]]:=a[k,i];
            inc(r);
            q[r]:=a[now,i];
          end;
      inc(l);
    end;
end;
//===========================================================================
procedure Work(x,y:longint);
var i:longint;
begin
  if not danger[x] then exit;
  now:=x;
  for i:=1 to length(s[y]) do
    begin
      if a[now,c[s[y,i]]]=0 then exit;
      now:=a[now,c[s[y,i]]];
    end;
  danger[now]:=true;
end;
//===========================================================================
procedure DP;
begin
  f[0,0]:=1;
  for z:=1 to n do
    for i:=0 to size do
      if f[z-1,i]<>0 then
        for j:=1 to 4 do
          begin
            if (a[i,j]=0) and (not danger[i]) then continue;
            k:=i;
            while (k<>-1) and (a[k,j]=0) do k:=point[k];
            k:=a[k,j];if k=0 then continue;
            f[z,k]:=(f[z,k]+f[z-1,i]) mod mo;
          end;
end;
//===========================================================================
begin
  danger[-1]:=true;
  c['A']:=1;c['C']:=2;c['G']:=3;c['T']:=4;
  init;
  Set_AC_machine;
  for i:=1 to size do
    for j:=1 to m do Work(i,j);
  DP;
  for i:=0 to size do
    if danger[i] then
      ans:=(ans+f[n,i]) mod mo;
  writeln(ans);
end.

program Genetic_engineering;
const mo=1000000009;
var n,m,i,j,k,z,now,size,l,r,len,ans:longint;
    c:array['A'..'T']of integer;
    danger,danger2:array[-1..100]of boolean;
    a:array[-1..100,1..4]of integer;
    q,point:array[0..100]of integer;
    f:array[0..1000,0..100]of longint;
    word:string;
//===========================================================================
procedure ins_Trie;
var i:longint;
begin
  now:=0;
  for i:=1 to length(word) do
    begin
      if a[now,c[word[i]]]=0 then
        begin
          inc(size);
          a[now,c[word[i]]]:=size;
        end;
      now:=a[now,c[word[i]]];
    end;
  danger[now]:=true;
end;
//===========================================================================
procedure init;
begin
  size:=0;
  readln(n,m);
  for i:=1 to m do
    begin
      readln(word);
      ins_Trie;
    end;
end;
//===========================================================================
procedure Set_AC_Machine;
begin
  q[0]:=0;l:=0;r:=0;
  point[0]:=-1;danger2:=danger;
  while l<=r do
    begin
      now:=q[l];
      for i:=1 to 4 do
        if a[now,i]>0 then
          begin
            k:=point[now];
            while (k<>-1) and (a[k,i]=0) do k:=point[k];
            point[a[now,i]]:=a[k,i];
            if danger2[now] then
            danger2[a[now,i]]:=danger2[a[now,i]] or danger2[a[k,i]];
            //danger[a[now,i]]:=danger[a[now,i]] or danger[a[k,i]];
            inc(r);
            q[r]:=a[now,i];
          end;
      inc(l);
    end;
end;
//===========================================================================
procedure DP;
begin
  f[0,0]:=1;
  for z:=1 to n do
    for i:=0 to size do
      if f[z-1,i]<>0 then
        for j:=1 to 4 do
          begin
            if (a[i,j]=0) and (not danger[i]) then continue;
            k:=i;
            while (k<>-1) and (a[k,j]=0) do k:=point[k];
            k:=a[k,j];if k=0 then continue;
            f[z,k]:=(f[z,k]+f[z-1,i]) mod mo;
          end;
end;
//===========================================================================
begin
  danger[-1]:=true;
  c['A']:=1;c['C']:=2;c['G']:=3;c['T']:=4;
  init;
  Set_AC_machine;
  DP;
  for i:=0 to size do
    if danger2[i] then
      ans:=(ans+f[n,i]) mod mo;
  writeln(ans);
end.

program Genetic_engineering;
const mo=1000000009;
var n,m,i,j,k,z,now,size,l,r,len,ans:longint;
    c:array['A'..'T']of longint;
    danger:array[-1..100]of boolean;
    a:array[-1..100,1..4]of longint;
    q,point:array[0..100]of longint;
    f:array[0..1000,0..100]of longint;
    s:array[1..10]of string;
    word:string;
//===========================================================================
procedure qsort(left,right:longint);
var l,r,mid:longint;
    k:string;
begin
  l:=left;r:=right;
  mid:=length(s[(l+r)shr 1]);
  repeat
    while length(s[l])<mid do inc(l);
    while length(s[r])>mid do dec(r);
    if l<=r then
      begin
        k:=s[l];s[l]:=s[r];s[r]:=k;
        inc(l);dec(r);
      end;
  until l>r;
  if left<r then qsort(left,r);
  if l<right then qsort(l,right);
end;
procedure ins_Trie;
var i:longint;
begin
  now:=0;
  for i:=1 to length(word) do
    begin
      if a[now,c[word[i]]]=0 then
        begin
          inc(size);
          a[now,c[word[i]]]:=size;
        end;
      now:=a[now,c[word[i]]];
    end;
  danger[now]:=true;
end;
//===========================================================================
procedure init;
begin
  size:=0;
  readln(n,m);
  for i:=1 to m do
    begin
      readln(word);
      s[i]:=word;
      ins_Trie;
    end;
end;
//===========================================================================
procedure Set_AC_Machine;
begin
  q[0]:=0;l:=0;r:=0;
  point[0]:=-1;
  while l<=r do
    begin
      now:=q[l];
      for i:=1 to 4 do
        if a[now,i]>0 then
          begin
            k:=point[now];
            while (k<>-1) and (a[k,i]=0) do k:=point[k];
            point[a[now,i]]:=a[k,i];
            inc(r);
            q[r]:=a[now,i];
          end;
      inc(l);
    end;
end;
//===========================================================================
procedure Work(x,y:longint);
var i:longint;
    flag:boolean;
begin
  if not danger[x] then flag:=false else flag:=true;
  now:=x;
  for i:=1 to length(s[y]) do
    begin
      if a[now,c[s[y,i]]]=0 then exit;
      if danger[now] then flag:=true;
      now:=a[now,c[s[y,i]]];
    end;
  if flag then danger[now]:=true;
end;
//===========================================================================
procedure DP;
begin
  f[0,0]:=1;
  for z:=1 to n do
    for i:=0 to size do
      if f[z-1,i]<>0 then
        for j:=1 to 4 do
          begin
            if (a[i,j]=0) and (not danger[i]) then continue;
            k:=i;
            while (k<>-1) and (a[k,j]=0) do k:=point[k];
            k:=a[k,j];if k=0 then continue;
            f[z,k]:=(f[z,k]+f[z-1,i]) mod mo;
          end;
end;
//===========================================================================
begin
  danger[-1]:=true;
  c['A']:=1;c['C']:=2;c['G']:=3;c['T']:=4;
  init;
  Set_AC_machine;
  qsort(1,m);
  for i:=1 to size do
    for j:=1 to m do Work(i,j);
  DP;
  for i:=0 to size do
    if danger[i] then
      ans:=(ans+f[n,i]) mod mo;
  writeln(ans);
end.

const bigp=1000000009;

type autoac=^pear;
     pear=record
            flag,depth,num,ti:longint;
            back,father:autoac;
            child:array[1..4] of autoac;
          end;

var root,p,q:autoac;
    m,n,i,j,k,tt,ls,rc,fc,sc,ans:longint;
    f:array[0..1010,0..300,0..15] of longint;
    u:array[0..10000] of autoac;
    s:string;
    ch:char;

procedure calc(p:autoac);
  var i:longint;
      q:autoac;
  begin
    if p^.flag=0 then
      begin
        q:=p^.back;
        while (q<>root) and (q^.flag=0) do q:=q^.back;
        if q^.flag=1 then
          begin
            p^.flag:=1;
            p^.depth:=q^.depth;
          end;
      end;
    for i:=1 to 4 do
      if p^.child[i]<>nil then calc(p^.child[i]);
  end;

procedure doit(p:autoac;s:longint);
  var i,j,c1,c2:longint;
      q:autoac;
  begin
    if (s=0) or (p<>root) then
      begin
        for i:=1 to 4 do
          begin
            c1:=p^.ti;
            q:=p;
            while (q<>root) and (q^.child[i]=nil) do q:=q^.back;
            if q^.child[i]<>nil then
              q:=q^.child[i];
            c2:=q^.ti;
            for j:=0 to 10 do
              if f[s,c1,j]>0 then
                begin
                  if (q^.flag=1) and (q^.depth>j) then
                    f[s+1,c2,0]:=(f[s+1,c2,0]+f[s,c1,j]) mod bigp
                  else
                    f[s+1,c2,j+1]:=(f[s+1,c2,j+1]+f[s,c1,j]) mod bigp;
                end;
          end;
      end;
    for i:=1 to 4 do
      if p^.child[i]<>nil then
        doit(p^.child[i],s);
  end;

procedure solve(p:autoac);
  var i:longint;
  begin
    if p^.flag=1 then
      ans:=(ans+f[n,p^.ti,0]) mod bigp;
    for i:=1 to 4 do
      if p^.child[i]<>nil then
        solve(p^.child[i]);
  end;

begin
  new(root);
  root^.father:=root;
  root^.back:=root;
  root^.num:=0;
  root^.ti:=1;
  root^.depth:=0;
  root^.flag:=0;
  for i:=1 to 4 do
    root^.child[i]:=nil;
  readln(n,m);
  tt:=1;
  for i:=1 to m do
    begin
      readln(s);
      p:=root;
      ls:=length(s);
      for j:=1 to ls do
        begin
          ch:=s[j];
          if ch='A' then sc:=1;
          if ch='C' then sc:=2;
          if ch='G' then sc:=3;
          if ch='T' then sc:=4;
          if p^.child[sc]=nil then
            begin
              new(q);
              q^.father:=p;
              q^.back:=nil;
              for k:=1 to 4 do
                q^.child[k]:=nil;
              inc(tt);
              q^.ti:=tt;
              q^.num:=sc;
              p^.child[sc]:=q;
              p:=q;
            end
          else
            p:=p^.child[sc];
        end;
      p^.flag:=1;
      p^.depth:=ls;
      //writeln(p^.ti);
    end;
  rc:=1;
  fc:=1;
  u[rc]:=root;
  while rc<=fc do
    begin
      if u[rc]<>root then
        begin
          p:=u[rc]^.father^.back;
          sc:=u[rc]^.num;
          while (p<>root) and (p^.child[sc]=nil) do p:=p^.back;
          if (p^.child[sc]<>nil) and (p^.child[sc]<>u[rc]) then p:=p^.child[sc];
          u[rc]^.back:=p;
          p:=u[rc];
          q:=p^.back;
          while (q<>root) and (q^.flag=0) do q:=q^.back;
          if q^.flag=1 then
            begin
              p^.flag:=1;
              p^.depth:=q^.depth;
            end;
        end;
      for i:=1 to 4 do
        if u[rc]^.child[i]<>nil then
          begin
            inc(fc);
            u[fc]:=u[rc]^.child[i];
          end;
      inc(rc);
    end;
  //calc(root);
  fillchar(f,sizeof(f),0);
  f[0,1,0]:=1;
  for i:=0 to n-1 do
    doit(root,i);
  ans:=0;
  solve(root);
  //writeln(f[n,21,0]);
  writeln(ans);
end.

const bigp=1000000009;

type autoac=^pear;
     pear=record
            flag,depth,num,ti:longint;
            back,father:autoac;
            child:array[1..4] of autoac;
          end;

var root,p,q:autoac;
    m,n,i,j,k,tt,ls,rc,fc,sc,ans:longint;
    f:array[0..1010,0..300,0..15] of longint;
    u:array[0..10000] of autoac;
    s:string;
    ch:char;

procedure doit(p:autoac;s:longint);
  var i,j,c1,c2:longint;
      q:autoac;
  begin
    if (s=0) or (p<>root) then
      begin
        for i:=1 to 4 do
          begin
            c1:=p^.ti;
            q:=p;
            while (q<>root) and (q^.child[i]=nil) do q:=q^.back;
            if q^.child[i]<>nil then
              q:=q^.child[i];
            c2:=q^.ti;
            for j:=0 to 10 do
              if f[s,c1,j]>0 then
                begin
                  if (q^.flag=1) and (q^.depth>j) then
                    f[s+1,c2,0]:=(f[s+1,c2,0]+f[s,c1,j]) mod bigp
                  else
                    f[s+1,c2,j+1]:=(f[s+1,c2,j+1]+f[s,c1,j]) mod bigp;
                end;
          end;
      end;
    for i:=1 to 4 do
      if p^.child[i]<>nil then
        doit(p^.child[i],s);
  end;

procedure solve(p:autoac);
  var i:longint;
  begin
    if p^.flag=1 then
      ans:=(ans+f[n,p^.ti,0]) mod bigp;
    for i:=1 to 4 do
      if p^.child[i]<>nil then
        solve(p^.child[i]);
  end;

begin
  new(root);
  root^.father:=root;
  root^.back:=root;
  root^.num:=0;
  root^.ti:=1;
  root^.depth:=0;
  root^.flag:=0;
  for i:=1 to 4 do
    root^.child[i]:=nil;
  readln(n,m);
  tt:=1;
  for i:=1 to m do
    begin
      readln(s);
      p:=root;
      ls:=length(s);
      for j:=1 to ls do
        begin
          ch:=s[j];
          if ch='A' then sc:=1;
          if ch='C' then sc:=2;
          if ch='G' then sc:=3;
          if ch='T' then sc:=4;
          if p^.child[sc]=nil then
            begin
              new(q);
              q^.father:=p;
              q^.back:=nil;
              for k:=1 to 4 do
                q^.child[k]:=nil;
              inc(tt);
              q^.ti:=tt;
              q^.num:=sc;
              q^.flag:=0;
              p^.child[sc]:=q;
              p:=q;
            end
          else
            p:=p^.child[sc];
        end;
      p^.flag:=1;
      p^.depth:=ls;
      writeln(p^.ti);
    end;
  rc:=1;
  fc:=1;
  u[rc]:=root;
  while rc<=fc do
    begin
      if u[rc]<>root then
        begin
          p:=u[rc]^.father^.back;
          sc:=u[rc]^.num;
          while (p<>root) and (p^.child[sc]=nil) do p:=p^.back;
          if (p^.child[sc]<>nil) and (p^.child[sc]<>u[rc]) then p:=p^.child[sc];
          u[rc]^.back:=p;
          p:=u[rc];
          if p^.flag=0 then
            begin
              q:=p^.back;
              while (q<>root) and (q^.flag=0) do q:=q^.back;
              if q^.flag=1 then
                begin
                  p^.flag:=1;
                  p^.depth:=q^.depth;
                end;
            end;
        end;
      for i:=1 to 4 do
        if u[rc]^.child[i]<>nil then
          begin
            inc(fc);
            u[fc]:=u[rc]^.child[i];
          end;
      inc(rc);
    end;
  fillchar(f,sizeof(f),0);
  f[0,1,0]:=1;
  for i:=0 to n-1 do
    doit(root,i);
  ans:=0;
  solve(root);
  writeln(ans);
end.

program xj;

  const
    mo=1000000009;

  var
    son:array[0..1000,1..4]of longint;
    flag:array[0..1000]of boolean;
    f:array[0..1000,0..120,0..12]of int64;
    q,next,list,dep:array[0..1000]of longint;
    i,j,k,n,m,tot,x,y,nn,l1,l2,now,nex,kk:longint;
    st:string;
    ans:int64;

  procedure insert;
    var
      now,ii:longint;
    begin
      now:=0;
      for ii:=1 to nn do
        begin
          if son[now][list[ii]]=0
            then begin inc(tot);dep[tot]:=dep[now]+1;son[now][list[ii]]:=tot; end;
          now:=son[now][list[ii]];
        end;
      flag[now]:=true;
    end;

  procedure get_ac;
  begin
   l1:=1;l2:=1;
   q[1]:=0;next[0]:=-1;
   while l1<=l2 do
    begin
     now:=q[l1];
     for k:=1 to 4 do
       begin
         nex:=son[now][k];
         if nex<>0
           then
             begin
               inc(l2);q[l2]:=nex;
               x:=next[now];
               while (x<>-1)and(son[x][k]=0) do  x:=next[x];
               if x<>-1
                 then next[nex]:=son[x,k]
                 else next[nex]:=0;
             end
           else
             begin
               x:=next[now];
               while (x<>-1)and(son[x][k]=0) do
                 x:=next[x];
               if x=-1 then son[now][k]:=0
                       else son[now][k]:=son[x][k];
             end;
       end;
     inc(l1);
    end;
  end;

  procedure run_ac;
    var
      now:longint;
    begin
      fillchar(f,sizeof(f),0);
      f[0,0,0]:=1;
      for i:=0 to n-1 do
        for j:=0 to tot do
          for k:=0 to 9 do
            if f[i][j][k]>0
              then
                begin
                  for kk:=1 to 4 do
                    begin
                      nex:=son[j][kk];
                      if nex<>0
                        then
                          begin
                            if (flag[nex])and(dep[nex]>=k+1)
                              then f[i+1][nex][0]:=(f[i+1][nex][0]+f[i][j][k]) mod mo;
                            if (not flag[nex])and(k+1<=9)
                              then f[i+1][nex][k+1]:=(f[i+1][nex][k+1]+f[i][j][k]) mod mo;
                          end;
                    end;
                end;
    end;

  begin
    readln(n,m);
    tot:=0;
    fillchar(flag,sizeof(flag),false);
    dep[0]:=0;
    for i:=1 to m do
      begin
        readln(st);
        nn:=length(st);
        for j:=1 to nn do
          case st[j] of
            'A':list[j]:=1;
            'C':list[j]:=2;
            'G':list[j]:=3;
            'T':list[j]:=4;
          end;
        insert;
      end;
    get_ac;
    run_ac;
    ans:=0;
    for i:=0 to tot do
      if f[n][i][0]>0
        then ans:=(ans+f[n][i][0]) mod mo;
    writeln(ans);
  end.

program xj;

  const
    mo=1000000009;

  var
    son:array[0..1000,1..4]of longint;
	flag:array[0..1000]of boolean;
	f:array[0..1000,0..1000]of int64;
	q,next,list:array[0..10000]of longint;
	i,j,k,n,m,tot,x,y,nn,l1,l2,now,nex:longint;
	st:string;
	ans:int64;

  procedure insert;
    var
	  now,ii:longint;
	begin
	  now:=0;
	  for ii:=1 to nn do
	    begin
		  if son[now][list[ii]]=0
		    then begin inc(tot);son[now][list[ii]]:=tot; end;
		  now:=son[now][list[ii]];
		end;
	  flag[now]:=true;
	end;

  procedure get_ac;
  begin
   l1:=1;l2:=1;
   q[1]:=0;next[0]:=-1;
   while l1<=l2 do
    begin
     now:=q[l1];
     for i:=1 to 4 do
      begin
       nex:=son[now,i];
       if nex<>0
        then
         begin
          inc(l2);q[l2]:=nex;
          x:=next[now];
          while (x<>-1)and(son[x,i]=0) do x:=next[x];
          if x=-1 then next[nex]:=0
                  else next[nex]:=son[x,i];
         end;
      end;
     inc(l1);
    end;
  end;

  procedure run_ac;
    var
	  now:longint;
	begin
	  fillchar(f,sizeof(f),0);
	  f[0,0]:=1;
	  for i:=0 to n do
	    for j:=0 to tot do
		  if f[i][j]>0
		    then
			  begin
			    for k:=1 to 4 do
				  begin
                    if son[j,k]<>0
					  then
                        begin
				          f[i+1][son[j,k]]:=(f[i+1][son[j,k]]+f[i][j]) mod mo;
				        end;
					if (son[j][k]=0)and(flag[j])
					  then
					    begin
						  now:=j;
						  while (now<>-1)and(son[now][k]=0) do
						    now:=next[now];
						  if now<>-1 then f[i+1][son[now][k]]:=(f[i+1][son[now][k]]+f[i][j]) mod mo;
						end;
				  end;
			  end;
	end;

  begin
    //assign(input,'x.in');reset(input);
	//assign(output,'x.out');rewrite(output);
	readln(n,m);
	tot:=0;
	fillchar(flag,sizeof(flag),false);
	for i:=1 to m do
	  begin
		readln(st);
		nn:=length(st);
		for j:=1 to nn do
		  case st[j] of
		    'A':list[j]:=1;
			'C':list[j]:=2;
			'G':list[j]:=3;
			'T':list[j]:=4;
		  end;
		insert;
	  end;
	get_ac;
	run_ac;
	ans:=0;
	for i:=0 to tot do
	  if flag[i]
	    then ans:=(ans+f[n][i]) mod mo;
    writeln(ans);
  end.

program xj;

  const
    mo=1000000009;

  var
    son:array[0..1000,1..4]of longint;
	flag:array[0..1000]of boolean;
	f:array[0..1000,0..1000]of int64;
	q,next,list:array[0..10000]of longint;
	i,j,k,n,m,tot,x,y,nn,l1,l2,now,nex:longint;
	st:string;
	ans:int64;

  procedure insert;
    var
	  now,ii:longint;
	begin
	  now:=0;
	  for ii:=1 to nn do
	    begin
		  if son[now][list[ii]]=0
		    then begin inc(tot);son[now][list[ii]]:=tot; end;
		  now:=son[now][list[ii]];
		end;
	  flag[now]:=true;
	end;

  procedure get_ac;
  begin
   l1:=1;l2:=1;
   q[1]:=0;next[0]:=-1;
   while l1<=l2 do
    begin
     now:=q[l1];
     for i:=1 to 4 do
      begin
       nex:=son[now,i];
       if nex<>0
        then
         begin
          inc(l2);q[l2]:=nex;
          x:=next[now];
          while (x<>-1)and(son[x,i]=0) do x:=next[x];
          if x=-1 then next[nex]:=0
                  else next[nex]:=son[x,i];
         end;
      end;
     inc(l1);
    end;
  end;

  procedure run_ac;
    var
	  now:longint;
	begin
	  fillchar(f,sizeof(f),0);
	  f[0,0]:=1;
	  for i:=0 to n do
	    for j:=0 to tot do
		  if f[i][j]>0
		    then
			  begin
			    for k:=1 to 4 do
				  begin
                    if son[j,k]<>0
					  then
                        begin
				          f[i+1][son[j,k]]:=(f[i+1][son[j,k]]+f[i][j]) mod mo;
				        end;
					if (son[j][k]=0)and(flag[j])
					  then
					    begin
						  now:=j;
						  while (now<>-1){and(son[now][k]=0)} do
						    begin
							  if son[now][k]<>0
							    then f[i+1][son[now][k]]:=(f[i+1][son[now][k]]+f[i][j]) mod mo;
							  now:=next[now];
						    end;
                                                  //if now<>-1
							    //then f[i+1][son[now][k]]:=(f[i+1][son[now][k]]+f[i][j]) mod mo;
						end;
				  end;
			  end;
	end;

  begin
    //assign(input,'x.in');reset(input);
	//assign(output,'x.out');rewrite(output);
	readln(n,m);
	tot:=0;
	fillchar(flag,sizeof(flag),false);
	for i:=1 to m do
	  begin
		readln(st);
		nn:=length(st);
		for j:=1 to nn do
		  case st[j] of
		    'A':list[j]:=1;
			'C':list[j]:=2;
			'G':list[j]:=3;
			'T':list[j]:=4;
		  end;
		insert;
	  end;
	get_ac;
	run_ac;
	ans:=0;
	for i:=0 to tot do
	  if flag[i]
	    then ans:=(ans+f[n][i]) mod mo;
    writeln(ans);
  end.

{$r-,q-,s-,i-,o+}
{$M 10000000}
const
  ABC='ACGT';
  base=1000000009;
var
  s:string;
  nexto,j,n,m,kb,i,x,o:longint;
  pow,link,pred,predch:array[0..555]of longint;
  leaf:array[0..555]of boolean;
  next:array[0..555,0..5]of longint;
  f:array[0..1111,0..11,0..111]of longint;
  procedure recl(x:longint);
    var
      i,ch:longint;
    begin
      if (link[x]<>-1)then exit;
      if (pred[x]=0)then begin
        link[x]:=0;
        exit;
      end;
      ch:=predch[x];
      i:=pred[x];
      if (link[i]=-1)then recl(i);
      i:=link[i];
      while (i>0)and(next[i][ch]=-1)do begin
        if (link[i]=-1)then recl(i);
        i:=link[i];
      end;
      if (next[i][ch]=-1)
        then i:=0
        else i:=next[i][ch];
      link[x]:=i;
    end;
  function next_bor(x,ch:longint):longint;
    begin
      while (x>0)and(next[x][ch]=-1)do x:=link[x];
      next_bor:=next[x][ch];
    end;
  function rec(i,k,x:longint):longint;
    var
      nextx,ch,res:longint;
    begin
      if (f[i][k][x]<>-1)then begin
        rec:=f[i][k][x];
        exit;
      end;
      if (leaf[x])then k:=0;
      if (k>10)or(pow[x]<k)then begin
        f[i][k][x]:=0;
        rec:=0;
        exit;
      end;
      if (i=n+1)and(k=0)then begin
        f[i][k][x]:=1;
        rec:=1;
        exit;
      end;
      if (i=n+1)then begin
        f[i][k][x]:=0;
        rec:=0;
        exit;
      end;
      res:=0;
      for ch:=1 to 4 do begin
        nextx:=next_bor(x,ch);
        if (nextx<0)then continue;
        res:=res+rec(i+1,k+1,nextx);
        if (res>=base)then dec(res,base);
      end;
      f[i][k][x]:=res;
      rec:=res;
      exit;
    end;
begin
  //assign(input,'input.txt');reset(input);
  //assign(output,'output.txt');rewrite(output);
  readln(n,m);
  kb:=0;
  fillchar(next,sizeof(next),$FF);
  fillchar(link,sizeof(link),$FF);
  fillchar(leaf,sizeof(leaf),false);
  link[0]:=0;
  pow[0]:=0;
  for i:=1 to m do begin
    readln(s);
    if (length(s)>n)then continue;
    x:=0;
    for j:=1 to length(s)do begin
      o:=pos(s[j],ABC);
      if (next[x][o]=-1)then begin
        inc(kb);
        next[x][o]:=kb;
      end;
      nexto:=next[x][o];
      pred[nexto]:=x;
      predch[nexto]:=o;
      pow[nexto]:=pow[x]+1;
      x:=nexto;
    end;
    leaf[x]:=true;
  end;
  for i:=0 to kb do recl(i);
  fillchar(f,sizeof(f),$FF);
  writeln(rec(1,0,0));
end.

{$r-,q-,s-,i-,o+}
{$M 10000000}
const
  ABC='ACGT';
  base=1000000009;
var
  s:string;
  nexto,j,n,m,kb,i,x,o:longint;
  pow,link,pred,predch:array[0..555]of longint;
  leaf:array[0..555]of boolean;
  next:array[0..555,0..5]of longint;
  f:array[0..1111,0..11,0..111]of longint;
  procedure recl(x:longint);
    var
      i,ch:longint;
    begin
      if (link[x]<>-1)then exit;
      if (pred[x]=0)then begin
        link[x]:=0;
        exit;
      end;
      ch:=predch[x];
      i:=pred[x];
      if (link[i]=-1)then recl(i);
      i:=link[i];
      while (i>0)and(next[i][ch]=-1)do begin
        if (link[i]=-1)then recl(i);
        i:=link[i];
      end;
      if (next[i][ch]=-1)
        then i:=0
        else i:=next[i][ch];
      link[x]:=i;
    end;
  function next_bor(x,ch:longint):longint;
    begin
      while (x>0)and(next[x][ch]=-1)do x:=link[x];
      next_bor:=next[x][ch];
    end;
  function rec(i,k,x:longint):longint;
    var
      nextx,ch,res:longint;
    begin
      if (f[i][k][x]<>-1)then begin
        rec:=f[i][k][x];
        exit;
      end;
      if (leaf[x])then k:=0;
      if (k>10)or(pow[x]<k)then begin
        f[i][k][x]:=0;
        rec:=0;
        exit;
      end;
      if (i=n+1)and(k=0)then begin
        f[i][k][x]:=1;
        rec:=1;
        exit;
      end;
      res:=0;
      for ch:=1 to 4 do begin
        nextx:=next_bor(x,ch);
        if (nextx<0)then continue;
        res:=res+rec(i+1,k+1,nextx);
        if (res>=base)then dec(res,base);
      end;
      f[i][k][x]:=res;
      rec:=res;
      exit;
    end;
begin
  //assign(input,'input.txt');reset(input);
  //assign(output,'output.txt');rewrite(output);
  readln(n,m);
  kb:=0;
  fillchar(next,sizeof(next),$FF);
  fillchar(link,sizeof(link),$FF);
  fillchar(leaf,sizeof(leaf),false);
  link[0]:=0;
  pow[0]:=0;
  for i:=1 to m do begin
    readln(s);
    x:=0;
    for j:=1 to length(s)do begin
      o:=pos(s[j],ABC);
      if (next[x][o]=-1)then begin
        inc(kb);
        next[x][o]:=kb;
      end;
      nexto:=next[x][o];
      pred[nexto]:=x;
      predch[nexto]:=o;
      pow[nexto]:=pow[x]+1;
      x:=nexto;
    end;
    leaf[x]:=true;
  end;
  for i:=0 to kb do recl(i);
  fillchar(f,sizeof(f),$FF);
  writeln(rec(1,0,0));
end.

uses math;
const cmod = 1000000009;

type Ttrie = ^kdl;
kdl = record
v:longint;
a:array['A'..'Z'] of TTrie;
kt:boolean;
l:longint;
st:string;
End;

const maxn=1010;
maxnode=1010;
var f1,f2:text;
A:array[1..maxn] of longint;
TNil:TTrie;
st:string;
Root:TTrie;
Next:array[1..maxn,'A'..'Z'] of longint;
F:array[0..maxn,0..20,1..maxnode] of longint;
Vis:array[0..maxn,0..20,1..maxnode] of boolean;
T:array[1..maxnode] of Ttrie;
spt,m:longint;
res:longint;
n,i:longint;

Procedure init(var u:TTrie);
var ch:char;
begin
        new(u);
        for ch:='A' to 'Z' do
          u^.a[ch]:=nil;
        inc(spt);
        u^.v:=spt;
        u^.kt:=false;
        u^.l:=0;
        u^.st:='';
        T[spt]:=u;
end;

Function Search(st:string):longint;
var p:TTrie;
i:longint;
begin
        p:=root;
        for i:=1 to length(st) do
          if p^.a[st[i]]<>nil then p:=p^.a[st[i]] else exit(-1);
        Search:=p^.v;
end;

Procedure Build(u:TTrie);
var p:TTrie;
ch:char;
x:longint;
j:longint;
st:string;
begin

          For j:=2 to length(u^.st)+1 do
            begin
              x:=search(copy(u^.st,j,length(u^.st)-j+1));
              if x<>-1 then
              Begin
                if T[x]^.kt then
                Begin
                  u^.kt:=true;
                  u^.l:=max(u^.l,T[x]^.l);
                End;
              End;
            End;
        for ch:='A' to 'Z' do
        Begin
          Next[u^.v,ch]:=1;
          For j:=2 to length(u^.st)+1 do
            begin
              x:=search(copy(u^.st,j,length(u^.st)-j+1)+ch);
              if x<>-1 then
              Begin
                Next[u^.v,ch]:=x;
                break;
              End;
            End;
        End;
        for ch:='A' to 'Z' do
          if u^.a[ch]<>nil then
          Begin
            Next[u^.v,ch]:=u^.A[ch]^.v;
            Build(u^.A[ch]);
          End;
end;

Procedure Push;
var j:longint;
p:TTrie;
u:longint;
begin
        p:=root;
          For j:=1 to length(st) do
          begin
            if p^.a[st[j]]=nil then Begin
            init(p^.a[st[j]]);
            p^.a[st[j]]^.st:=p^.st+st[j]; End;
            p:=p^.a[st[j]]
          end;
        p^.kt:=true;
        p^.l:=length(st);
end;

Function Rec(i,k,j:longint):longint; {den i con k , nut j}
var ch:char;
p:TTrie;
begin
        if (i=n) then
        exit(longint(k=0));
        if k>10 then exit(0);
        if Vis[i,k,j] then exit(F[i,k,j]);
        Vis[i,k,j]:=true;
        for ch:='A' to 'Z' do
        begin
          if Next[j,ch]<>0 then
          Begin
            p:=T[Next[j,ch]];
            if p^.kt then
            Begin
              if k+1<=p^.l then
              F[i,k,j]:=(F[i,k,j]+Rec(i+1,0,Next[j,ch])) mod cmod;
            end
            else
            if Next[j,ch]<>1 then
            F[i,k,j]:=(F[i,k,j]+Rec(i+1,k+1,Next[j,ch])) mod cmod;
          End;
        End;
        Rec:=F[i,k,j];

end;

Procedure DP;
var i,j:longint;
ch:char;
begin
        fillchar(vis,sizeof(vis),false);
        writeln(f2,Rec(0,0,1));
end;

begin
        assign(f1,'');reset(f1);
        assign(f2,'');rewrite(f2);
        readln(f1,n,m);
        Init(root);
        for i:=1 to m do
        Begin
          readln(F1,st);
          push;
        End;
        Build(root);
        DP;
        close(f1);
        close(f2);
end.

uses math;
const cmod = 1000000007;

type Ttrie = ^kdl;
kdl = record
v:longint;
a:array['A'..'Z'] of TTrie;
kt:boolean;
l:longint;
st:string;
End;

const maxn=1000;
maxnode=1000;
var f1,f2:text;
A:array[1..maxn] of longint;
TNil:TTrie;
st:string;
Root:TTrie;
Next:array[1..maxn,'A'..'Z'] of longint;
F:array[0..maxn,0..20,1..maxnode] of longint;
Vis:array[0..maxn,0..20,1..maxnode] of boolean;
T:array[1..maxnode] of Ttrie;
spt,m:longint;
res:longint;
n,i:longint;

Procedure init(var u:TTrie);
var ch:char;
begin
        new(u);
        for ch:='A' to 'Z' do
          u^.a[ch]:=nil;
        inc(spt);
        u^.v:=spt;
        u^.kt:=false;
        u^.st:='';
        T[spt]:=u;
end;

Function Search(st:string):longint;
var p:TTrie;
i:longint;
begin
        p:=root;
        for i:=1 to length(st) do
          if p^.a[st[i]]<>nil then p:=p^.a[st[i]] else exit(-1);
        Search:=p^.v;
end;

Procedure Build(u:TTrie);
var p:TTrie;
ch:char;
x:longint;
j:longint;
st:string;
begin

          For j:=2 to length(u^.st)+1 do
            begin
              x:=search(copy(u^.st,j,length(u^.st)-j+1));
              if x<>-1 then
              Begin
                if T[x]^.kt then
                Begin
                  u^.kt:=true;
                  u^.l:=max(u^.l,T[x]^.l);
                End;
              End;
            End;
        for ch:='A' to 'Z' do
        Begin
          Next[u^.v,ch]:=1;
          For j:=2 to length(u^.st)+1 do
            begin
              x:=search(copy(u^.st,j,length(u^.st)-j+1)+ch);
              if x<>-1 then
              Begin
                Next[u^.v,ch]:=x;
                break;
              End;
            End;
        End;
        for ch:='A' to 'Z' do
          if u^.a[ch]<>nil then
          Begin
            Next[u^.v,ch]:=u^.A[ch]^.v;
            Build(u^.A[ch]);
          End;
end;

Procedure Push;
var j:longint;
p:TTrie;
u:longint;
begin
        p:=root;
          For j:=1 to length(st) do
          begin
            if p^.a[st[j]]=nil then Begin
            init(p^.a[st[j]]);
            p^.a[st[j]]^.st:=p^.st+st[j]; End;
            p:=p^.a[st[j]]
          end;
        p^.kt:=true;
        p^.l:=length(st);
end;

Function Rec(i,k,j:longint):longint; {den i con k , nut j}
var ch:char;
p:TTrie;
begin
        if (i=n) then exit(longint(k=0));
        if k>10 then exit(0);
        if Vis[i,k,j] then exit(F[i,k,j]);
        Vis[i,k,j]:=true;
        for ch:='A' to 'Z' do
        begin
          if Next[j,ch]<>0 then
          Begin
            p:=T[Next[j,ch]];
            if p^.kt then
            Begin
              if k+1<=p^.l then
              F[i,k,j]:=(F[i,k,j]+Rec(i+1,0,Next[j,ch])) mod cmod;
            end
            else
            F[i,k,j]:=(F[i,k,j]+Rec(i+1,k+1,Next[j,ch])) mod cmod;
          End;
        End;
        Rec:=F[i,k,j];

end;

Procedure DP;
var i,j:longint;
ch:char;
begin
        writeln(f2,Rec(0,0,1));
end;

begin
        assign(f1,'');reset(f1);
        assign(f2,'');rewrite(f2);
        readln(f1,n,m);
        Init(root);
        for i:=1 to m do
        Begin
          readln(F1,st);
          push;
        End;
        Build(root);
        DP;
        close(f1);
        close(f2);
end.

const cmod = 1000000007;

type Ttrie = ^kdl;
kdl = record
v:longint;
a:array['A'..'Z'] of TTrie;
kt:boolean;
st:string;
End;

const maxn=1000;
maxnode=1000;
var f1,f2:text;
A:array[1..maxn] of longint;
TNil:TTrie;
st:string;
Root:TTrie;
Next:array[1..maxn,'A'..'Z'] of longint;
F:array[0..maxn,0..20,1..maxnode] of longint;
Vis:array[0..maxn,0..20,1..maxnode] of boolean;
T:array[1..maxnode] of Ttrie;
spt,m:longint;
res:longint;
n,i:longint;

Procedure init(var u:TTrie);
var ch:char;
begin
        new(u);
        for ch:='A' to 'Z' do
          u^.a[ch]:=nil;
        inc(spt);
        u^.v:=spt;
        u^.kt:=false;
        u^.st:='';
        T[spt]:=u;
end;

Function Search(st:string):longint;
var p:TTrie;
i:longint;
begin
        p:=root;
        for i:=1 to length(st) do
          if p^.a[st[i]]<>nil then p:=p^.a[st[i]] else exit(-1);
        Search:=p^.v;
end;

Procedure Build(u:TTrie);
var p:TTrie;
ch:char;
x:longint;
j:longint;
st:string;
begin
        for ch:='A' to 'Z' do
        Begin
          Next[u^.v,ch]:=1;
          For j:=2 to length(u^.st)+1 do
            begin
              x:=search(copy(u^.st,j,length(u^.st)-1)+ch);
              if x<>-1 then
              Begin
                Next[u^.v,ch]:=x;
                break;
              End;
            End;
        End;
        for ch:='A' to 'Z' do
          if u^.a[ch]<>nil then
          Begin
            Next[u^.v,ch]:=u^.A[ch]^.v;
            Build(u^.A[ch]);
          End;
end;

Procedure Push;
var j:longint;
p:TTrie;
u:longint;
begin
        p:=root;
          For j:=1 to length(st) do
          begin
            if p^.a[st[j]]=nil then Begin
            init(p^.a[st[j]]);
            p^.a[st[j]]^.st:=p^.st+st[j]; End;
            p:=p^.a[st[j]]
          end;
        p^.kt:=true;
end;

Function Rec(i,k,j:longint):longint; {den i con k , nut j}
var ch:char;
p:TTrie;
begin
        if (i=n) then exit(longint(k=0));
        if k>10 then exit(0);
        if Vis[i,k,j] then exit(F[i,k,j]);
        Vis[i,k,j]:=true;
        for ch:='A' to 'Z' do
        begin

          if Next[j,ch]<>0 then
          Begin
            p:=T[Next[j,ch]];
            if p^.kt then
            Begin
              if k+1<=length(p^.st) then
              F[i,k,j]:=(F[i,k,j]+Rec(i+1,0,Next[j,ch])) mod cmod;
            end
            else
            F[i,k,j]:=(F[i,k,j]+Rec(i+1,k+1,Next[j,ch])) mod cmod;
          End;
        End;
        Rec:=F[i,k,j];

end;

Procedure DP;
var i,j:longint;
ch:char;
begin
        writeln(f2,Rec(0,0,1));
end;

begin
        assign(f1,'');reset(f1);
        assign(f2,'');rewrite(f2);
        readln(f1,n,m);
        Init(root);
        for i:=1 to m do
        Begin
          readln(F1,st);
          push;
        End;
        Build(root);
        DP;
        close(f1);
        close(f2);
end.

{$mode objfpc}
const pm=1000000009;

function trans(const ch:char):longint;
begin case ch of
		'A':	exit(0);
		'C':	exit(1);
		'G':	exit(2);
		'T':	exit(3);
	end;
end;

type
	dfa=	object
			ep,root:longint;
			b:array[0..10010] of record
								next:array[0..3] of longint;
								depth,fail:longint;
								flag:boolean;
							end;
			q:array[0..10010] of longint;
			function Create(x:longint):longint;
			procedure init();
			procedure ins(const s:string);
			procedure build();
		end;

	function dfa.Create(x:longint):longint;
	begin inc(ep); fillchar(b[ep].next,sizeof(b[ep].next),255);
		b[ep].depth:=x; b[ep].fail:=-1; b[ep].flag:=false; exit(ep);
	end;

	procedure dfa.init();
	begin ep:=0; root:=Create(0); end;

	procedure dfa.ins(const s:string);
	var cur,i,x:longint;
	begin cur:=root;
		for i:=1 to length(s) do
		begin x:=trans(s[i]);
			if b[cur].next[x]=-1 then b[cur].next[x]:=Create(b[cur].depth+1);
			cur:=b[cur].next[x];
		end;
		b[cur].flag:=true;
	end;

	procedure dfa.build();
	var head,tail,cur,i:longint;
	begin head:=1; tail:=2; q[head]:=root; b[root].fail:=-1;
		while head<tail do
		begin cur:=q[head]; inc(head);
			for i:=0 to 3 do
			begin if b[cur].next[i]<>-1 then begin q[tail]:=b[cur].next[i]; inc(tail); end;
				if b[cur].fail=-1 then
					if b[cur].next[i]=-1 then
						b[cur].next[i]:=root
					else  b[b[cur].next[i]].fail:=root
				else  if b[cur].next[i]=-1 then
						b[cur].next[i]:=b[b[cur].fail].next[i]
					else  b[b[cur].next[i]].fail:=b[b[cur].fail].next[i];
			end;
		end;
	end;

var
ac:dfa;
ss:string;
dp:array[0..1010,0..110,0..11] of longint;

procedure lemon();
var n,m,i,node,L,k,x,y,ans:longint;
begin readln(n,m);
	ac.init();
	for i:=1 to m do begin readln(ss); ac.ins(ss); end;
	//dp[n][node][L]	length(n) string having suffix(node) and the first L letters of the suffix have been covered
	ac.build();
	with ac do
	begin dp[0][1][0]:=1;
		for i:=0 to n-1 do
			for node:=1 to ep do
				for L:=0 to b[node].depth do
					if dp[i,node,L]>0 then
						for k:=0 to 3 do
						begin //writeln(i,' ',node,' ',L,' ',k,' ',b[node].next[k]);
							y:=b[node].next[k]; if y=-1 then continue;
							x:=L-(b[node].depth-b[y].depth+1);
							if x>=0 then
							begin if b[y].flag then x:=b[y].depth;
								inc(dp[i+1,y,x],dp[i,node,L]);
								if dp[i+1,y,x]>=pm then dec(dp[i+1,y,x],pm);
								//writeln(i+1,' ',y,' ',x,' ',dp[i+1,y,x]);
							end;
						end;
	end;
	ans:=0;
	for i:=1 to ac.ep do ans:=(ans+dp[n,i,ac.b[i].depth]) mod pm;
	writeln(ans);
end;

begin
{$ifndef ONLINE_JUDGE}
	assign(input,'86C.in');
	reset(input);
{$endif}
lemon();
end.

{$R+,S+,Q+,I+,O-}
{R-,S-,Q-,I-,O+}
const md = round(1e9+9);
      let: string = 'ACGT';
var
  ans,ii,jj,kk,max,km,nn,m,n,i,j,t,q,k: longint;
  dd: boolean;
  sw,s: array [0..110] of string;
  ss,st: string;
  a: array [0..110,'A'..'Z'] of longint;
  fn: array [0..110,0..110] of longint;
  word: array [0..110] of boolean;
  pv,de,len: array [0..110] of longint;
  pc: array [0..110] of char;
  f: array [0..1010,0..110,0..11] of longint;
begin
//  assign(input,'in'); reset(input);
//  assign(output,'out'); rewrite(output);
  readln(nn,m);
  fillchar(a,sizeof(a),0);
  fillchar(word,sizeof(word),False);
  n:=1;
  de[1]:=0;
  for i:=1 to m do
  begin
    readln(s[i]);
    len[i]:=length(s[i]);
    t:=1;
    for j:=1 to len[i] do
    begin
      if a[t,s[i,j]] = 0 then
      begin
        inc(n);
        pv[n]:=t;
        pc[n]:=s[i,j];
        de[n]:=de[t]+1;
        a[t,s[i,j]]:=n;
      end;
      t:=a[t,s[i,j]];
    end;
    word[t]:=True;
  end;
  sw[1]:='';
  for i:=2 to n do sw[i]:=sw[pv[i]]+pc[i];
  dd:=True;
  while dd do
  begin
    dd:=False;
    for i:=1 to n do
      if word[i] then
        for j:=1 to n do
          if not word[j] then
            if length(sw[j]) > length(sw[i]) then
              if Copy(sw[j],length(sw[j])-length(sw[i])+1,length(sw[i])) = sw[i] then
              begin
                word[j]:=True;
                dd:=True;
              end;
  end;
  for i:=1 to n do
    for q:=1 to 4 do
    begin
      st:='';
      t:=i;
      while t > 1 do
      begin
        st:=pc[t]+st;
        t:=pv[t];
      end;
      st:=st+let[q];
      max:=0; km:=1;
      for ii:=2 to n do
      begin
        ss:=''; t:=ii;
        while t > 1 do
        begin
          ss:=pc[t]+ss;
          t:=pv[t];
        end;
        if length(ss) > length(st) then continue;
        if Copy(st,length(st)-length(ss)+1,length(ss)) = ss then
          if length(ss) > max then
          begin
            max:=length(ss);
            km:=ii;
          end;
      end;
      fn[i,q]:=km;
    end;
  fillchar(f,sizeof(f),0);
  f[0,1,0]:=1;
  for i:=0 to nn-1 do
    for j:=1 to n do
      for k:=0 to de[j] do
        if f[i,j,k] > 0 then
          for q:=1 to 4 do
          begin
            ii:=i+1;
            jj:=fn[j,q];
            kk:=k+1;
            if word[jj] and (de[jj] >= k+1) then kk:=0;
            inc(f[ii,jj,kk],f[i,j,k]);
            if f[ii,jj,kk] >= md then dec(f[ii,jj,kk],md);
          end;
  ans:=0;
  for i:=1 to n do ans:=(ans+f[nn,i,0]) mod md;
  writeln(ans);
  close(input);
  close(output);
end.

{R+,S+,Q+,I+,O-}
{$R-,S-,Q-,I-,O+}
const md = round(1e9+9);
      let: string = 'ACGT';
var
  ans,ii,jj,kk,max,km,nn,m,n,i,j,t,q,k: longint;
  s: array [0..110] of string;
  ss,st: string;
  a: array [0..110,'A'..'Z'] of longint;
  fn: array [0..110,0..110] of longint;
  word: array [0..110] of boolean;
  pv,de,len: array [0..110] of longint;
  pc: array [0..110] of char;
  f: array [0..1010,0..110,0..11] of longint;
begin
//  assign(input,'in'); reset(input);
//  assign(output,'out'); rewrite(output);
  readln(nn,m);
  fillchar(a,sizeof(a),0);
  fillchar(word,sizeof(word),False);
  n:=1;
  de[1]:=0;
  for i:=1 to m do
  begin
    readln(s[i]);
    len[i]:=length(s[i]);
    t:=1;
    for j:=1 to len[i] do
    begin
      if a[t,s[i,j]] = 0 then
      begin
        inc(n);
        pv[n]:=t;
        pc[n]:=s[i,j];
        de[n]:=de[t]+1;
        a[t,s[i,j]]:=n;
      end;
      t:=a[t,s[i,j]];
    end;
    word[t]:=True;
  end;
  for i:=1 to n do
    for q:=1 to 4 do
    begin
      st:='';
      t:=i;
      while t > 1 do
      begin
        st:=pc[t]+st;
        t:=pv[t];
      end;
      st:=st+let[q];
      max:=0; km:=1;
      for ii:=2 to n do
      begin
        ss:=''; t:=ii;
        while t > 1 do
        begin
          ss:=pc[t]+ss;
          t:=pv[t];
        end;
        if length(ss) > length(st) then continue;
        if Copy(st,length(st)-length(ss)+1,length(ss)) = ss then
          if length(ss) > max then
          begin
            max:=length(ss);
            km:=ii;
          end;
      end;
      fn[i,q]:=km;
    end;
  fillchar(f,sizeof(f),0);
  f[0,1,0]:=1;
  for i:=0 to nn-1 do
    for j:=1 to n do
      for k:=0 to de[j] do
        if f[i,j,k] > 0 then
          for q:=1 to 4 do
          begin
            ii:=i+1;
            jj:=fn[j,q];
            kk:=k+1;
            if word[jj] then kk:=0;
            inc(f[ii,jj,kk],f[i,j,k]);
            if f[ii,jj,kk] >= md then dec(f[ii,jj,kk],md);
          end;
  ans:=0;
  for i:=1 to n do ans:=(ans+f[nn,i,0]) mod md;
  writeln(ans);
  close(input);
  close(output);
end.

{R+,S+,Q+,I+,O-}
{$R-,S-,Q-,I-,O+}
const md = round(1e9+9);
      let: string = 'ACGT';
var
  ans,ii,jj,kk,max,km,nn,m,n,i,j,t,q,k: longint;
  s: array [0..110] of string;
  ss,st: string;
  a: array [0..110,'A'..'Z'] of longint;
  fn: array [0..110,0..110] of longint;
  word: array [0..110] of boolean;
  pv,de,len: array [0..110] of longint;
  pc: array [0..110] of char;
  f: array [0..1010,0..110,0..11] of longint;
begin
//  assign(input,'in'); reset(input);
//  assign(output,'out'); rewrite(output);
  readln(nn,m);
  fillchar(a,sizeof(a),0);
  fillchar(word,sizeof(word),False);
  n:=1;
  de[1]:=0;
  for i:=1 to m do
  begin
    readln(s[i]);
    len[i]:=length(s[i]);
    t:=1;
    for j:=1 to len[i] do
    begin
      if a[t,s[i,j]] = 0 then
      begin
        inc(n);
        pv[n]:=t;
        pc[n]:=s[i,j];
        de[n]:=de[t]+1;
        a[t,s[i,j]]:=n;
      end;
      t:=a[t,s[i,j]];
    end;
    word[t]:=True;
  end;
  for i:=1 to n do
    for q:=1 to 4 do
    begin
      st:='';
      t:=i;
      while t > 1 do
      begin
        st:=pc[t]+st;
        t:=pv[t];
      end;
      st:=st+let[q];
      max:=0; km:=1;
      for ii:=2 to n do
      begin
        ss:=''; t:=ii;
        while t > 1 do
        begin
          ss:=pc[t]+ss;
          t:=pv[t];
        end;
        if length(ss) > length(st) then break;
        if Copy(st,length(st)-length(ss)+1,length(ss)) = ss then
          if length(ss) > max then
          begin
            max:=length(ss);
            km:=ii;
          end;
      end;
      fn[i,q]:=km;
    end;
  fillchar(f,sizeof(f),0);
  f[0,1,0]:=1;
  for i:=0 to nn-1 do
    for j:=1 to n do
      for k:=0 to de[j] do
        if f[i,j,k] > 0 then
          for q:=1 to 4 do
          begin
            ii:=i+1;
            jj:=fn[j,q];
            kk:=k+1;
            if word[jj] then kk:=0;
            inc(f[ii,jj,kk],f[i,j,k]);
            if f[ii,jj,kk] >= md then dec(f[ii,jj,kk],md);
          end;
  ans:=0;
  for i:=1 to n do ans:=(ans+f[nn,i,0]) mod md;
  writeln(ans);
  close(input);
  close(output);
end.

{$R+,S+,Q+,I+,O-}
{R-,S-,Q-,I-,O+}
const md = round(1e9+9);
      let: string = 'ACGT';
var
  ans,ii,jj,kk,max,km,nn,m,n,i,j,t,q,k: longint;
  dd: boolean;
  sw,s: array [0..110] of string;
  ss,st: string;
  a: array [0..110,'A'..'Z'] of longint;
  fn: array [0..110,0..110] of longint;
  word: array [0..110] of boolean;
  pv,de,len: array [0..110] of longint;
  pc: array [0..110] of char;
  f: array [0..1010,0..110,0..11] of longint;
begin
//  assign(input,'in'); reset(input);
//  assign(output,'out'); rewrite(output);
  readln(nn,m);
  fillchar(a,sizeof(a),0);
  fillchar(word,sizeof(word),False);
  n:=1;
  de[1]:=0;
  for i:=1 to m do
  begin
    readln(s[i]);
    len[i]:=length(s[i]);
    t:=1;
    for j:=1 to len[i] do
    begin
      if a[t,s[i,j]] = 0 then
      begin
        inc(n);
        pv[n]:=t;
        pc[n]:=s[i,j];
        de[n]:=de[t]+1;
        a[t,s[i,j]]:=n;
      end;
      t:=a[t,s[i,j]];
    end;
    word[t]:=True;
  end;
  sw[1]:='';
  for i:=2 to n do sw[i]:=sw[pv[i]]+pc[i];
  dd:=True;
  while dd do
  begin
    dd:=False;
    for i:=1 to n do
      if word[i] then
        for j:=1 to n do
          if not word[j] then
            if length(sw[j]) > length(sw[i]) then
              if Copy(sw[j],length(sw[j])-length(sw[i])+1,length(sw[i])) = sw[i] then
              begin
                word[j]:=True;
                dd:=True;
              end;
  end;
  for i:=1 to n do
    for q:=1 to 4 do
    begin
      st:='';
      t:=i;
      while t > 1 do
      begin
        st:=pc[t]+st;
        t:=pv[t];
      end;
      st:=st+let[q];
      max:=0; km:=1;
      for ii:=2 to n do
      begin
        ss:=''; t:=ii;
        while t > 1 do
        begin
          ss:=pc[t]+ss;
          t:=pv[t];
        end;
        if length(ss) > length(st) then continue;
        if Copy(st,length(st)-length(ss)+1,length(ss)) = ss then
          if length(ss) > max then
          begin
            max:=length(ss);
            km:=ii;
          end;
      end;
      fn[i,q]:=km;
    end;
  fillchar(f,sizeof(f),0);
  f[0,1,0]:=1;
  for i:=0 to nn-1 do
    for j:=1 to n do
      for k:=0 to de[j] do
        if f[i,j,k] > 0 then
          for q:=1 to 4 do
          begin
            ii:=i+1;
            jj:=fn[j,q];
            kk:=k+1;
            if word[jj] and (de[jj] >= k) then kk:=0;
            inc(f[ii,jj,kk],f[i,j,k]);
            if f[ii,jj,kk] >= md then dec(f[ii,jj,kk],md);
          end;
  ans:=0;
  for i:=1 to n do ans:=(ans+f[nn,i,0]) mod md;
  writeln(ans);
  close(input);
  close(output);
end.

{$R+,S+,Q+,I+,O-}
{R-,S-,Q-,I-,O+}
const md = round(1e9+9);
      let: string = 'ACGT';
var
  ans,ii,jj,kk,max,km,nn,m,n,i,j,t,q,k: longint;
  dd: boolean;
  sw,s: array [0..110] of string;
  ss,st: string;
  a: array [0..110,'A'..'Z'] of longint;
  fn: array [0..110,0..110] of longint;
  word: array [0..110] of boolean;
  pv,de,len: array [0..110] of longint;
  pc: array [0..110] of char;
  f: array [0..1010,0..110,0..11] of longint;
begin
//  assign(input,'in'); reset(input);
//  assign(output,'out'); rewrite(output);
  readln(nn,m);
  fillchar(a,sizeof(a),0);
  fillchar(word,sizeof(word),False);
  n:=1;
  de[1]:=0;
  for i:=1 to m do
  begin
    readln(s[i]);
    len[i]:=length(s[i]);
    t:=1;
    for j:=1 to len[i] do
    begin
      if a[t,s[i,j]] = 0 then
      begin
        inc(n);
        pv[n]:=t;
        pc[n]:=s[i,j];
        de[n]:=de[t]+1;
        a[t,s[i,j]]:=n;
      end;
      t:=a[t,s[i,j]];
    end;
    word[t]:=True;
  end;
  sw[1]:='';
  for i:=2 to n do sw[i]:=sw[pv[i]]+pc[i];
  dd:=True;
  while dd do
  begin
    dd:=False;
    for i:=1 to n do
      if word[i] then
        for j:=1 to n do
          if not word[j] then
            if length(sw[j]) > length(sw[i]) then
              if Copy(sw[j],length(sw[j])-length(sw[i])+1,length(sw[i])) = sw[i] then
              begin
                word[j]:=True;
                dd:=True;
              end;
  end;
  for i:=1 to n do
    for q:=1 to 4 do
    begin
      st:='';
      t:=i;
      while t > 1 do
      begin
        st:=pc[t]+st;
        t:=pv[t];
      end;
      st:=st+let[q];
      max:=0; km:=1;
      for ii:=2 to n do
      begin
        ss:=''; t:=ii;
        while t > 1 do
        begin
          ss:=pc[t]+ss;
          t:=pv[t];
        end;
        if length(ss) > length(st) then continue;
        if Copy(st,length(st)-length(ss)+1,length(ss)) = ss then
          if length(ss) > max then
          begin
            max:=length(ss);
            km:=ii;
          end;
      end;
      fn[i,q]:=km;
    end;
  fillchar(f,sizeof(f),0);
  f[0,1,0]:=1;
  for i:=0 to nn-1 do
    for j:=1 to n do
      for k:=0 to de[j] do
        if f[i,j,k] > 0 then
          for q:=1 to 4 do
          begin
            ii:=i+1;
            jj:=fn[j,q];
            kk:=k+1;
            if word[jj] then kk:=0;
            inc(f[ii,jj,kk],f[i,j,k]);
            if f[ii,jj,kk] >= md then dec(f[ii,jj,kk],md);
          end;
  ans:=0;
  for i:=1 to n do ans:=(ans+f[nn,i,0]) mod md;
  writeln(ans);
  close(input);
  close(output);
end.

{$R+,S+,Q+,I+,O-}
{R-,S-,Q-,I-,O+}
const md = round(1e9+9);
      let: string = 'ACGT';
var
  ans,ii,jj,kk,max,km,nn,m,n,i,j,t,q,k: longint;
  s: array [0..110] of string;
  ss,st: string;
  a: array [0..110,'A'..'Z'] of longint;
  fn: array [0..110,0..110] of longint;
  word: array [0..110] of boolean;
  pv,de,len: array [0..110] of longint;
  pc: array [0..110] of char;
  f: array [0..1010,0..110,0..11] of longint;
begin
//  assign(input,'in'); reset(input);
//  assign(output,'out'); rewrite(output);
  readln(nn,m);
  fillchar(a,sizeof(a),0);
  fillchar(word,sizeof(word),False);
  n:=1;
  de[1]:=0;
  for i:=1 to m do
  begin
    readln(s[i]);
    len[i]:=length(s[i]);
    t:=1;
    for j:=1 to len[i] do
    begin
      if a[t,s[i,j]] = 0 then
      begin
        inc(n);
        pv[n]:=t;
        pc[n]:=s[i,j];
        de[n]:=de[t]+1;
        a[t,s[i,j]]:=n;
      end;
      t:=a[t,s[i,j]];
    end;
    word[t]:=True;
  end;
  for i:=1 to n do
    for q:=1 to 4 do
    begin
      st:='';
      t:=i;
      while t > 1 do
      begin
        st:=pc[t]+st;
        t:=pv[t];
      end;
      st:=st+let[q];
      max:=0; km:=1;
      for ii:=2 to n do
      begin
        ss:=''; t:=ii;
        while t > 1 do
        begin
          ss:=pc[t]+ss;
          t:=pv[t];
        end;
        if length(ss) > length(st) then continue;
        if Copy(st,length(st)-length(ss)+1,length(ss)) = ss then
          if length(ss) > max then
          begin
            max:=length(ss);
            km:=ii;
          end;
      end;
      fn[i,q]:=km;
    end;
  fillchar(f,sizeof(f),0);
  f[0,1,0]:=1;
  for i:=0 to nn-1 do
    for j:=1 to n do
      for k:=0 to de[j] do
        if f[i,j,k] > 0 then
          for q:=1 to 4 do
          begin
            ii:=i+1;
            jj:=fn[j,q];
            kk:=k+1;
            if word[jj] then kk:=0;
            inc(f[ii,jj,kk],f[i,j,k]);
            if f[ii,jj,kk] >= md then dec(f[ii,jj,kk],md);
          end;
  ans:=0;
  for i:=1 to n do ans:=(ans+f[nn,i,0]) mod md;
  writeln(ans);
  close(input);
  close(output);
end.

const mode=1000000009;
var tot,n,m,now:longint;
trie1,trie2:array[0..1000,1..4]of longint;
fail,q:array[0..1000]of longint;
danger:array[0..1000]of boolean;
f:array[0..1000,0..1000]of longint;
procedure insert(x:longint);
begin
  if trie1[now,x]=0 then
  begin
    inc(tot);
    trie1[now,x]:=tot;
    now:=tot;
  end else now:=trie1[now,x];
end;
procedure init;
var i,j:longint;
st:string;
begin
  tot:=1;
  readln(n,m);
  for i:=1 to m do
  begin
    readln(st);
    now:=1;
    for j:=1 to length(st) do
    begin
      if st[j]='A' then insert(1);
      if st[j]='C' then insert(2);
      if st[j]='G' then insert(3);
      if st[j]='T' then insert(4);
    end;
    danger[now]:=true;
  end;
end;
procedure build;
var head,tail,i,x:longint;
begin
  trie2:=trie1;tail:=0;
  for i:=1 to 4 do
  begin
    if trie2[1,i]=0 then trie2[1,i]:=1
    else
    begin
      inc(tail);
      q[tail]:=trie2[1,i];
      fail[trie2[1,i]]:=1;
    end;
  end;
  head:=1;
  repeat
    x:=q[head];
    danger[x]:=danger[x] or danger[fail[x]];
    for i:=1 to 4 do
    begin
      if trie2[x,i]=0 then trie2[x,i]:=trie2[fail[x],i]
      else
      begin
        inc(tail);
        q[tail]:=trie2[x,i];
        fail[trie2[x,i]]:=trie2[fail[x],i];
      end;
    end;
    inc(head);
  until head>tail;
end;
procedure work;
var i,j,k,ans:longint;
begin
  f[0,1]:=1;
  for i:=0 to n-1 do
    for j:=1 to tot do
    begin
      if f[i,j]=0 then continue;
      for k:=1 to 4 do
      begin
        if danger[j] then
        begin
          if trie2[j,k]<>1 then
            f[i+1,trie2[j,k]]:=(f[i+1,trie2[j,k]]+f[i,j])mod mode;
        end
        else
        begin
          if trie1[j,k]<>0 then
          begin
            f[i+1,trie1[j,k]]:=(f[i+1,trie1[j,k]]+f[i,j])mod mode;
          end;
        end;
      end;
    end;
  ans:=0;
  for i:=1 to tot do
    if danger[i] then ans:=(ans+f[n,i])mod mode;
  writeln(ans);
end;
begin
  init;
  build;
  work;
end.

const mode=1000000009;
var tot,n,m,now:longint;
trie1,trie2:array[0..1000,1..4]of longint;
fail,q,danger:array[0..100]of longint;
f:array[0..1000,0..100,0..10]of longint;
function getmax(a,b:longint):longint;
begin
  if a>b then getmax:=a else getmax:=b;
end;
procedure insert(x:longint);
begin
  if trie1[now,x]=0 then
  begin
    inc(tot);
    trie1[now,x]:=tot;
    now:=tot;
  end else now:=trie1[now,x];
end;
procedure init;
var i,j:longint;
st:string;
begin
  tot:=1;
  readln(n,m);
  for i:=1 to m do
  begin
    readln(st);
    now:=1;
    for j:=1 to length(st) do
    begin
      if st[j]='A' then insert(1);
      if st[j]='C' then insert(2);
      if st[j]='G' then insert(3);
      if st[j]='T' then insert(4);
    end;
    danger[now]:=length(st);
  end;
end;
procedure build;
var head,tail,i,x:longint;
begin
  trie2:=trie1;tail:=0;
  for i:=1 to 4 do
  begin
    if trie2[1,i]=0 then trie2[1,i]:=1
    else
    begin
      inc(tail);
      q[tail]:=trie2[1,i];
      fail[trie2[1,i]]:=1;
    end;
  end;
  head:=1;
  repeat
    x:=q[head];
    danger[x]:=getmax(danger[x],danger[fail[x]]);
    for i:=1 to 4 do
    begin
      if trie2[x,i]=0 then trie2[x,i]:=trie2[fail[x],i]
      else
      begin
        inc(tail);
        q[tail]:=trie2[x,i];
        fail[trie2[x,i]]:=trie2[fail[x],i];
      end;
    end;
    inc(head);
  until head>tail;
end;
procedure work;
var i,j,k,ans,v:longint;
begin
  f[0,1,0]:=1;
  for i:=0 to n-1 do
    for j:=1 to tot do
      for v:=0 to 9 do
      begin
        if f[i,j,v]=0 then continue;
        for k:=1 to 4 do
        begin
          if v=0 then
          begin
            if trie2[j,k]=1 then continue;
            if danger[trie2[j,k]]>v then f[i+1,trie2[j,k],0]:=(f[i+1,trie2[j,k],0]+f[i,j,v])mod mode
            else f[i+1,trie2[j,k],1]:=(f[i+1,trie2[j,k],1]+f[i,j,0])mod mode;
          end
          else
          begin
            if trie1[j,k]=0 then continue;
            if danger[trie1[j,k]]>v then f[i+1,trie1[j,k],0]:=(f[i+1,trie1[j,k],0]+f[i,j,v])mod mode
            else f[i+1,trie1[j,k],v+1]:=(f[i+1,trie1[j,k],v+1]+f[i,j,v])mod mode;
          end;
        end;
      end;
  ans:=0;
  for i:=1 to tot do
    ans:=(ans+f[n,i,0])mod mode;
  writeln(ans);
end;
begin
  init;
  build;
  work;
end.