program school;
var
t,n,m,i,j,x,x1,x2,z,y:longint;
a,l,d,p:array[1..100000]of longint;
bz,biaozhi:array[1..100000]of boolean;
function find(v:longint):longint;
begin
{if v=l[v] then
begin
x:=v;
exit
end
else
begin
find(l[v]);
l[v]:=x
end }
if l[v]<>v then l[v]:=find(l[v]);
exit(l[v]);
end;
begin
assign (input,'sent.in');
reset (input);
assign (output,'sent.out');
rewrite (output);
readln (n);
readln (m);
for i:=1 to n do
begin
bz[i]:=true;
biaozhi[i]:=true
end;
for i:=1 to n do
l[i]:=i;
for i:=1 to m do
begin
readln (z,y);
biaozhi[z]:=false;
biaozhi[y]:=false;
inc(a[z]);
inc(a[y]);
x1:=find(z);
x2:=find(y);
l[x1]:=x2
end;
for i:=1 to n do
begin
x:=find(i);
bz[x]:=false;
if a[i]mod 2=0 then
inc(d[x])
else
inc(p[x])
end;
for i:=1 to n do
begin
if bz[i]=false then
begin
inc(t);
if (p[i]<>0)and(p[i]<>2) then
t:=t+(p[i]-2)div 2
end
end;
for i:=1 to n do
if biaozhi[i] then
dec(t);
t:=t-1;
if t=0 then
writeln ('-1')
else
writeln(t);
close (input);
close (output)
end.