#include <bits/stdc++.h>
using namespace std;
const int N = 1e8 + 5;
long long MAX = 1e9;
long long MOD = 1e9 + 7;
long long Mod = 1e9 + 7;
double EPS = 0.0001;
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); }
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
vector<string> possAns;
map<string, vector<string>> swps;
int n;
set<string> ans;
void Solve(string st) {
  if (st.length() == n) {
    ans.insert(st);
  } else {
    int i = 0;
    if (swps.find(st.substr(i, 1)) != swps.end()) {
      vector<string> ok = swps[st.substr(i, 1)];
      for (auto a : ok) {
        string st2 = st.substr(0, i);
        st2 += a;
        st2 += st.substr(i + 1);
        Solve(st2);
      }
    }
  }
}
int main() {
  int q;
  cin >> n >> q;
  for (long long i = 0; i < q; i++) {
    string st1, st2;
    cin >> st1 >> st2;
    swps[st2].push_back(st1);
  }
  Solve("a");
  cout << ans.size() << endl;
  return 0;
}
