#include <bits/stdc++.h>
using namespace std;
int connection[7][7];
int n, q;
int sum = 0;
void dfs(int s, int count, int mul) {
  if (count == n) {
    sum += mul;
    return;
  }
  for (int i = 0; i < 6; i++) {
    if (connection[s][i] > 0) {
      dfs(i, count + 1, mul * connection[s][i]);
    }
  }
}
int main() {
  while (cin >> n >> q) {
    cin.get();
    memset(connection, 0, sizeof(connection));
    sum = 0;
    for (int i = 0; i < q; i++) {
      string str;
      getline(cin, str);
      int s = str[str.length() - 1] - 'a';
      int t = str[0] - 'a';
      connection[s][t]++;
    }
    dfs(0, 1, 1);
    cout << sum << endl;
  }
}
