import sys input = sys.stdin.readline N,M=map(int,input().split()) S=[input().strip() for i in range(N)] X=dict() X["P"]="C" X["G"]="P" X["C"]="G" L=list(range(N)) Q=[([],L,0)] while Q: now,L,ind=Q.pop() if ind==M: if L==[]: print("".join(now)) exit() else: continue for x in "PGC": flag=1 LL=[] for i in L: if S[i][ind]==X[x]: flag=0 break if S[i][ind]==x: LL.append(i) if flag==1: Q.append((now+[x],LL,ind+1)) print(-1)