#include<bits/stdc++.h>
using namespace std;

void dij(int V, int E, vector<vector<int> >a, int src, vector<bool> &c)
{
	int dist[V] = {INT_MAX};
  	dist[src] = 0;
  	for (int i = 1; i <= V - 1; i++) 
    { 
        for (int j = 0; j < E; j++) 
        { 
            int u = a[j][0]; 
            int v = a[j][1]; 
            int weight = a[j][2]; 
            if (dist[u] != INT_MAX && dist[u] + weight < dist[v])
            {
                dist[v] = dist[u] + weight;
              	c[j] = true;
            }
        } 
    }
}

int main()
{
  	int n, m;
  	cin>>n>>m;
  	vector<vector<int> >a(n, vector<int> (m, 0));
  	//vector<vector<bool> >vis(n, vector<int> (m, false));
  	for(int i = 0; i < n; i++)
    	for(int j = 0; j < m; j++)
          	cin>>a[i][j];
  	//memset(vis, false, sizeof(vis));
  	vector<bool> c(m, false);
  	bellman(n, m, a, vis, 0, c);
  	int res = 0;
  	for(int i = 0; i < m; i++)
      	if(c[i] == false)
          	res++;
  	cout<<res<<"\n";
	return 0;
}