#include <bits/stdc++.h>
using namespace std;
multimap<char, string> m;
int n, k;
int dfs(char a, int sz) {
  int sum = 0;
  if (sz == n) return 1;
  pair<multimap<char, string>::iterator, multimap<char, string>::iterator> ret;
  ret = m.equal_range(a);
  for (multimap<char, string>::iterator it = ret.first; it != ret.second;
       it++) {
    string tem = it->second;
    sum += dfs(tem[0], sz + 1);
  }
  return sum;
}
void solve() {
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    string tem1;
    char tem2;
    cin >> tem1 >> tem2;
    m.insert(pair<char, string>(tem2, tem1));
  }
  cout << dfs('a', 1) << endl;
}
int main() {
  solve();
  return 0;
}
