// やけくそTLE解. //#define _GLIBCXX_DEBUG #include using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define all(a) (a).begin(), (a).end() const ll INF32 = 2e9; const ll INF64 = 4e18; void printYN(bool ok){ if(ok)cout << "Yes" << endl; else cout << "No" << endl; return; } signed main() { int N, M; cin >> N >> M; vector S(N); vector won(N, false); string ans = ""; rep(i, N)cin >> S[i]; rep(i, M){ bool G = false,C = false, P = false; rep(j, N){ if(won[j])continue; if(S[j][i]=='G')G = true; if(S[j][i]=='C')C = true; if(S[j][i]=='P')P = true; } if(G&&C&&P){ cout << -1 << endl; return 0; } if(C&&(!P)){ ans.push_back('G'); rep(j, N){ if(S[j][i]=='C')won[j]=true; } } else if(P&&(!G)){ ans.push_back('C'); rep(j, N){ if(S[j][i]=='P')won[j]=true; } } else if(G&&(!C)){ ans.push_back('P'); rep(j, N){ if(S[j][i]=='G')won[j]=true; } } else ans.push_back('G'); } bool ok = true; rep(i, N){ if(!won[i])ok = false; } if(ok)cout << ans << endl; else cout << -1 << endl; return 0; }