#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int u, v, c;
};
int n, m;
vector<Edge> es;
vector<vector<int>> g;
int timer;
vector<int> tin;
vector<int> path;
vector<set<int>> cycles;
vector<int> incycle;
vector<set<int>> ec;
void dfs(int v, int p) {
  tin[v] = timer++;
  for (int i : g[v]) {
    int to = v ^ es[i].u ^ es[i].v;
    if (to != p) {
      path.push_back(i);
      if (tin[to] == -1) {
        dfs(to, v);
      } else if (tin[to] < tin[v]) {
        cycles.emplace_back();
        int pos = path.size() - 1;
        do {
          incycle[path[pos]] = cycles.size() - 1;
          cycles.back().insert(path[pos--]);
        } while (es[path[pos]].u != to && es[path[pos]].v != to);
        incycle[path[pos]] = cycles.size() - 1;
        cycles.back().insert(path[pos--]);
      }
      path.pop_back();
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  es.resize(m);
  g.resize(n);
  ec.resize(m);
  for (int i = 0; i < m; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    --u;
    --v;
    --c;
    es[i] = {u, v, c};
    g[u].push_back(i);
    g[v].push_back(i);
  }
  tin.resize(n, -1);
  incycle.resize(m, -1);
  dfs(0, -1);
  for (int i = 0; i < m; i++) {
    ec[es[i].c].insert(i - (incycle[i] == -1 ? m : 0));
  }
  set<pair<int, int>> ord;
  for (int c = 0; c < m; c++) {
    if (!ec[c].empty()) {
      ord.insert(make_pair(ec[c].size(), c));
    }
  }
  int ans = 0;
  while (!ord.empty()) {
    int c = ord.begin()->second;
    ord.erase(ord.begin());
    int i = *ec[c].begin();
    if (i < 0) {
      i += m;
    }
    ec[c].erase(ec[c].begin());
    ans++;
    if (incycle[i] != -1) {
      int ic = incycle[i];
      cycles[ic].erase(i);
      if (cycles[ic].size() == 1) {
        int j = *cycles[ic].begin();
        cycles[ic].erase(cycles[ic].begin());
        int _c = es[j].c;
        if (ord.count(make_pair(ec[_c].size(), _c))) {
          ord.erase(make_pair(ec[_c].size(), _c));
          ec[_c].erase(j);
          if (!ec[_c].empty()) {
            ord.insert(make_pair(ec[_c].size(), _c));
          }
        }
      }
    }
  }
  cout << ans << endl;
}
