#include <bits/stdc++.h>
#define ll long long
#define el cout << '\n'
#define ii pair<int, int>
#define fi first
#define se second
using namespace std;
const int maxn = 255;
const int INF = 1e9;
int n, m, d[maxn + 10][maxn + 10], s, t;
vector<int> adj[maxn + 10];
bool vis[maxn + 10][maxn + 10];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen("BAGENTS.INP", "r"))
{
freopen("BAGENTS.INP", "r", stdin);
freopen("BAGENTS.OUT", "w", stdout);
}
cin >> n >> m;
cin >> s >> t;
for (int i = 1; i <= m; i++)
{
int x, y;
cin >> x >> y;
adj[x].push_back(y);
}
d[s][t] = 0;
vis[s][t] = 1;
queue<ii> q;
q.push({s, t});
while (!q.empty())
{
ii t = q.front();
q.pop();
int x = t.fi;
int y = t.se;
if (x == y) return cout << d[x][y], 0;
for (int next_x : adj[x])
for (int next_y : adj[y])
{
if (vis[next_x][next_y]) continue;
d[next_x][next_y] = d[x][y] + 1;
vis[next_x][next_y] = 1;
q.push({next_x, next_y});
}
}
cout << -1;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CgojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIGVsIGNvdXQgPDwgJ1xuJwojZGVmaW5lIGlpIHBhaXI8aW50LCBpbnQ+CiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgbWF4biA9IDI1NTsKY29uc3QgaW50IElORiA9IDFlOTsKCmludCBuLCBtLCBkW21heG4gKyAxMF1bbWF4biArIDEwXSwgcywgdDsKdmVjdG9yPGludD4gYWRqW21heG4gKyAxMF07CmJvb2wgdmlzW21heG4gKyAxMF1bbWF4biArIDEwXTsKCmludCBtYWluKCkKewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsgY2luLnRpZSgwKTsgY291dC50aWUoMCk7CiAgICBpZiAoZm9wZW4oIkJBR0VOVFMuSU5QIiwgInIiKSkKICAgIHsKICAgICAgICBmcmVvcGVuKCJCQUdFTlRTLklOUCIsICJyIiwgc3RkaW4pOwogICAgICAgIGZyZW9wZW4oIkJBR0VOVFMuT1VUIiwgInciLCBzdGRvdXQpOwogICAgfQoKICAgIGNpbiA+PiBuID4+IG07CiAgICBjaW4gPj4gcyA+PiB0OwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbTsgaSsrKQogICAgewogICAgICAgIGludCB4LCB5OwogICAgICAgIGNpbiA+PiB4ID4+IHk7CiAgICAgICAgYWRqW3hdLnB1c2hfYmFjayh5KTsKICAgIH0KICAgIGRbc11bdF0gPSAwOwogICAgdmlzW3NdW3RdID0gMTsKICAgIHF1ZXVlPGlpPiBxOwogICAgcS5wdXNoKHtzLCB0fSk7CgogICAgd2hpbGUgKCFxLmVtcHR5KCkpCiAgICB7CiAgICAgICAgaWkgdCA9IHEuZnJvbnQoKTsKICAgICAgICBxLnBvcCgpOwogICAgICAgIGludCB4ID0gdC5maTsKICAgICAgICBpbnQgeSA9IHQuc2U7CgogICAgICAgIGlmICh4ID09IHkpIHJldHVybiBjb3V0IDw8IGRbeF1beV0sIDA7CgogICAgICAgIGZvciAoaW50IG5leHRfeCA6IGFkalt4XSkKICAgICAgICAgICAgZm9yIChpbnQgbmV4dF95IDogYWRqW3ldKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZiAodmlzW25leHRfeF1bbmV4dF95XSkgY29udGludWU7CiAgICAgICAgICAgICAgICBkW25leHRfeF1bbmV4dF95XSA9IGRbeF1beV0gKyAxOwogICAgICAgICAgICAgICAgdmlzW25leHRfeF1bbmV4dF95XSA9IDE7CiAgICAgICAgICAgICAgICBxLnB1c2goe25leHRfeCwgbmV4dF95fSk7CiAgICAgICAgICAgIH0KICAgIH0KICAgIGNvdXQgPDwgLTE7Cn0K