#include <bits/stdc++.h>
using namespace std;
const int cmx = 1e5 + 5;
int n;
int q;
vector<pair<string, string> > v;
bool isOk(string s) {
  while (1) {
    if (s.size() == 1) break;
    bool ok = false;
    string temp = "";
    for (int i = 0; i < v.size(); i++) {
      string a = v[i].first;
      string b = v[i].second;
      if (s[0] == a[0] and s[1] == a[1]) {
        temp += b;
        for (int i = 2; i < s.size(); i++) temp += s[i];
        ok = true;
        break;
      }
    }
    s = temp;
    if (!ok) return false;
  }
  if (s == "a") return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    string a, b;
    cin >> a >> b;
    v.push_back({a, b});
  }
  int ans = 0;
  for (char c0 = 'a'; c0 <= 'f'; c0++) {
    for (char c1 = 'a'; c1 <= 'f'; c1++) {
      if (n == 2) {
        string s = "";
        s += c0;
        s += c1;
        ans += isOk(s);
        continue;
      }
      for (char c2 = 'a'; c2 <= 'f'; c2++) {
        if (n == 3) {
          string s = "";
          s += c0;
          s += c1;
          s += c2;
          ans += isOk(s);
          continue;
        }
        for (char c3 = 'a'; c3 <= 'f'; c3++) {
          if (n == 4) {
            string s = "";
            s += c0;
            s += c1;
            s += c2;
            s += c3;
            ans += isOk(s);
            continue;
          }
          for (char c4 = 'a'; c4 <= 'f'; c4++) {
            if (n == 5) {
              string s = "";
              s += c0;
              s += c1;
              s += c2;
              s += c3;
              s += c4;
              ans += isOk(s);
              continue;
            }
            for (char c5 = 'a'; c5 <= 'f'; c5++) {
              string s = "";
              s += c0;
              s += c1;
              s += c2;
              s += c3;
              s += c4;
              s += c5;
              ans += isOk(s);
            }
          }
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
