Under construction

Still being built. Things may change

5-Path

Time limit2sMemory limit512 MB

Summary
Given an edge list, find the shortest prefix that creates a simple path of exactly 5 edges between nodes a and b, or report -1.
Level

Hard8 of 10

Topics
Graph, Binary search, BFS
Solved
No attempts yet

Problem

You are given a list of edges of an undirected graph. The graph has two special nodes, aa and bb. Find the minimum size of a prefix of this list such that the graph represented by this prefix contains a simple path of 5 edges between nodes aa and bb.

Input

The first line contains two integers nn and mm, the number of nodes and the number of edges in the graph. Each of the following mm lines contains two integers viv_i and uiu_i, the endpoints of an edge (1≤vi,ui≤n1 \le v_i, u_i \le n). The last line contains two integers aa and bb, the special nodes (a≠ba \neq b, 1≤a,b≤n1 \le a, b \le n). The graph has no multiple edges and no self-loops.

Output

If the graph represented by the given edge list contains a simple path of 5 edges, output the answer to the problem. Otherwise, output −1-1.

Examples2

  1. Example 1

    Input
    10 9
    1 6
    6 9
    9 10
    10 3
    3 2
    2 7
    7 5
    5 8
    8 4
    6 7
    
    Expected output
    6
    
  2. Example 2

    Input
    10 10
    1 2
    1 3
    1 4
    1 5
    1 6
    1 7
    1 8
    1 9
    10 2
    10 3
    1 10
    
    Expected output
    -1