#include <bits/stdc++.h>
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
bool used[100];
int mincost[100];
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<pair<int, int>> V[n];
  for (int i = 0; i < m; ++i) {
    int t1, t2, t3;
    ;
    scanf("%d %d %d", &t1, &t2, &t3);
    t1--;
    t2--;
    V[t1].push_back(make_pair(t3, t2));
  }
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      que;
  que.push(pair<int, int>(0, 0));
  int res = 0, cur = 0;
  while (!que.empty()) {
    int cost = que.top().first, v = que.top().second;
    que.pop();
    if (used[v]) {
      if (mincost[v] != mincost[cur] + cost) {
        res++;
      }
      continue;
    }
    used[v] = 1;
    mincost[v] = cost + mincost[cur];
    cur = v;
    for (int i = 0; i < V[v].size(); ++i) {
      que.push(pair<int, int>(V[v][i].first, V[v][i].second));
    }
  }
  printf("%d\n", res);
  return 0;
}
