/*bfs适用于所有边的权值相同的情况*/
#include<bits/stdc++.h>
using namespace std;
int n, m, start, End, a, b, Map[51][51], book[51];
struct note
{
int x;//当前所在城市
int s;//计数
};
int main()
{
struct note q[2510];
int head, tail, flag = 0;
cin >> n >> m >> start >> End;
//初始化图
for(int i=1;i<=n;i++)
for (int j = 1; j <= n; j++)
{
if (i == j)
Map[i][j] = 0;
else
Map[i][j] = 99999999;
}
while (m--)
{
cin >> a >> b;
Map[a][b] = 1;
Map[b][a] = 1;//无向图
}
head = 1, tail = 1;
book[1]= start;
flag = 0;
q[tail].x = start;
q[tail].s = 0;
tail++;
while (head<tail)//c++里的stl还不太懂,先这样写吧
{
int cur = q[head].x;
for (int j = 1; j <= n; j++)
{
if (Map[cur][j] == 1 && book[j] == 0)
{
q[tail].x = j;
q[tail].s = q[head].s + 1;
tail++;
book[j] = 1;
}
if (q[tail].x == End)
{
flag = 1;
break;
}
}
if (flag == 1)
break;
head++;
}
cout << q[tail - 1].s << endl;
return 0;
}