#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<int> dijkstra(int s, vector<vector<pair<int, int>>>& adj) {
  vector<bool> visit(N);
  vector<int> dist(N, 1e9), par(N);
  priority_queue<pair<int, int>> q;
  dist[s] = 0;
  q.push(make_pair(0, s));
  visit[s] = true;
  par[s] = s;
  while (!q.empty()) {
    pair<int, int> tmp = q.top();
    q.pop();
    int t = tmp.second;
    visit[t] = true;
    if (dist[t] < tmp.first * (-1)) continue;
    for (int i = 0; i < adj[t].size(); i++) {
      int next = adj[t][i].first;
      if (visit[next]) continue;
      if (dist[next] > dist[t] + adj[t][i].second) {
        dist[next] = dist[t] + adj[t][i].second;
        par[next] = t;
        q.push(make_pair(dist[next] * (-1), next));
      }
    }
  }
  return par;
}
int main() {
  cin >> N >> M;
  vector<vector<pair<int, int>>> adj(N, vector<pair<int, int>>());
  for (int i = 0; i < N; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    adj[a].push_back(make_pair(b, c));
    adj[b].push_back(make_pair(a, c));
  }
  set<pair<int, int>> need;
  for (int i = 0; i < N; i++) {
    vector<int> par = dijkstra(i, adj);
    for (int j = 0; j < N; j++) {
      if (i == j) continue;
      need.insert((par[j] < j ? make_pair(par[j], j) : make_pair(j, par[j])));
    }
  }
  cout << M - need.size() << endl;
}
