#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  queue<string> qi;
  queue<string> qq;
  qi.push("a");
  vector<char> v;
  vector<string> v1;
  for (int i = 0; i < m; i++) {
    string ss;
    char sss;
    cin >> ss >> sss;
    v.push_back(sss);
    v1.push_back(ss);
  }
  set<string> s1;
  while (!qi.empty()) {
    string topi = qi.front();
    qi.pop();
    if (topi.size() == n + 1) break;
    if (topi.size() == n) s1.insert(topi);
    for (int i = 0; i < v.size(); i++) {
      if (topi[0] == v[i]) {
        string tt = v1[i];
        for (int j = 1; j < topi.size(); j++) tt += topi[j];
        qi.push(tt);
      }
    }
  }
  cout << s1.size() << endl;
  return 0;
}
