using System.Diagnostics; using System.Text; class Program { static string ReadLine() => Console.ReadLine().Trim(); static int ReadInt() => int.Parse(ReadLine()); static long ReadLong() => long.Parse(ReadLine()); static int[] ReadIntArray() { string str = ReadLine(); return str != "" ? str.Split().Select(_ => int.Parse(_)).ToArray() : new int[0]; } static long[] ReadLongArray() { string str = ReadLine(); return str != "" ? str.Split().Select(_ => long.Parse(_)).ToArray() : new long[0]; } static (int a, int b) ReadInt2() { int[] vs = ReadIntArray(); return (a: vs[0], b: vs[1]); } static (int a, int b, int c) ReadInt3() { int[] vs = ReadIntArray(); return (a: vs[0], b: vs[1], c: vs[2]); } static (int a, int b, int c, int d) ReadInt4() { int[] vs = ReadIntArray(); return (a: vs[0], b: vs[1], c: vs[2], d: vs[3]); } static (long a, long b) ReadLong2() { long[] vs = ReadLongArray(); return (a: vs[0], b: vs[1]); } static (long a, long b, long c) ReadLong3() { long[] vs = ReadLongArray(); return (a: vs[0], b: vs[1], c: vs[2]); } static (long a, long b, long c, long d) ReadLong4() { long[] vs = ReadLongArray(); return (a: vs[0], b: vs[1], c: vs[2], d: vs[3]); } class Player { public Player(string s) { char[] vs = s.ToArray(); Hands = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) { if (vs[i] == 'G') Hands[i] = 0; if (vs[i] == 'C') Hands[i] = 1; if (vs[i] == 'P') Hands[i] = 2; } } public int[] Hands; public bool IsDead = false; } static void Main() { SourceExpander.Expander.Expand(); (int N, int M) = ReadInt2(); List players = new List(); for (int i = 0; i < N; i++) players.Add(new Player(ReadLine())); List ans = new List(); for (int i = 0; i < M; i++) { int[] hands = new int[3]; for (int k = 0; k < N; k++) { if (!players[k].IsDead) hands[players[k].Hands[i]]++; } int h = F(hands); ans.Add(h); if (h == -1) { Console.WriteLine(-1); return; } for (int k = 0; k < N; k++) { if (!players[k].IsDead) { if (h == 0 && players[k].Hands[i] == 1) players[k].IsDead = true; if (h == 1 && players[k].Hands[i] == 2) players[k].IsDead = true; if (h == 2 && players[k].Hands[i] == 0) players[k].IsDead = true; } } } if(players.All(_ => _.IsDead)) Console.WriteLine(G(ans)); else Console.WriteLine(-1); string G(List ans) { StringBuilder sb = new StringBuilder(); foreach (int v in ans) { if (v == 0) sb.Append('G'); if (v == 1) sb.Append('C'); if (v == 2) sb.Append('P'); } return sb.ToString(); } int F(int[] hands) { if (hands[0] == 0 && hands[1] == 0 && hands[2] == 0) return 0; if (hands[0] > 0 && hands[1] > 0 && hands[2] > 0) return -1; if (hands[1] > 0 && hands[2] > 0) return 1; if (hands[0] > 0 && hands[2] > 0) return 2; if (hands[0] > 0 && hands[1] > 0) return 0; if (hands[0] > 0) return 2; if (hands[1] > 0) return 0; if (hands[2] > 0) return 1; return -1; } } } #region Expanded by https://github.com/kzrnm/SourceExpander namespace SourceExpander{public class Expander{[Conditional("EXP")]public static void Expand(string inputFilePath=null,string outputFilePath=null,bool ignoreAnyError=true){}public static string ExpandString(string inputFilePath=null,bool ignoreAnyError=true){return "";}}} #endregion Expanded by https://github.com/kzrnm/SourceExpander