#include <bits/stdc++.h>
using namespace std;
vector<pair<string, string>> v;
long long ans = 0, n, m;
void dfs(string s) {
  if (s.length() == n) {
    ans++;
    return;
  }
  for (long long i = 0; i < m; i++) {
    if (s[0] == v[i].second[0]) dfs(v[i].first + s.substr(1));
  }
}
int main() {
  string x, y;
  cin >> n >> m;
  ;
  for (long long i = 1; i <= m; i++) {
    cin >> x >> y;
    v.push_back(make_pair(x, y));
  }
  dfs("a");
  cout << ans << endl;
  return 0;
}
