#include <bits/stdc++.h>
using namespace std;
const long long mod = 2019;
const long double pi = acos(-1);
const long long maxn = 300006;
template <class T>
ostream &operator<<(ostream &out, vector<T> &A) {
  for (auto x : A) out << x << " ";
  return out;
}
template <class T>
ostream &operator<<(ostream &out, set<T> &A) {
  for (auto x : A) out << x << " ";
  return out;
}
template <class T1, class T2>
T1 powr(T1 a, T2 b) {
  T1 res = 1;
  for (long long i = 1; i < b + 1; i++) res = res * a;
  return res;
}
long long n, q;
vector<vector<string> > g(6);
set<string> sy;
void dfs(string str) {
  if (str.size() == n) {
    sy.insert(str);
    return;
  }
  for (long long i = 0; i < str.size(); i++) {
    for (auto x : g[str[0] - 'a']) dfs(x + str.substr(1));
  }
}
int32_t main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> q;
  while (q--) {
    string s;
    char t;
    cin >> s >> t;
    g[t - 'a'].push_back(s);
  }
  dfs("a");
  cout << sy.size() << endl;
}
