// Decline is inevitable,
// Romance will last forever.
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define LL long long
#define bug(x) cout << x << '\n'
#define int long long
const int maxn = 60 + 10;
const int maxm = 1e3 + 10;
const int INF = 0x3f3f3f3f;
const int dx[] = {0, 0, -1, 1}; //{0, 0, 1, 1, 1,-1,-1,-1}
const int dy[] = {1, -1, 0, 0}; //{1,-1, 1, 0,-1, 1, 0,-1}
const int P = 1e9 + 7;
int k, n;
LL power(LL a, LL b) {
LL ans = 1 % P;
for (; b; b >>= 1) {
if (b & 1) ans = ans * a % P;
a = a * a % P;
}
return ans;
}
map<string, int> m1;
ll dp[maxn][7];
void solve() {
cin >> k >> n;
memset(dp, 0, sizeof(dp));
for(int i = 1; i <= 6; i++) dp[1][i] = 1;
for(int i = 2; i <= k; i++)
for(int j = 1; j <= 6; j++)
for(int k = 1; k <= 6; k++)
for(int p = 1; p <= 6; p++) {
if(j==p || j+p==7 || k==p || k+p==7) continue;
dp[i][p] += dp[i-1][j] * dp[i-1][k];
dp[i][p]%=P;
}
m1["white"] = 1; m1["yellow"] = 6;
m1["green"] = 2; m1["blue"] = 5;
m1["red"] = 3; m1["orange"] = 4;
struct node {
ll v[7];
node(){memset(v, 0, sizeof(v));}
};
map<ll, node> ans;
map<ll, int> col, vis;
priority_queue<ll> pq;
for(int i = 1; i <= n; i++) {
ll x; string s;
cin >> x >> s;
col[x] = m1[s];
pq.push(x);
vis[x] = 1;
}
while(!pq.empty()) {
ll t = pq.top();
pq.pop();
node n1, n2;
if(t >= pow(2, k-1)) {
node tmp;
tmp.v[col[t]] = 1;
ans[t] = tmp;
if(!vis[t >> 1]) pq.push(t >> 1);
continue;
}
if(!col[t<<1])
for(int i = 1; i <= 6; i++)
n1.v[i] = dp[k-(int)log2(t*2)][i];
else n1 = ans[t << 1];
if(!col[t<<1|1])
for(int i = 1; i <= 6; i++)
n2.v[i] = dp[k-(int)log2(t*2+1)][i];
else n2 = ans[t << 1|1];
node tmp;
for(int j = 1; j <= 6; j++)
for(int k = 1; k <= 6; k++)
for(int p = 1; p <= 6; p++) {
if(j == p || k == p || j + p == 7 || k + p == 7) continue;
tmp.v[p] += n1.v[j] * n2.v[k];
tmp.v[p] %= P;
}
if(col[t]) {
for(int i = 1; i <= 6; i++) {
if(i != col[t]) tmp.v[i] = 0;
}
}
else {
col[t] = 7;
}
ans[t] = tmp;
if(t>=2 && !vis[t/2])pq.push(t/2), vis[t/2] = 1;
}
ll res = 0;
for(int i = 1; i <= 6; i++)
res = (res + ans[1].v[i]) % P;
cout << res << '\n';
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// int T; scanf("%d", &T); while(T--)
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
// int T; cin >> T;while(T--)
solve();
return 0;
}
/*
*/