#include <bits/stdc++.h>
using namespace std;
long long powmod(long long base, long long exp, long long MOD) {
  long long res = 1;
  while (exp > 0) {
    if (exp % 2 == 1) res = (res * base) % MOD;
    base = (base * base) % MOD;
    exp /= 2;
  }
  return (res % MOD);
}
int n, m;
bool cmp(pair<pair<int, int>, int> &a, pair<pair<int, int>, int> &b) {
  return a.second < b.second;
}
int find(vector<int> &arr, int i) {
  if (arr[i] != i)
    return arr[i] = find(arr, arr[i]);
  else
    return arr[i];
}
void uni(vector<int> &parent, vector<int> &rank, int x, int y) {
  int xroot = find(parent, x);
  int yroot = find(parent, y);
  if (rank[xroot] < rank[yroot])
    parent[xroot] = yroot;
  else if (rank[yroot] < rank[xroot])
    parent[yroot] = xroot;
  else {
    parent[yroot] = xroot;
    rank[xroot]++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  vector<pair<int, int> > *arr = new vector<pair<int, int> >[n + 1];
  vector<pair<pair<int, int>, int> > v;
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    arr[x].push_back(make_pair(y, z));
    arr[y].push_back(make_pair(x, z));
    v.push_back(make_pair(make_pair(x, y), z));
  }
  vector<int> rank(n + 1, 0), parent(n + 1);
  for (int i = 1; i <= n; i++) parent[i] = i;
  sort(v.begin(), v.end(), cmp);
  vector<pair<int, int> > *ans = new vector<pair<int, int> >[n + 1];
  long long cnt = 0;
  int temp = -1;
  for (int i = 0; i < v.size(); i++) {
    int temp1 = v[i].first.first;
    int temp2 = v[i].first.second;
    if (v[i].second == -2) continue;
    if (v[i].second != temp) {
      int k = i;
      temp = v[k].second;
      while (v[k].second == temp) {
        int temp1 = v[k].first.first;
        int temp2 = v[k].first.second;
        if (find(parent, temp1) == find(parent, temp2)) v[k].second = -2;
        k++;
      }
    }
    if (v[i].second == temp && (find(parent, temp1) == find(parent, temp2))) {
      cnt++;
    } else if (find(parent, temp1) != find(parent, temp2)) {
      ans[temp1].push_back(make_pair(temp2, v[i].second));
      ans[temp2].push_back(make_pair(temp1, v[i].second));
      uni(parent, rank, temp1, temp2);
    }
    temp = v[i].second;
  }
  cout << cnt;
  delete[] arr;
  delete[] ans;
  return 0;
}
