#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
int64_t fx[10] = {0, 1, 0, -1, 1, -1, 1, -1};
int64_t fy[10] = {1, 0, -1, 0, 1, -1, -1, 1};
const long long M = 2e5 + 10, M2 = 1e6 + 6, oo = 1e9 + 7, mod = 998244353;
const long long MC = (1 << 20) + 5;
int64_t ara[2005];
map<int64_t, map<string, int64_t> > dp;
map<int64_t, string> mark;
map<string, map<string, int64_t> > bad;
vector<vector<int64_t> > adj;
vector<string> allcolors;
int64_t bigmod(int64_t n, int64_t p, int64_t md) {
  if (p == 0) return 1;
  int64_t ans = bigmod(n, p / 2, oo);
  ans = (ans * ans) % md;
  if (p & 1) ans = (ans * n) % oo;
  return ans;
}
void precomp() {}
void solve() {
  int64_t kval, n, ans = 0;
  vector<int64_t> vec;
  queue<int64_t> q;
  cin >> kval >> n;
  allcolors = {"white", "yellow", "green", "blue", "red", "orange"};
  for (string s : allcolors) {
    for (string ss : allcolors) {
      bad[s][ss] = 0;
    }
  }
  for (int64_t i = 0; i < 6; i += 2) {
    bad[allcolors[i]][allcolors[i + 1]] = 1;
    bad[allcolors[i + 1]][allcolors[i]] = 1;
  }
  for (string s : allcolors) {
    bad[s][s] = 1;
  }
  string s;
  for (int64_t i = 0; i < n; i++) {
    cin >> ara[i] >> s;
    q.push(ara[i]);
    for (string s : allcolors) dp[ara[i]][s] = 0;
    dp[ara[i]][s] = 1;
  }
  for (int64_t i = 0; i < n; i++) {
    int64_t u = ara[i];
    while (u >= 1 && mark.count(u) == 0) {
      mark[u] = 1;
      vec.push_back(u);
      u = u / 2;
    }
  }
  mark[1] = 1;
  vec.push_back(1);
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  reverse(vec.begin(), vec.end());
  int64_t sz = (int64_t)(vec.size());
  for (int64_t u : vec) {
    for (string c : allcolors) {
      int64_t lnum = 0, rnum = 0;
      for (string cc : allcolors) {
        if (!mark.count(u * 2))
          lnum = 1;
        else if (!bad[c][cc]) {
          lnum += dp[u * 2][cc];
          lnum %= oo;
        }
        if (!mark.count(u * 2 + 1))
          rnum = 1;
        else if (!bad[c][cc]) {
          rnum += dp[u * 2 + 1][cc];
          rnum %= oo;
        }
      }
      if (dp[u].count(c) == 0) dp[u][c] = 1;
      dp[u][c] *= (lnum * rnum) % oo;
      dp[u][c] %= oo;
    }
  }
  int64_t tot = (1LL << kval) - 1;
  tot -= sz;
  ans = bigmod(4LL, tot, oo);
  int64_t sm = 0;
  for (string s : allcolors) {
    if (dp[1].count(s)) sm = (sm + dp[1][s]) % oo;
  }
  ans = (ans * sm) % oo;
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  precomp();
  solve();
  return 0;
}
