#define taskname "L"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005, oo = 1e9;
vector<int> adj[maxn];
int cap[30], dem[30], mn[30], fx[maxn], ban[maxn][30], cur[maxn], d[maxn], ans[maxn], fxl[30];
int tin[maxn], tout[maxn], cnt, n, m, s, t, _s, _t, cell, l;
string ds[maxn], dt[maxn];
struct edge {
int u, v, de, f, c;
} e[maxn*maxn];
inline void add(int u, int v, int c, int de = 0)
{
if (c == 0) return;
if (v == t) assert(u >= cell+1 && u <= cell+l);
if (u == s) assert(v == _t);
// if ((u == s || v == t || true) && (c > 0))
// cerr<<"ADD: "<<u<<" "<<v<<" "<<c<<" "<<de<<"\n";
adj[u].emplace_back(cnt);
e[cnt++] = {u, v, de, 0, c};
tin[v] += de;
tout[u] += de;
adj[v].emplace_back(cnt);
e[cnt++] = {v, u, 0, 0, 0};
}
inline bool BFS(int st = s, int ed = t)
{
fill(d, d+ed+1, -1);
d[st] = 0;
queue<int> q;
q.emplace(st);
while (q.size())
{
int u = q.front(); q.pop();
for (int id: adj[u])
{
auto [_, v, de, f, c] = e[id];
if (d[v] == -1 && f < c) d[v] = d[u] + 1, q.emplace(v);
}
}
return d[ed] != -1;
}
int DFS(int u = s, int flow = 1e9)
{
// cerr<<"CUR: "<<u<<" "<<flow<<"\n";
if (u == t) return flow;
for (int &i=cur[u]; i<adj[u].size(); i++)
{
int id = adj[u][i];
auto [_, v, de, f, c] = e[id];
if (d[v] == d[u] + 1 && f < c)
{
int tmp = DFS(v, min(flow, c - f));
if (tmp)
{
e[id].f += tmp;
e[id^1].f -= tmp;
return tmp;
}
}
}
return 0;
}
/**
s = 0
cells: 1 -> cell
letters: cell+1 -> cell+l
_s = cell+l+1;
_t = cell+l+2;
t = cell+l+3
**/
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cin>>m>>n;
memset(fx, -1, sizeof fx);
memset(ans, -1, sizeof ans);
for (int i=0; i<26; i++) cap[i] = 1e9;
for (int i=1; i<m; i++)
{
string s, t;
cin>>t>>s;
dt[i] = t;
ds[i] = s;
memset(dem, 0, sizeof dem);
int tmp[30];
memset(tmp, 0, sizeof tmp);
vector<int> bn;
for (int j=0; j<n; j++)
if (s[j] == 'G') fx[j] = t[j] - 'a', ans[j] = t[j] - 'a', dem[t[j]-'a']++;
else if (s[j] == 'Y') ban[j][t[j]-'a'] = 1, dem[t[j]-'a']++, tmp[t[j]-'a']++;
else bn.emplace_back(t[j]-'a'), ban[j][t[j]-'a'] = 1;
for (int j: bn) if (cap[j] == 1e9) cap[j] = dem[j]; else assert(cap[j] == dem[j]);
for (int j=0; j<26; j++) mn[j] = max(mn[j], tmp[j]);
}
for (int i=0; i<n; i++) if (fx[i] != -1) fxl[fx[i]]++;
for (int i=0; i<26; i++) if (cap[i] != 1e9) cap[i] -= fxl[i], mn[i] = cap[i];
for (int i=0; i<26; i++) assert(mn[i] <= cap[i]);
cell = 0;
vector<int> ve;
for (int i=0; i<n; i++) if (fx[i] == -1) ve.emplace_back(i);
cell = ve.size();
l = 26;
s = 0;
_s = cell+l+1;
_t = _s+1;
t = _t+1;
// cerr<<"SS: "<<s<<" "<<t<<"\n";
for (int i=1; i<=cell; i++)
{
add(_s, i, 1);
for (int j=1; j<=26; j++) if (!ban[ve[i-1]][j-1]) add(i, cell+j, 1);
}
for (int i=1; i<=26; i++) add(cell+i, _t, cap[i-1], mn[i-1]);
add(_t, _s, oo);
for (int i=0; i<cnt; i++) e[i].c -= e[i].de;
for (int i=1; i<t; i++) add(s, i, tin[i]), add(i, t, tout[i]);
int anss = 0;
while (BFS())
{
fill(cur, cur+t+1, 0);
int x;
while (x = DFS(s, cell)) anss += x;
}
int smn = accumulate(mn, mn+26);
assert(anss == smn);
// cerr<<"LUONG: "<<anss<<"\n";
for (int i=0; i<cnt; i++)
{
auto [u, v, de, f, c] = e[i];
if (u >= 1 && u <= cell && v >= cell+1 && v <= cell+l)
{
// cerr<<"F & C: "<<f<<" "<<c<<"\n";
// cerr<<"WUT: "<<u<<" "<<v<<" "<<d[u]<<" "<<d[v]<<"\n";
if (f == c)
ans[ve[u-1]] = v - (cell+1);//, cerr<<"ANS: "<<ve[u-1]<<" "<<(v-cell-1)<<"\n";
}
}
string res="";
for (int i=0; i<n; i++) res += (char)(ans[i]+'a');
for (int i=1; i<m; i++)
{
for (int j=0; j<n; j++)
{
if (ds[i][j] == 'G')
{
if (res[j] != dt[i][j]) cout<<"WA ON TEST: "<<i<<" MUST BE: "<<dt[i][j]<<" AT: "<<j<<" FOUND: "<<res[j]<<"\n";
}
else
{
if (res[j] == dt[i][j]) cout<<"WA ON TEST: "<<i<<" MUST NOT BE: "<<dt[i][j]<<" AT: "<<j<<" FOUND: "<<res[j]<<"\n";
}
}
}
cout<<res;
}
/**
**/