import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int a = sc.nextInt(); int b = sc.nextInt(); ArrayList> graph = new ArrayList<>(); for (int i = 0; i <= n + 1; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { int x = sc.nextInt(); int y = sc.nextInt() + 1; graph.get(x).add(y); graph.get(y).add(x); } PriorityQueue queue = new PriorityQueue<>(); for (int i = 1; i <= a; i++) { queue.add(new Path(i, 0)); } int[] costs = new int[n + 2]; Arrays.fill(costs, Integer.MAX_VALUE); while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.idx] <= p.value) { continue; } costs[p.idx] = p.value; for (int x : graph.get(p.idx)) { queue.add(new Path(x, p.value + 1)); } } int min = Integer.MAX_VALUE; for (int i = b + 1; i < costs.length; i++) { min = Math.min(min, costs[i]); } if (min == Integer.MAX_VALUE) { System.out.println(-1); } else { System.out.println(min); } } static class Path implements Comparable { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { return value - another.value; } } }