#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000000000000000;
const int SI = 1000000;
int par[SI], ans[SI], deg[SI];
vector<int> adj[SI];
queue<int> tarjan;
struct Edge {
  int from, to, w, idx;
  bool operator<(const Edge &e) const { return w < e.w; }
} E[SI];
int UN_FIND(int root) {
  if (root == par[root]) return root;
  return par[root] = UN_FIND(par[root]);
}
void merge_(int sub1, int sub2) { par[UN_FIND(sub2)] = UN_FIND(sub1); }
void topo_sort() {
  while (!tarjan.empty()) {
    int root = tarjan.front();
    tarjan.pop();
    for (auto to : adj[root]) {
      --deg[to];
      if (deg[to] == 1) tarjan.push(to);
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &E[i].from, &E[i].to, &E[i].w);
    E[i].idx = i;
  }
  for (int i = 1; i <= n; ++i) par[i] = i;
  sort(E + 1, E + m + 1);
  int j;
  for (int i = 1; i <= m; ++i) {
    j = i;
    while ((j + 1 <= m) && (E[i].w == E[j + 1].w)) ++j;
    set<int> nodes;
    for (int k = i; k <= j; ++k) {
      E[k].from = UN_FIND(E[k].from), E[k].to = UN_FIND(E[k].to);
      if (E[k].from == E[k].to) continue;
      nodes.insert(E[k].from);
      nodes.insert(E[k].to);
    }
    for (auto it = nodes.begin(); it != nodes.end(); ++it) {
      adj[*it].clear();
      deg[*it] = 0;
    }
    while (!tarjan.empty()) tarjan.pop();
    for (int k = i; k <= j; ++k) {
      int c1 = E[k].from, c2 = E[k].to;
      if (c1 == c2) continue;
      adj[c1].push_back(c2);
      adj[c2].push_back(c1);
      ++deg[c1];
      ++deg[c2];
    }
    for (auto it = nodes.begin(); it != nodes.end(); ++it) {
      if (deg[*it] == 1) tarjan.push(*it);
    }
    topo_sort();
    for (int k = i; k <= j; ++k) {
      int c1 = E[k].from, c2 = E[k].to;
      if (c1 == c2) continue;
      if (deg[c1] > 1 && deg[c2] > 1)
        ans[E[k].idx] = 1;
      else
        ans[E[k].idx] = 2;
      merge_(c1, c2);
    }
    swap(i, j);
  }
  int annn = 0;
  for (int i = 1; i <= m; ++i)
    if (ans[i] == 0) ++annn;
  cout << annn;
  return 0;
}
