#include using namespace std; using ll = long long; constexpr char newl = '\n'; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m, a, b; cin >> n >> m >> a >> b; --a; vector< vector > g(n + 1); for (int i = 0; i < m; i++) { int l, r; cin >> l >> r; --l; g[l].push_back(r); g[r].push_back(l); } queue q; vector d(n + 1, -1); for (int i = 0; i <= a; i++) { d[i] = 0; q.push(i); } while (!q.empty()) { int cur = q.front(); q.pop(); for (int nex : g[cur]) { if (d[nex] != -1) continue; d[nex] = d[cur] + 1; q.push(nex); } } int ans = 1e9; for (int i = b; i <= n; i++) { ans = min(ans, (d[i] == -1 ? 1000000000 : d[i])); } cout << (ans >= 1000000000 ? -1 : ans) << newl; return 0; }