#include using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rrep(i,n) for(int i=(int)(n-1);i>=0;i--) #define ALL(v) v.begin(),v.end() #define RALL(v) v.rbegin(),v.rend() template using V=vector; template using VV=V>; using u128=__int128_t; using ll=long long; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); ll n,m; cin>>n>>m; V S(n); rep(i,n) cin>>S[i]; V A(m,'G'); V D(n); rep(j,m){ int g=0,c=0,p=0; rep(i,n){ if(D[i]) continue; if(S[i][j]=='G') g=1; else if(S[i][j]=='C') c=1; else p=1; } if(g+c+p==3){ cout<<-1<