{$M 400000000}
const maxn = 10000;
      fi = '';
      fo = '';
type tqueue = record
                front,rear,nitem:word;
                item: array[0..maxn-1] of word;
              end;
var n,s,t:word;
    m:longint;
    g: array[1..maxn,0..maxn] of word;
    trace: array[1..maxn] of word;
    queue: tqueue;
procedure enter;
var i:longint;
    u,v:word;
begin
  assign(input,fi);
  reset(input);
  readln(n,m,s,t);
  for i:=1 to n do
  g[i,0]:=0;
  for i:=1 to m do
  begin
    readln(u,v);
    inc(g[u,0]);
    g[u,g[u,0]]:=v;
  end;
  close(input);
end;
procedure initq;
begin
  with queue do
  begin
    front:=0;
    rear:=1;
    nitem:=0;
  end;
end;
procedure push(v:word);
begin
  with queue do
  begin
    inc(nitem);
    front:=(front+1) mod maxn;
    item[front]:=v;
  end;
end;
function pop:word;
begin
  with queue do
  begin
    dec(nitem);
    pop:=item[rear];
    rear:=(rear+1) mod maxn;
  end;
end;
function empty:boolean;
begin
  with queue do
  empty:=(nitem=0);
end;
procedure printtrace;
var i:word;
begin
  for i:=1 to n do
  write(trace[i],' ');
  writeln;
end;
procedure bfs;
var i,j:word;
    visit: array[1..maxn] of boolean;
begin
  initq;
  fillchar(visit,sizeof(visit),false);
  fillchar(trace,sizeof(trace),0);
  push(s);
  visit[s]:=true;
  repeat
    i:=pop;
    for j:=1 to g[i,0] do
    if not visit[g[i,j]] then
    begin
      push(g[i,j]);
      visit[g[i,j]]:=true;
      trace[g[i,j]]:=i;
      if g[i,j]=t then exit;
    end;
  until empty;
end;
procedure solve;
var lock,res:word;
    visit: array[1..maxn] of boolean;
function dfs(i:longint):boolean;
var j:longint;
    p:boolean;
begin
  visit[i]:=true;
  if i=t then dfs:=true
  else
  if i=lock then dfs:=false
  else
  begin
    p:=false;
    for j:=1 to g[i,0] do
    if not visit[g[i,j]] then
    begin
      p:=p or dfs(g[i,j]);
      if p then break;
    end;
    dfs:=p;
  end;
end;
begin
  assign(output,fo);
  rewrite(output);
  bfs;
  lock:=trace[t];
  res:=0;
  while (lock<>s) and (lock<>0) do
  begin
    fillchar(visit,sizeof(visit),false);
    if not dfs(s) then inc(res);
    lock:=trace[lock];
  end;
  writeln(res);
  close(output);
end;
begin
  enter;
  solve;
end.