#include #include #include using namespace std; int main() { int n, m; cin >> n >> m; vector s(n); for (int i = 0; i < n; i++) cin >> s[i]; vector won(n, false); bool g, c, p; string ans = ""; char beat; for (int i = 0; i < m; i++) { g = c = p = false; for (int j = 0; j < n; j++) { 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 == 1) { if (g) { ans.push_back('P'); beat = 'G'; } if (c) { ans.push_back('G'); beat = 'C'; } if (p) { ans.push_back('C'); beat = 'P'; } } else if (g + c + p == 2) { if (g && c){ ans.push_back('G'); beat = 'C'; } if (c && p) { ans.push_back('C'); beat = 'P'; } if (p && g) { ans.push_back('P'); beat = 'G'; } } else if (g + c + p == 3) { cout << -1 << endl; return 0; } else { ans.push_back('G'); beat = 'P'; } for (int j = 0; j < n; j++) if (s[j][i] == beat) won[j] = true; } for (int i = 0; i < n; i++) { if (!won[i]) { cout << -1 << endl; return 0; } } cout << ans << endl; return 0; }