Bob was bored so he decided to write down a string a
and z
are adjacent. Bob has given you this graph and challenges you to find any string that would generate this graph or determine that Bob has made an error somewhere.
The given graph will be simple and won't have self edges.
Constraints
Subtask 1 [5%]
Subtask 2 [10%]
The graph is guaranteed to be connected.
Subtask 3 [85%]
No additional constraints.
Input Specification
The first line contains two space-separated integers,
The next
Output Specification
Output any string -1
if no such string exists.
Sample Input 1
4 5
1 2
1 3
3 2
4 2
3 4
Sample Output 1
dccb
Explanation for Sample Output 1
Many other answers are possible, including abbc
and yzza
.
Sample Input 2
5 6
1 2
1 3
3 4
4 2
4 5
1 4
Sample Output 2
-1
Explanation for Sample Output 2
No such string exists.
Comments