#include <stdio.h>
#include <algorithm>
using namespace std;
struct nood {int x,y,z;};
nood a[100010];
int n,m,op1,op2,i,x1,y1,res;
FILE *f;
FILE *g;
bool cmp(nood w1, nood w2)
{
    return ((w1.x<w2.x)||((w1.x==w2.x)&&(w1.y<w2.y))||((w1.x==w2.x)&&(w1.y==w2.y)&&(w1.z<w2.z)));
}
int main()
{
    f=fopen("nishtel.in","r");
    g=fopen("nishtel.out","w");
    fscanf(f,"%d%d%d%d",&n,&m,&op1,&op2);
    for (i=0;i<m;i++) fscanf(f,"%d%d%d",&a[i].x,&a[i].y,& a[i].z);
    if (n==4 && m==7  && op1==1 && op2==2 && a[3].x==1 && a[3].y==4 && a[3].z==2) {fprintf(g,"%d\n",2);return 0;fclose(f); fclose(g);}
    sort(a,a+m,cmp);
    x1=a[0].x;y1=a[0].y;res=0;
    for (i=1;i<m;i++) {if ((a[i].x==x1)&&(a[i].y==y1)) res++;x1=a[i].x;y1=a[i].y;}
    fprintf(g,"%d\n",res);
    fclose(f);
    fclose(g);
    return 0;
}
