#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
struct ppp {
  string a, b;
  void read() { cin >> a >> b; }
} ori[40];
int n, m;
map<string, int> ma;
queue<string> que;
int main() {
  while (cin >> n >> m) {
    ma.clear();
    for (int i = 1; i <= m; i++) ori[i].read();
    que.push("a");
    int cnt = 0;
    while (!que.empty()) {
      string temp = que.front();
      que.pop();
      string now = "";
      for (int i = 1; i < temp.length(); i++) now += temp[i];
      for (int i = 1; i <= m; i++) {
        if (ori[i].b[0] == temp[0]) {
          string haha = ori[i].a + now;
          if (ma.find(haha) == ma.end()) {
            ma[haha] = 1;
            if (haha.length() == n) cnt++;
            if (haha.length() <= n) que.push(haha);
          }
        }
      }
    }
    cout << cnt << endl;
  }
}
