Sorting It All Out

No attempts yetTime limit1sMemory limit128 MB

Problem

An ascending sorted sequence of distinct values orders the elements from smallest to largest using some form of a less-than operator. For example, the sorted sequence A, B, C, D implies A < B, B < C, and C < D. In this problem you are given a set of relations of the form A < B, and you must determine whether these relations specify a unique sorted order.

Input

The input consists of multiple problem instances. Each instance starts with a line containing two positive integers n and m. The first value is the number of objects to sort, where 2n262 \le n \le 26. The objects to be sorted are the first n uppercase letters of the alphabet. The second value m is the number of relations of the form A < B given in this instance. The next m lines each contain one such relation, consisting of three characters: an uppercase letter, the character <, and a second uppercase letter. No letter lies outside the first n letters of the alphabet. A line with n = m = 0 marks the end of the input.

Output

For each problem instance, output a single line. This line must be exactly one of the following three:

Sorted sequence determined after xxx relations: yyy...y.
Sorted sequence cannot be determined.
Inconsistency found after xxx relations.

Here xxx is the number of relations processed at the moment a sorted sequence is determined or an inconsistency is found, whichever comes first, and yyy...y is the sorted ascending sequence. Relations are processed one at a time in order; as soon as the order becomes uniquely determined or a contradiction appears, the result is reported using the count of relations processed so far. If all relations are processed without determining a unique order and without any contradiction, the order cannot be determined.