#include <bits/stdc++.h>
using namespace std;
map<char, vector<string>> change;
set<string> vis;
queue<string> q;
int n, m;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    string a, b;
    cin >> a >> b;
    change[b[0]].push_back(a);
  }
  int ans = 0;
  q.push("a");
  vis.insert("a");
  while (!q.empty()) {
    string s = q.front();
    q.pop();
    if ((int)s.size() == n) {
      ans++;
      continue;
    }
    for (string tmp : change[s[0]]) {
      string t = tmp + s.substr(1);
      if (!vis.count(t)) {
        vis.insert(t);
        q.push(t);
      }
    }
  }
  printf("%d\n", ans);
}
