#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #pragma warning(disable:4996) //#define ATCODER #ifdef ATCODER #include #endif typedef long long ll; typedef unsigned long long ull; #define LINF 9223300000000000000 #define LINF2 1223300000000000000 #define LINF3 1000000000000 #define INF 2140000000 const long long MOD = 1000000007; //const long long MOD = 998244353; using namespace std; #ifdef ATCODER using namespace atcoder; #endif void solve() { int n, m; scanf("%d%d", &n, &m); vector>> g(n); // to,edge vector a(m), b(m); int i; for (i = 0; i < m; i++) { scanf("%d%d", &a[i], &b[i]); a[i]--; b[i]--; g[a[i]].push_back(make_pair(b[i],i)); } for (i = 0; i < m; i++) { int ans0 = 0; vector pr(n); vector dist(n, INF); queue que; que.push(b[i]); dist[b[i]] = 0; while (!que.empty()) { int tmp = que.front(); que.pop(); int k; for (k = 0; k < (int)g[tmp].size(); k++) { int ne = g[tmp][k].first; if (dist[ne] == INF) { dist[ne] = dist[tmp] + 1; pr[ne] = g[tmp][k].second; que.push(ne); } } } int j; for (j = 0; j < n; j++) { if (dist[j] == INF) { printf("-1"); return; } } } for (i = 0; i < m; i++) { vector pr(n); vector dist(n, INF); queue que; que.push(b[i]); dist[b[i]] = 0; while (!que.empty()) { int tmp = que.front(); que.pop(); int k; for (k = 0; k < (int)g[tmp].size(); k++) { int ne = g[tmp][k].first; if (dist[ne] == INF) { dist[ne] = dist[tmp] + 1; pr[ne] = g[tmp][k].second; que.push(ne); } } } if (dist[a[i]] % 2 == 0) { vector ans(m); int curr = a[i]; int cnt = 0; while (1) { int edge = pr[curr]; ans[edge] = 1 - cnt; cnt = 1 - cnt; curr = a[edge]; if (curr == a[i]) break; } int k; for (k = 0; k < m; k++) { if (ans[k]) printf("R"); else printf("G"); } printf("\n"); return; } } printf("-1\n"); return; } int main() { #if 1 solve(); #else int T, t; scanf("%d", &T); for (t = 0; t < T; t++) { //cout << "Case #" << t + 1 << ": "; solve(); } #endif return 0; }