This page is still under construction.

Parts of this page are still being built. What you see may change.

Beautiful Automata

Time limit2sMemory limit512 MB

Summary
Given a DAG, find the lexicographically smallest string whose suffix automaton is exactly this graph, or report -1 if none exists.
Level

Hard10 of 10

Topics
Graph, Topological sort, String, Greedy
Solved
No attempts yet

Statement

Oleksandr is a fan of strings. His favourite data structure is the suffix automaton.

Consider a string ss of lowercase English letters. The suffix automaton of ss is the smallest directed acyclic graph GG (the one with the fewest vertices) with a letter l(e)l(e) written on each edge ee and a fixed starting vertex v0v_0, such that

{w∣w is a substring of s}={l(e1)l(e2)⋯l(ek)∣(e1,e2,…,ek) is a path in G starting at v0}.\{w \mid w \text{ is a substring of } s\} = \{l(e_1)l(e_2)\cdots l(e_k) \mid (e_1, e_2, \ldots, e_k) \text{ is a path in } G \text{ starting at } v_0\}.

Oleksandr likes suffix automata more than any other graphs. He calls a directed acyclic graph GG ss-beautiful if a lowercase letter can be written on each edge and a starting vertex v0v_0 chosen so that GG becomes the suffix automaton of ss.

Oleksandr likes lexicographically small strings. Given a graph GG, find the lexicographically smallest string ss such that GG is ss-beautiful.

Input

The first line contains two integers nn and mm (1≤n≤20001 \le n \le 2000, 1≤m≤30001 \le m \le 3000), the number of vertices and the number of edges in GG. Each of the next mm lines contains two integers vv and uu (1≤v,u≤n1 \le v, u \le n, v≠uv \ne u), denoting a directed edge from vv to uu. It is guaranteed that GG is acyclic.

Output

Output a single line containing the lexicographically smallest string ss consisting of lowercase English letters such that GG is ss-beautiful. If no such string exists, output −1-1.

Hint

The suffix automata for the first three sample tests are shown below.

Examples4

  1. Example 1

    Input
    2 1
    1 2
    
    Expected output
    a
    
  2. Example 2

    Input
    4 5
    1 2
    2 3
    1 4
    2 4
    3 4
    
    Expected output
    aab
    
  3. Example 3

    Input
    5 5
    1 2
    1 3
    2 3
    3 4
    4 5
    
    Expected output
    abab
    
  4. Example 4

    Input
    4 5
    1 2
    1 3
    1 4
    2 3
    4 3
    
    Expected output
    -1