#include <bits/stdc++.h>
using namespace std;
int dp(char c, int count, int n, vector<char> vec[]) {
  if (count == n) {
    return 1;
  } else {
    int value = 0;
    for (int i = 0; i < vec[c - 'a'].size(); i++) {
      value = value + dp(vec[c - 'a'][i], count + 1, n, vec);
    }
    return value;
  }
}
int main() {
  int n, count;
  cin >> n >> count;
  char str[3], b;
  vector<char> vec[6];
  for (int i = 0; i < count; i++) {
    cin >> str >> b;
    vec[b - 'a'].push_back(str[0]);
  }
  cout << dp('a', 1, n, vec);
  return 0;
}
