func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T>   T modpow(T base, T exp) {     T result = 1;     while (exp > 0) {       if (exp & 1) result = (result * base);       base = (base * base);       exp >>= 1;     }     return result;   }   int main() {     queue<string> poss;     long long int n, q;     string x, y, poss1;     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> q;     map<string, vector<string> > m;     for (long long int(i) = (0); (i) < (q); (i)++) {       cin >> x >> y;       m[y].push_back(x);     }     map<string, vector<string> >::iterator it;     it = m.begin();     if ((*it).first !=  a ) {       cout << 0 << endl;       return 0;     } else {       for (long long int(i) = (0); (i) < (m[ a ].size()); (i)++)         poss.push((m[ a ])[i]);       int cnt = 2;       while (cnt != n) {         while ((poss.front()).length() != cnt + 1) {           string c = (poss.front()).substr(0, 1);           if (m.find(c) != m.end()) {             string str = poss.front();             poss.pop();             str = str.substr(1, str.length() - 1);             for (long long int(j) = (0); (j) < (m[c].size()); (j)++)               poss.push(m[c][j] + str);           } else             poss.pop();           if (poss.empty()) {             cout <<  0  << endl;             return 0;           }         }         cnt++;       }     }     cout << poss.size() << endl;     return 0;   }   