#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 1e18;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;
const int MAXLOG = 18;
int n, m;
int H[MAXN];
int anc[MAXN][MAXLOG];
int maxi[MAXN][MAXLOG];
int par[MAXN];
vector<pair<int, int> > G[MAXN];
vector<pair<int, pair<int, int> > > edges;
void dfs_pre_LCA(int v, int p = -1, int c = 0) {
  anc[v][0] = p;
  maxi[v][0] = c;
  if (p != -1)
    H[v] = H[p] + 1;
  else
    H[v] = 0;
  for (int i = 1; i < MAXLOG; i++)
    if (anc[v][i - 1] != -1)
      anc[v][i] = anc[anc[v][i - 1]][i - 1],
      maxi[v][i] = max(maxi[v][i - 1], maxi[anc[v][i - 1]][i - 1]);
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i].first, w = G[v][i].second;
    if (p != u) dfs_pre_LCA(u, v, w);
  }
}
int queryLCA(int u, int v) {
  int maxim = 0;
  if (H[v] < H[u]) swap(v, u);
  for (int i = MAXLOG - 1; i > -1; i--)
    if (anc[v][i] != -1 && H[anc[v][i]] >= H[u])
      maxim = max(maxim, maxi[v][i]), v = anc[v][i];
  if (v == u) return maxim;
  for (int i = MAXLOG - 1; i > -1; i--)
    if (anc[v][i] != anc[u][i])
      maxim = max(maxim, maxi[v][i]), maxim = max(maxim, maxi[u][i]),
      v = anc[v][i], u = anc[u][i];
  maxim = max(maxim, maxi[v][0]);
  maxim = max(maxim, maxi[u][0]);
  return maxim;
}
int find(int v) {
  if (par[v] == v) return v;
  return par[v] = find(par[v]);
}
void unite(int u, int v) {
  par[find(u)] = find(v);
  find(u);
}
priority_queue<pair<int, pair<int, int> > > pq;
void kruskal() {
  for (int i = 0; i < n; i++) par[i] = i;
  while (!pq.empty()) {
    int u = pq.top().second.first, v = pq.top().second.second;
    int c = -pq.top().first;
    pq.pop();
    if (find(u) != find(v)) {
      unite(u, v);
      G[u].push_back({v, c});
      G[v].push_back({u, c});
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    a--;
    b--;
    pq.push({-c, {a, b}});
    edges.push_back({c, {a, b}});
  }
  memset(anc, -1, sizeof(anc));
  kruskal();
  dfs_pre_LCA(0);
  int ans = 0;
  for (auto e : edges) {
    int c = e.first;
    int v = e.second.first, u = e.second.second;
    if (queryLCA(u, v) == c) ans++;
  }
  printf("%d\n", ans - n + 1);
  return 0;
}
