#include <bits/stdc++.h>
using namespace std;
vector<int> st;
int s_find(int r) { return st[r] == r ? r : st[r] = s_find(st[r]); }
void s_union(int a, int b) {
  int sa = s_find(a);
  int sb = s_find(b);
  st[sa] = sb;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<array<int, 3>> e;
  for (int i = 0; i < m; ++i) {
    int a, b, w;
    scanf("%d%d%d", &a, &b, &w);
    --a;
    --b;
    e.push_back({w, a, b});
  }
  sort(e.begin(), e.end());
  for (int i = 0; i < n; ++i) st.push_back(i);
  int cnt = 0, i = 0;
  while (i < m) {
    int j = i;
    while (i < m && e[j][0] == e[i][0]) i++;
    for (int k = j; k < i; ++k) cnt += s_find(e[k][1]) != s_find(e[k][2]);
    for (int k = j; k < i; ++k) s_union(e[k][1], e[k][2]);
  }
  printf("%d\n", cnt - n + 1);
  return 0;
}
