#include <bits/stdc++.h>
using namespace std;
int n, q;
string a[50];
string b[50];
int dfs(char c, int dep) {
  if (dep == n - 1) {
    return 1;
  }
  int ans = 0;
  for (long long int i = 1; i <= q; i++) {
    if (b[i][0] == c) {
      ans += dfs(a[i][0], dep + 1);
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> q;
  for (long long int i = 1; i <= q; i++) {
    cin >> a[i] >> b[i];
  }
  cout << dfs('a', 0);
  return 0;
}
