#include<bits/stdc++.h>
using namespace std;
int n,k,num[50005],ty,eat[50005],ans=0;
int find(int a) {
if(a!=num[a]) num[a]=find(num[a]);
return num[a];
}
}
int main() {
cin>>n>>k;
for(int i=1; i<=n; i++) {
num[i]=i;
}
for(int i=1; i<=k; i++) {
cin>>ty;
if(ty==1) {
int o,p;
cin>>o>>p;
if(o>n||p>n) {
ans++;
continue;
} else if(eat[find(o)]==find(p) || eat[find(p)]==find(o)) {
ans++;
continue;
} else {
num[find(o)]=num[find(p)];
}
} else {
int o,p;
cin>>o>>p;
if(o>n||p>n) {
ans++;
continue;
} else if(eat[find(p)]==find(o) || find(p)==find(o)) {
ans++;
continue;
} else {
if(eat[find(o)]!=0) {
num[find(p)]=eat[find(o)];
} else {
eat[find(o)]=num[find(p)];
}
}
}
}
cout<<ans;
return 0;
}
有七个点MLE