program D; var graf1:array[1..10000,1..10000] of 0..1; n,m,i,j,x,y,a:longint; f:text; function tri(ii:longint):boolean; var res:boolean; begin res:=false; if (graf1[ii,ii-1]=1)and(graf1[ii-1,ii-2]=1)and(graf1[ii,ii-2]=1) then res:=true; tri:=res; end; {_______________________________} begin assign(f,'penalty.in'); reset(f); readln(f,n,m); for i:=1 to n do graf1[i,i]:=0; for i:=1 to m do begin readln(f,x,y); graf1[x,y]:=1; graf1[y,x]:=1; end; read(f,a); close(f); i:=n; x:=0; while i>=1 do begin if tri(i) then begin if i-1=a then i:=a else i:=i-2; end else begin if i<=a then x:=x+1000; i:=i-1; end; end; write(x); end.