#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> sides(M, vector<int>(3));
  for (int i = 0; i < M; i++) {
    cin >> sides[i][1] >> sides[i][2] >> sides[i][0];
    sides[i][1]--;
    sides[i][2]--;
  }
  sort(sides.begin(), sides.end());
  pair<bool, int> checked[N][N];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      checked[i][j].first = false;
    }
  }
  int spath[M];
  int count = 0;
  for (int i = 0; i < M; i++) {
    spath[i] = sides[i][0];
    int &x = sides[i][1];
    int &y = sides[i][2];
    if (spath[i] <= 2) {
      checked[x][y].first = checked[y][x].first = true;
      checked[x][y].second = checked[y][x].second = i;
      continue;
    }
    bool use = true;
    for (int p = 0; p < N; p++) {
      if (checked[x][p].first && checked[y][p].first) {
        int sum = spath[checked[x][p].second] + spath[checked[y][p].second];
        if (sum < spath[i]) {
          use = false;
          spath[i] = sum;
        }
      }
    }
    if (!use) count++;
    checked[x][y].first = checked[y][x].first = true;
    checked[x][y].second = checked[y][x].second = i;
  }
  cout << count << endl;
  return 0;
}
