#include <bits/stdc++.h>
using namespace std;
int ans = 0;
int n, q;
string a[50], b[50];
void solve(int p, char x) {
  if (p == n) {
    ans++;
    return;
  }
  for (int i = 1; i <= q; i++) {
    if (b[i][0] == x) solve(p + 1, a[i][0]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t) {
    cin >> n >> q;
    for (int i = 1; i < q + 1; i++) cin >> a[i] >> b[i];
    using ans_type = void;
    solve(1, 'a');
    cout << ans;
    cout << endl;
    t--;
  }
  return 0;
}
