{$A+,B-,D+,E+,F-,G-,I+,L+,N-,O-,P-,Q-,R-,S+,T-,V+,X+} {$M 16384,0,655360} program net; var i,j,n,k,x1,x2,l:integer; a:array[1..200,1..200]of byte; b1,b2:array[1..200]of byte; stek:array[1..200]of boolean; s,m:array[1..200]of integer; f1,f2:text; begin assign(f1,'net.dat'); assign(f2,'net.res'); reset(f1); rewrite(f2); read(f1,n,k); {for i:=1 to n do begin readln(f1,x1,x2); readln(f1); a[x1,x2]:=1; end;} i:=0; while not eof(f1) do begin inc(i); read(f1,b1[i],b2[i]); readln(f1); end; for i:=1 to n do a[b1[i],b2[i]]:=1; close(f1); stek[i]:=true; for i:=1 to n do for j:=1 to n do begin if b1[i]=b2[j] then s[i]:=j; end; for i:=1 to n do for j:=1 to n do begin if s[i]=s[j] then inc(m[s[i]]); end; i:=1; while m[i]<>0 do inc(l); if l=k then write(f2,'1') else write(f2,'0'); end.