#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
struct Edge {
  int u, v, c;
  Edge(int v, int c) : v(v), c(c) {}
  Edge(int u, int v, int c) : u(u), v(v), c(c) {}
  bool operator<(const Edge &x) const { return c < x.c; }
};
bool ok[N];
vector<Edge> e, g[N];
int n, m, parent[N], level[N], spT[N][22], mxT[N][22];
int findParent(int u) {
  return u == parent[u] ? u : parent[u] = findParent(parent[u]);
}
void kruskal() {
  sort(e.begin(), e.end());
  for (int i = 1; i <= n; i++) {
    parent[i] = i;
  }
  for (int i = 0; i < m; i++) {
    int x = findParent(e[i].u);
    int y = findParent(e[i].v);
    if (x != y) {
      ok[i] = 1;
      parent[x] = y;
      g[e[i].u].push_back(Edge(e[i].v, e[i].c));
      g[e[i].v].push_back(Edge(e[i].u, e[i].c));
    }
  }
}
void dfs(int u, int p, int w) {
  mxT[u][0] = w;
  spT[u][0] = p;
  level[u] = level[p] + 1;
  for (int i = 0; i < g[u].size(); i++) {
    if (g[u][i].v != p) {
      dfs(g[u][i].v, u, g[u][i].c);
    }
  }
}
void init() {
  kruskal();
  memset(spT, -1, sizeof spT);
  level[0] = -1;
  dfs(1, 0, 0);
  for (int j = 1; (1 << j) <= n; j++) {
    for (int i = 1; i <= n; i++) {
      if (spT[i][j - 1] != -1) {
        spT[i][j] = spT[spT[i][j - 1]][j - 1];
        mxT[i][j] = max(mxT[i][j - 1], mxT[spT[i][j - 1]][j - 1]);
      }
    }
  }
}
int query(int p, int q) {
  if (level[p] < level[q]) swap(p, q);
  int ret = 0;
  for (int i = 19; i >= 0; i--) {
    if (level[p] - (1 << i) >= level[q]) {
      ret = max(ret, mxT[p][i]);
      p = spT[p][i];
    }
  }
  if (p == q) return ret;
  for (int i = 19; i >= 0; i--) {
    if (spT[p][i] != -1 && spT[p][i] != spT[q][i]) {
      ret = max(ret, max(mxT[q][i], mxT[p][i]));
      p = spT[p][i];
      q = spT[q][i];
    }
  }
  return ret = max(ret, max(mxT[p][0], mxT[q][0]));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    e.push_back(Edge(u, v, c));
  }
  init();
  int ans = 0;
  for (int i = 0; i < m; i++) {
    if (ok[i]) continue;
    int x = query(e[i].u, e[i].v);
    assert(x <= e[i].c);
    if (x == e[i].c) ans++;
  }
  cout << ans << '\n';
  return 0;
}
