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 = {'G', 'C', 'P'} for i in range(N): if i in fin: continue hand.discard(next_h(S[i][k])) match len(hand): case 0: print(-1) exit() case 1: res = hand.pop() case 2: res = [h for h in H if h not in hand].pop() for i in range(N): if S[i][k] == next_h(res): fin.add(i) ans.append(res) print(*ans, sep='')