#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int N, M; cin >> N >> M; vector S(N); for (int i = 0; i < N; i++) { cin >> S[i]; } map win_hand = {{'G', 'P'}, {'C', 'G'}, {'P', 'C'}}; // 負けた岩井星人 vector is_loser(N, false); string ans; rep(i, M) { // 残っている岩井星人の手を集める。 set hands; rep(j, N) { if (is_loser[j]) { continue; } hands.insert(S[j][i]); } switch (hands.size()) { case 0: // 既に全ての岩井星人に勝利しているのでどの手を出してもよい。 ans += "G"; break; case 1: // 勝つ手を出す。 ans += win_hand[*hands.begin()]; break; case 2: // 負けない手を出す。 if (hands.contains('G') && hands.contains('C')) { ans += 'G'; } else if (hands.contains('C') && hands.contains('P')) { ans += 'C'; } else if (hands.contains('P') && hands.contains('G')) { ans += 'P'; } break; case 3: // 負けない手が存在しない。 cout << -1 << endl; return 0; } // 負ける岩井星人を除外する。 rep(j, N) { if (is_loser[j]) { continue; } if (ans.back() == win_hand[S[j][i]]) { is_loser[j] = true; } } } // 負けていない岩井星人が残っている。 if (!all_of(is_loser.begin(), is_loser.end(), [](bool b) { return b; })) { cout << -1 << endl; return 0; } cout << ans << endl; return 0; }