#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using D = double;
template <typename T>
using pii = pair<T, T>;
int n, q, ans;
string a[100], b[100];
void dfs(char ch, int i) {
  if (i == n) {
    ans++;
    return;
  }
  for (int j = 0; j < q; j++)
    if (b[j][0] == ch) dfs(a[j][0], i + 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> q;
  for (int i = 0; i < q; i++) cin >> a[i] >> b[i];
  dfs('a', 1);
  cout << ans << '\n';
  return 0;
}
