#include <bits/stdc++.h>
using namespace std;
int n, q;
string a, b;
set<string> S;
map<char, set<string>> ab;
int go(string s) {
  if (s.length() == n)
    S.insert(s);
  else
    for (auto &a : ab[s[0]]) go(a + s.substr(1, 42));
  return S.size();
}
int main() {
  for (cin >> n >> q; q--; ab[b[0]].insert(a)) cin >> a >> b;
  cout << go("a");
}
