program ex;
type
ss=array[1..100]of integer;
var
a,h:ss;
f1,f2:text;
n,m:integer;
procedure init;
var
i:integer;
begin
assign(f1,'goblin.in');
assign(f2,'goblin.out');
reset(f1);
rewrite(f2);
readln(f1,n,m);
for i:=1 to m do
readln(f1,a[i],h[i]);
close(f1);
end;
function pd:boolean;
var
i,t:integer;
begin
pd:=true;
for i:=1 to m do
if a[i]=h[i] then inc(t);
if t=i then exit(false);
end;
begin
init;
if pd=false then writeln(f2,'0');
close(f2);
end.