program city;
type
re=record
dt,deep:integer;
end;
var
i,j,n,m,s,e,t1,t2,len,deep:integer;
b:array[1..100,1..100]of boolean;
lhc:array[1..100000]of re;
begin
assign(input,'city.in');
reset(input);
readln(n,m,s,e);
for i:=1 to m do
begin
readln(t1,t2);
b[t1,t2]:=true;
end;
close(input);
len:=1;
lhc[1].dt:=s;
lhc[1].deep:=1;
assign(output,'city.out');
rewrite(output);
i:=1;
repeat
inc(deep);
while lhc[i].deep=deep do
begin
if lhc[i].dt=e then
begin
writeln(deep);
deep:=0;
break;
end;
for j:=1 to n do
if b[lhc[i].dt,j] then
begin
inc(len);
lhc[len].dt:=j;
lhc[len].deep:=deep+1;
end;
inc(i);
end;
until deep=0;
close(output);
end.