//入力チェック+解が確定するjを求める #include #include #include #include using namespace std; using namespace atcoder; using ll = long long; //#define endl "\n"; ll N, M, chk[100009]; string S[100009]; vector ans; vector te = {'G', 'C', 'P'}; set rest; void dfs(ll pos){ if(pos == M){ if(rest.size() == 0){ for(auto s: ans) cout << s; cout << endl; exit(0); }else{ return; } } vector visited(3, true); for(int k = 0; k < 3; k++){ for(auto itr = rest.begin(); itr != rest.end(); ++itr){ if(S[*itr][pos] == te[(k + 2) % 3]){ visited[k] = false; } } if(visited[k]){ vector tmp; for(auto itr = rest.begin(); itr != rest.end(); ++itr){ if(S[*itr][pos] == te[(k + 1) % 3]){ tmp.push_back(*itr); } } if(tmp.size() == 0 && rest.size() > 0) continue; //あいこにする必要はない ans.push_back(te[k]); for(auto p: tmp) rest.erase(p); if(rest.size() == 0){ cout << "OK idx=" << pos + 1 << endl; exit(0); } dfs(pos + 1); for(auto p: tmp) rest.insert(p); ans.pop_back(); } } cout << "NG idx=" << pos + 1 << endl; exit(0); } int main(){ cin >> N >> M; assert(1 <= N && N <= 1e5); assert(1 <= M && M <= 1e5); assert(1 <= N * M && N * M<= 1e5); for(int i = 0; i < N; i++){ cin >> S[i]; assert(S[i].size() == M); for(int j = 0; j < M; j++){ assert(S[i][j] == 'G' || S[i][j] == 'C' || S[i][j] == 'P'); } rest.insert(i); } dfs(0); cout << -1 << endl; return 0; }