{$M 4000000000}
const maxn = 2000;
maxm = 5000;
fi = '';
fo = '';
var m,n,t:word;
a: array[1..maxn,0..maxm] of word;
visit: array[1..maxn] of boolean;
procedure enter;
var i,j,u,v:word;
begin
assign(input,fi);
reset(input);
readln(n,m);
for i:=1 to n do
begin
a[i,0]:=0;
visit[i]:=false;
end;
for i:=1 to m do
begin
readln(u,v);
inc(a[u,0]);
a[u,a[u,0]]:=v;
inc(a[v,0]);
a[v,a[v,0]]:=u;
end;
end;
procedure dfs(i:word);
var j:word;
begin
visit[i]:=true;
for j:=1 to a[i,0] do
if not visit[a[i,j]] then dfs(a[i,j]);
end;
procedure solve;
var i:word;
begin
assign(output,fo);
rewrite(output);
t:=0;
for i:=1 to n do
if not visit[i] then
begin
inc(t);
dfs(i);
end;
writeln(m-n+t);
close(output);
end;
begin
enter;
solve;
end.
eyRNIDQwMDAwMDAwMDB9CmNvbnN0IG1heG4gPSAyMDAwOwogICAgICBtYXhtID0gNTAwMDsKICAgICAgZmkgPSAnJzsKICAgICAgZm8gPSAnJzsKdmFyIG0sbix0OndvcmQ7CiAgICBhOiBhcnJheVsxLi5tYXhuLDAuLm1heG1dIG9mIHdvcmQ7CiAgICB2aXNpdDogYXJyYXlbMS4ubWF4bl0gb2YgYm9vbGVhbjsKcHJvY2VkdXJlIGVudGVyOwp2YXIgaSxqLHUsdjp3b3JkOwpiZWdpbgogIGFzc2lnbihpbnB1dCxmaSk7CiAgcmVzZXQoaW5wdXQpOwogIHJlYWRsbihuLG0pOwogIGZvciBpOj0xIHRvIG4gZG8KICBiZWdpbgogICAgYVtpLDBdOj0wOwogICAgdmlzaXRbaV06PWZhbHNlOwogIGVuZDsKICBmb3IgaTo9MSB0byBtIGRvCiAgYmVnaW4KICAgIHJlYWRsbih1LHYpOwogICAgaW5jKGFbdSwwXSk7CiAgICBhW3UsYVt1LDBdXTo9djsKICAgIGluYyhhW3YsMF0pOwogICAgYVt2LGFbdiwwXV06PXU7CiAgZW5kOwplbmQ7CnByb2N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