#include<cstdio>
#include<vector>
#include<cstring>
#include<queue>
using namespace std;
#define F1 "Sorted sequence determined after %d relations: "
#define F2 "Inconsistency found after %d relations."
#define F3 "Sorted sequence cannot be determined."
int n,m;
bool mp[26][26],vst[26];
int in[26];
queue<int> pre,topo;
int toposort()
{
//for(int i=0;i<26;i++)
//if(vst[i]) putchar(i+'A');
//putchar('\n');
int inn[26];
memcpy(inn,in,sizeof(in));
int tot=0;
while(!topo.empty())
topo.pop();
for(int i=0;i<26;i++)
if(vst[i]&&inn[i]==0){
tot++;
topo.push(i);
//putchar(i+'A');
if(tot>=2) return 0;
}
if(tot==0) return -1;
while(!pre.empty())
pre.pop();
pre.push(topo.front());
while(!topo.empty())
{
int cur=topo.front();
topo.pop();
int cnt=0;
for(int i=0;i<26;i++)
{
if(mp[cur][i])
{
inn[i]--;
if(!inn[i])
{
cnt++;
tot++;
topo.push(i);
pre.push(i);
}
}
if(cnt>=2) return 0;
}
}
//printf("%d\n",tot);
if(tot==n) return 1;
return 0;
}
int main()
{
scanf("%d%d",&n,&m);
bool ok=false;
for(int i=1;i<=m;i++)
{
getchar();
char a,b;
a=getchar();
getchar();
b=getchar();
if(ok) continue;
vst[a-'A']=vst[b-'A']=true;
if(!mp[a-'A'][b-'A'])
in[b-'A']++;
else continue;
if(mp[b-'A'][a-'A'] || b==a)
{
printf(F2,i);
//return 0;
ok=true;
}
mp[a-'A'][b-'A']=true;
int ans=toposort();
if(ans==0) continue;
else if(ans==1)
{
printf(F1,i);
while(!pre.empty())
{
putchar(pre.front()+'A');
pre.pop();
}
putchar('.');
//return 0;
ok=true;
}
else {
printf(F2,i);
//return 0;
ok=true;
}
}
if(!ok) printf(F3);
return 0;
}