import sys input = sys.stdin.readline sys.setrecursionlimit(10**5+10) from collections import * def dfs(v, pv, t): global pos seen[v] = True hist.append(v) for i, nv in G[v]: if t0: r = m-1 break else: l = m+1 ans = l if ans==Q+1: print(-1) else: print(ans)