local mmi, mma = math.min, math.max local inf = 1000000007 local n, m = io.read("*n", "*n") local a, b = io.read("*n", "*n") local t = {} for i = 1, a do t[i] = 0 end for i = a + 1, n + 1 do t[i] = inf end local edge = {} for i = 1, n + 1 do edge[i] = {} end for i = 1, m do local l, r = io.read("*n", "*n") edge[l][r + 1] = true edge[r + 1][l] = true end local tasks = {} for i = 1, a do tasks[i] = i end local done = 0 while done < #tasks do done = done + 1 local src = tasks[done] for dst, _u in pairs(edge[src]) do if 1 + t[src] < t[dst] then t[dst] = 1 + t[src] table.insert(tasks, dst) end end end local ret = inf for i = b + 1, n + 1 do ret = mmi(ret, t[i]) end if ret == inf then ret = -1 end print(ret)