N, M = map(int, input().split()) S = [input() for _ in range(N)] fin = set() H = "GCPG" def next_h(c): return H[H.index(c) + 1] ans = [] for k in range(M): hand_tmp = {'G', 'C', 'P'} for i in range(N): if i in fin: continue hand_tmp.discard(next_h(S[i][k])) match len(hand_tmp): case 0: print(-1) exit() case 1: hand = hand_tmp.pop() case 2: hand = next_h([h for h in H if h not in hand_tmp].pop()) for i in range(N): if S[i][k] == next_h(hand): fin.add(i) ans.append(hand) if len(fin) == N: print(*ans, sep='') else: print(-1)