{$M 400000000}
const maxn = 10000;
fi = '';
fo = '';
oo = 60000;
type tqueue = record
front,rear,nitem:word;
item: array[0..maxn-1] of word;
end;
pnode = ^node;
node = record
v: word;
next: pnode;
end;
var n,m,s:word;
g: array[1..maxn] of pnode;
queue: tqueue;
sen: node;
nilt: pnode;
procedure insert(u,v:word);
var p:pnode;
begin
new(p);
p^.v:=v;
p^.next:=g[u];
g[u]:=p;
end;
function found(u,v:word):boolean;
var p:pnode;
begin
found:=false;
p:=g[u];
while p<>nilt do
begin
found:=(found or (p^.v=v));
if found then exit;
p:=p^.next;
end;
end;
procedure enter;
var i,j,u,v:word;
{a: array[1..maxn,1..maxn] of boolean;}
begin
assign(input,fi);
reset(input);
readln(n,m,s);
{for i:=1 to n do
for j:=1 to n do
a[i,j]:=false;}
sen.v:=0;
nilt:=@sen;
for i:=1 to n do
g[i]:=nilt;
for i:=1 to m do
begin
readln(u,v);
if not found(u,v) then
begin
{a[u,v]:=true;}
insert(u,v);
end;
end;
close(input);
end;
procedure initq;
begin
with queue do
begin
front:=0;
rear:=1;
nitem:=0;
end;
end;
function empty:boolean;
begin
with queue do
empty:=(nitem=0);
end;
procedure push(v:word);
begin
with queue do
begin
front:=(front+1) mod maxn;
inc(nitem);
item[front]:=v;
end;
end;
function pop:word;
begin
with queue do
begin
pop:=item[rear];
rear:=(rear+1) mod maxn;
dec(nitem);
end;
end;
procedure bfs;
var u,v,res,i:word;
p:pnode;
d: array[1..maxn] of word;
sta: array[1..maxn] of boolean;
begin
initq;
fillchar(d,sizeof(d),oo);
fillchar(sta,sizeof(sta),false);
res:=0;
push(s);
d[s]:=0;
repeat
u:=pop;
p:=g[u];
while p<>nilt do
begin
v:=p^.v;
{writeln(u,' ',v,' ',d[u],' ',d[v]);}
if d[u]+1<d[v] then
begin
d[v]:=d[u]+1;
push(v);
if sta[u] then
begin
if not sta[v] then
begin
sta[v]:=true;
inc(res);
end;
end;
end
else
if d[u]+1=d[v] then
begin
if not sta[v] then
begin
sta[v]:=true;
inc(res);
end;
end;
p:=p^.next;
end;
until empty;
{for i:=1 to n do write(d[i],' ');
writeln;}
writeln(res);
end;
procedure solve;
var i:word;
begin
assign(output,fo);
rewrite(output);
bfs;
close(output);
end;
begin
enter;
solve;
end.
eyRNIDQwMDAwMDAwMH0KY29uc3QgbWF4biA9IDEwMDAwOwogICAgICBmaSA9ICcnOwogICAgICBmbyA9ICcnOwogICAgICBvbyA9IDYwMDAwOwp0eXBlIHRxdWV1ZSA9IHJlY29yZAogICAgICAgICAgICAgICAgZnJvbnQscmVhcixuaXRlbTp3b3JkOwogICAgICAgICAgICAgICAgaXRlbTogYXJyYXlbMC4ubWF4bi0xXSBvZiB3b3JkOwogICAgICAgICAgICAgIGVuZDsKICAgICBwbm9kZSA9IF5ub2RlOwogICAgIG5vZGUgPSByZWNvcmQKICAgICAgICAgICAgICB2OiB3b3JkOwogICAgICAgICAgICAgIG5leHQ6IHBub2RlOwogICAgICAgICAgICBlbmQ7CnZhciBuLG0sczp3b3JkOwogICAgZzogYXJyYXlbMS4ubWF4bl0gb2YgcG5vZGU7CiAgICBxdWV1ZTogdHF1ZXVlOwogICAgc2VuOiBub2RlOwogICAgbmlsdDogcG5vZGU7CnByb2NlZHVyZSBpbnNlcnQodSx2OndvcmQpOwp2YXIgcDpwbm9kZTsKYmVnaW4KICBuZXcocCk7CiAgcF4udjo9djsKICBwXi5uZXh0Oj1nW3VdOwogIGdbdV06PXA7CmVuZDsKZnVuY3Rpb24gZm91bmQodSx2OndvcmQpOmJvb2xlYW47CnZhciBwOnBub2RlOwpiZWdpbgogIGZvdW5kOj1mYWxzZTsKICBwOj1nW3VdOwogIHdoaWxlIHA8Pm5pbHQgZG8KICBiZWdpbgogICAgZm91bmQ6PShmb3VuZCBvciAocF4udj12KSk7CiAgICBpZiBmb3VuZCB0aGVuIGV4aXQ7CiAgICBwOj1wXi5uZXh0OwogIGVuZDsKZW5kOwpwcm9jZWR1cmUgZW50ZXI7CnZhciBpLGosdSx2OndvcmQ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