#include <bits/stdc++.h>
using namespace std;
long long n, m, c, suf[111], nx[111][4], dp[1010][111][11];
string s[11], C = "ATCG";
set<string> S;
map<string, int> M;
map<string, int>::iterator it;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s[i];
    S.insert(s[i]);
    for (int j = 0; j < s[i].size() + 1; j++)
      if (M.find(s[i].substr(0, j)) == M.end()) {
        M[s[i].substr(0, j)] = c;
        c++;
      }
  }
  for (it = M.begin(); it != M.end(); it++) {
    for (int i = 0; i < it->first.size() + 1; i++)
      if (S.count(it->first.substr(i))) {
        suf[it->second] = it->first.size() - i;
        break;
      }
  }
  for (it = M.begin(); it != M.end(); it++)
    for (int i = 0; i < 4; i++) {
      string t = it->first + C[i];
      while (M.find(t) == M.end()) t = t.substr(1);
      nx[it->second][i] = M[t];
    }
  dp[0][0][0] = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < c; j++)
      for (int k = 0; k < 10; k++)
        if (dp[i][j][k])
          for (int l = 0; l < 4; l++) {
            int next = nx[j][l];
            if (suf[next] >= k + 1)
              dp[i + 1][next][0] =
                  (dp[i + 1][next][0] + dp[i][j][k]) % 1000000009LL;
            else {
              if (k + 1 == 10) continue;
              dp[i + 1][next][k + 1] =
                  (dp[i + 1][next][k + 1] + dp[i][j][k]) % 1000000009LL;
            }
          }
  long long ans = 0;
  for (int i = 0; i < c; i++) ans = (ans + dp[n][i][0]) % 1000000009LL;
  cout << ans;
}
