#include<stdio.h>
int f[100020];
int father(int k)
{
if (f[k] == k)
return k;
return f[k] = father(f[k]);
}
int main(void)
{
freopen("explosion.in", "r", stdin);
freopen("explosion.out", "w", stdout);
int a, b, x, y, i;
int ans = 0;
for (i = 0; i < 100010; i++)
f[i] = i;
scanf("%d%d", &x, &y);
while (x != -1)
{
a = father(x);
b = father(y);
if (a != b)
f[a] = b;
else
ans++;
scanf("%d%d", &x, &y);
}
printf("%d", ans);
fclose(stdin);
fclose(stdout);
return 0;
}