#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 200010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const unsigned long long BS1 = 10000019ULL;
const int INF = (1 << 29);
template <class T>
inline void fastScan(T &x) {
  register char c = getchar();
  int neg = 0;
  x = 0;
  for (; (c < 48 || c > 57) && (c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
int n, m;
int par[N];
struct Edge {
  int u, v, w;
} edges[N];
bool as(Edge a, Edge b) { return a.w < b.w; }
int findRep(int r) {
  if (r == par[r]) {
    return r;
  }
  return par[r] = findRep(par[r]);
}
int main() {
  fastScan(n);
  fastScan(m);
  for (int i = 1; i <= m; i++) {
    fastScan(edges[i].u);
    fastScan(edges[i].v);
    fastScan(edges[i].w);
  }
  sort(edges + 1, edges + m + 1, as);
  for (int i = 1; i <= n; i++) {
    par[i] = i;
  }
  int cnt = 0;
  for (int i = 1, j; i <= m; i++) {
    for (j = i + 1; j <= m; j++) {
      if (edges[i].w != edges[j].w) {
        break;
      }
    }
    for (int k = i; k < j; k++) {
      int U = findRep(edges[k].u);
      int V = findRep(edges[k].v);
      if (U != V) {
        cnt++;
      }
    }
    for (int k = i; k < j; k++) {
      int U = findRep(edges[k].u);
      int V = findRep(edges[k].v);
      if (U != V) {
        par[U] = V;
      }
    }
    i = j - 1;
  }
  printf("%d\n", cnt - n + 1);
}
