//#define _GLIBCXX_DEBUG #include using namespace std; #define rep(i, n) for(int i=0; i; using vs = vector; using vi = vector; using vvi = vector; template using PQ = priority_queue; template using PQG = priority_queue, greater>; const int INF = 0xccccccc; const ll LINF = 0xcccccccccccccccLL; template inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template istream &operator>>(istream &is, pair &p) { return is >> p.first >> p.second;} template ostream &operator<<(ostream &os, const pair &p) { return os << p.first << ' ' << p.second;} struct SCC { struct csr { vector start, elist; csr(int n, const vector> &edges) : start(n+1), elist(edges.size()) { for(pair e:edges) { start[e.first+1]++; } for(int i = 1; i <= n; i++) { start[i] += start[i-1]; } vector counter = start; for(pair e:edges) { elist[counter[e.first]++] = e.second; } } }; int n; vector> edges; SCC(int n_) : n(n_) {} void add(int from, int to) {edges.emplace_back(from, to);} pair> scc_ids() { csr g(n, edges); int now_ord = 0, group_num = 0; vector used, low(n), ord(n, -1), ids(n); used.reserve(n); auto dfs = [&](auto self, int v)->void { low[v] = ord[v] = now_ord++; used.push_back(v); for(int i = g.start[v]; i < g.start[v+1]; i++) { int to = g.elist[i]; if(ord[to] == -1) { self(self, to); low[v] = min(low[v], low[to]); } else { low[v] = min(low[v], ord[to]); } } if(low[v] == ord[v]) { while(true) { int u = used.back(); used.pop_back(); ord[u] = n; ids[u] = group_num; if(u == v) break; } group_num++; } }; for(int i = 0; i < n; i++) { if(ord[i] == -1) dfs(dfs, i); } for(int &x:ids) { x = group_num - 1 - x; } return {group_num, ids}; } vector> scc() { pair> ids = scc_ids(); int group_num = ids.first; vector counts(group_num); for(int x:ids.second) counts[x]++; vector> groups(group_num); for(int i = 0; i < group_num; i++) { groups[i].reserve(counts[i]); } for(int i = 0; i < n; i++) { groups[ids.second[i]].push_back(i); } return groups; } }; //head int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; if(m <= n) { puts("-1"); return 0; } SCC scc(n); vector> G(n); rep(i, m) { int a, b; cin >> a >> b; a--; b--; scc.add(a, b); G[a].emplace_back(b, i); } if(scc.scc_ids().first != 1) { puts("-1"); return 0; } vi check(n, -1); vvi r(n); auto dfs = [&](auto self, int i) -> vi { vi res; for(auto [ne, id]:G[i]) { vi u; if(check[ne] == -1) { check[ne] = check[i]^1; r[ne] = r[i]; r[ne].emplace_back(id); u = self(self, ne); if(not u.empty()) u.emplace_back(id); } else if(check[ne] == check[i]) { u.emplace_back(id); } if(not u.empty()) res = u; } return res; }; auto __s = [&](int root) { fill(all(check), -1); check[root] = 0; rep(i, n) r[i].clear(); return dfs(dfs, root); }; vi x = __s(0); if(x.empty()) { puts("-1"); return 0; } int to = scc.edges[x[0]].second; vi y = r[to]; __s(to); vi z = r[0]; if((int(z.size())^int(x.size()))&1) { while(not x.empty()) { z.emplace_back(x.back()); x.pop_back(); } } else { z.reserve(int(z.size())+int(y.size())); copy(all(y), back_inserter(z)); } vector

pa(n, {-1, -1}); pa[to] = {0, 0}; vi re; rep(i, int(z.size())) { auto [f, t] = scc.edges[z[i]]; if(pa[t].first == -1) { pa[t] = {pa[f].first^1, i+1}; } else { if(pa[t].first == pa[f].first) { vi zz; for(int j = pa[t].second; j <= i; j++) { zz.emplace_back(z[j]); } rep(k, pa[t].second) re.emplace_back(z[k]); for(int k = i+1; k < int(z.size()); k++) re.emplace_back(z[k]); z.swap(zz); break; } else { pa[t].second = i+1; } } } string ans(m, '_'); for(auto x:re) ans[x] = 'R'; if(re.empty()) { int u = -1; vi ch(m); for(auto x:z) ch[x] = 1; rep(i, m) if(not ch[i]) { chmax(u, pa[scc.edges[i].second].second); } ans[z[u]] = 'R'; } rep(i, int(z.size())) if(ans[z[i]] == 'R') { rotate(z.begin(), z.begin()+i+1, z.end()); } ans[z[0]] = 'G'; for(int i = 1; i < int(z.size()); i++) ans[z[i]] = (i&1?'G':'R'); rep(i, m) if(ans[i] == '_') ans[i] = 'R'; cout << ans << endl; }