#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;

#define maxn 30

int n, m;
bool smaller[maxn][maxn];
enum Result
{
    inconsistent, determined, undetermined
};

bool cmp(int a, int b)
{
    return smaller[a][b];
}

int get_id(char a)
{
    return a - 'A';
}

Result work(int a, int b)
{
    if (smaller[b][a])
        return inconsistent;
    smaller[a][b] = true;
    for (int i = 0; i < n; i++)
        if (smaller[i][a])
            smaller[i][b] = true;
    for (int i = 0; i < n; i++)
            if (smaller[b][i])
                smaller[a][i] = true;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            if (smaller[i][a] && smaller[b][j])
                smaller[i][j] = true;
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            if (!(smaller[i][j] || smaller[j][i]))
                return undetermined;
    return determined;
}

void input(int x)
{
    char st[5];
    for (int i = x + 1; i < m; i++)
        gets(st);
}

void output()
{
    int f[maxn];
    for (int i = 0; i < n; i++)
        f[i] = i;
    sort(f, f + n, cmp);
    for (int i = 0; i < n; i++)
        putchar(f[i] + 'A');
}

int main()
{
    while (scanf("%d%d", &n, &m), n | m)
    {
        getchar();
        memset(smaller, 0, sizeof(smaller));
        Result ans = undetermined;
        for (int i = 0; i < m; i++)
        {
            char a, b, opr;
            a = getchar();
            opr = getchar();
            b = getchar();
            getchar();
            if (opr == '<')
                ans = work(get_id(a), get_id(b));
            else
                ans = work(get_id(b), get_id(a));
            if (ans == inconsistent)
            {
                printf("Inconsistency found after %d relations.\n", i + 1);
                input(i);
                break;
            }
            if (ans == determined)
            {
                printf("Sorted sequence determined after %d relations: ", i + 1);
                input(i);
                output();
                printf(".\n");
                break;
            }
        }
        if (ans == undetermined)
            puts("Sorted sequence cannot be determined.");
    }
    return 0;
}