#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long n, ans, sum, x, k, ret;
string a;
int arr[1000000];
char c, b;
map<char, vector<string> > m;
map<char, int> ma;
void solve(int sz, char v) {
  if (sz == n - 1) {
    ans += ma[v];
    return;
  }
  if (m[v].size() == 0) return;
  for (int i = 0; i < m[v].size(); i++) {
    solve(sz + 1, m[v][i][0]);
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    cin >> a >> b;
    m[b].push_back(a);
    ma[b]++;
  }
  solve(1, 'a');
  cout << ans << endl;
}
