#include <bits/stdc++.h>
using namespace std;
const int INF = 1e+9;
struct edge {
  int to;
  int cost;
};
void dijkstra(vector<edge> G[], vector<int> &d, int s) {
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  d[s] = 0;
  q.push(make_pair(0, s));
  while (!q.empty()) {
    pair<int, int> p = q.top();
    q.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        q.push(make_pair(d[e.to], e.to));
      }
    }
  }
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<edge> G[101];
  vector<int> d(N + 1, INF);
  for (int i = 0; i < M; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    edge e = {v, c};
    G[u].push_back(e);
  }
  dijkstra(G, d, 1);
  int count = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < G[i].size(); j++) {
      if (d[G[i][j].to] != d[i] + G[i][j].cost) count++;
    }
  }
  cout << count << endl;
  return 0;
}
