#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<queue>
#include<stack>
using namespace std;
const int maxn = 505;
int f[maxn], val[maxn];
//0代表同类, 1代表赢, 2代表输
struct node{int u, v, rel;}data[maxn*4];
int Find(int x)
{
int k = f[x];
if(f[x] != x)
{
f[x] = Find(f[x]);
val[x] = (val[x]+val[k])%3;
}
return f[x];
}
//如果k是裁判是否有矛盾产生,有返回产生矛盾的行数, 没有返回-1
int Solve(int k, int N, int M)
{//这里跟食物链一样的
int i, u, v, ru, rv;
for(i=0; i<N; i++)
f[i] = i, val[i]=0;
for(i=0; i<M; i++)
{
u = data[i].u, v = data[i].v;
if(u != k && v != k)
{
ru = Find(u), rv = Find(v);
if(ru == rv && (val[v]+data[i].rel)%3 != val[u] )
return i;
f[ru] = rv;
val[ru] = (data[i].rel-val[u]+val[v]+3)%3;
}
}
return -1;
}
int main()
{
int i, N, M;
while(scanf("%d%d", &N, &M) != EOF)
{
char ch;
for(i=0; i<M; i++)
{
scanf("%d%c%d", &data[i].u, &ch, &data[i].v);
if(ch == ‘=‘)
data[i].rel = 0;
else if(ch == ‘>‘)
data[i].rel = 1;
else
data[i].rel = 2;
}
int p = Solve(-1, N, M);
//没有矛盾产生,无法判断出谁是裁判
if(N != 1 && p == -1)
printf("Can not determine\n");
else if(N == 1)//只有一个人,只能是裁判
printf("Player 0 can be determined to be the judge after 0 lines\n");
else
{
int k=0, q, j;//k记录有多少个可以担任裁判
for(i=0; i<N; i++)
{
j = Solve(i, N, M);
if(j == -1)
k++, q = i;
else
p = max(p, j);//因为要求可以最近的看出裁判的地方,其实就是别的点产生矛盾最远的地方
if(k > 1)
break;
}
if(k == 0)
printf("Impossible\n");
else if(k > 1)
printf("Can not determine\n");
else
printf("Player %d can be determined to be the judge after %d lines\n", q, p+1);
}
}
return 0;
}