def win(hands): if len(hands) == 1: h = hands.pop() if h == "G": return "P" elif h == "C": return "G" else: return "C" else: l, r = sorted(hands) if (l, r) == ("C", "G"): return "G" elif (l, r) == ("C", "P"): return "C" else: return "P" N, M = [int(s) for s in input().split()] S = [[*input()] for _ in range(N)] remain = {*range(N)} answers = [] for m in range(M): hands = {S[r][m] for r in remain} if len(hands) == 3: print("-1") exit() if len(hands) == 0: answers.append("G") continue w = win(hands) answers.append(w) nremain = set() for r in remain: if S[r][m] == w: nremain.add(r) remain = nremain print(*answers, sep="")