program xmz;
var
f1,f2:text;
a,n,m,sx,sy,t1,t2:integer;
x,y,zx,zy:array[1..200000]of longint;
begin
assign(f1,'board.in');assign(f2,'board.out');
rewrite(f2);reset(f1);
read(f1,n,m);
for a:=1 to m do
begin
read(f1,t1); if x[t1]=0 then sx:=sx+1; x[t1]:=x[t1]+1;
read(f1,t2); if y[t2]=0 then sy:=sy+1; y[t2]:=y[t2]+1;
zx[t1]:=t2;
zy[t2]:=t1;
end;
if sx<sy then for a:=1 to n do if x[a]=1 then m:=m-1;
if sy<sx then for a:=1 to n do if y[a]=1 then m:=m-1;
if sx=sy then for a:=1 to n do
begin
if x[a]=1 then begin m:=m-1;if y[zx[a]]=1 then y[zx[a]]:=5;end;
if y[a]=1 then begin m:=m-1;if x[zy[a]]=1 then x[zy[a]]:=5;end;
end;
if m<0 then write(f2,0) else write(f2,m);
close(f1);close(f2);
end.