#include <bits/stdc++.h>
using namespace std;
struct edge {
  int a, b, c, f, index;
};
const int MAXN = 100000 + 10;
vector<pair<int, int> > G[MAXN + 1];
vector<edge> Gflow[MAXN + 10];
vector<vector<int> > cycles;
int color[MAXN + 1], s, t, ptr[MAXN + 1], d[MAXN + 10];
pair<int, int> pr[MAXN + 1];
map<int, int> cnt;
void dfs(int v, int p = -1, int col = -1) {
  color[v] = 1;
  pr[v] = {p, col};
  for (int i = 0; i < (int)G[v].size(); i++) {
    int u = G[v][i].first;
    if (!color[u])
      dfs(u, v, G[v][i].second);
    else if (color[u] == 2) {
      cycles.push_back(vector<int>());
      int s = v, t = u;
      cycles.back().push_back(G[v][i].second);
      cnt[G[v][i].second]--;
      while (t != s) {
        cycles.back().push_back(pr[t].second);
        cnt[pr[t].second]--;
        t = pr[t].first;
      }
    }
  }
  color[v] = 2;
}
bool bfs() {
  memset(d, -1, sizeof(d));
  queue<int> q;
  q.push(s);
  d[0] = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < (int)Gflow[v].size(); i++) {
      int u = Gflow[v][i].a;
      if (d[u] == -1 && Gflow[v][i].c - Gflow[v][i].f > 0) {
        d[u] = d[v] + 1;
        q.push(u);
      }
    }
  }
  return d[t] != -1;
}
int dfs1(int v, int flow) {
  if (!flow) return 0;
  if (v == t) return flow;
  for (int to = ptr[v]; to < (int)Gflow[v].size(); to++, ptr[v]++) {
    int u = Gflow[v][to].a;
    if (d[u] != d[v] + 1) continue;
    int cur = dfs1(u, min(flow, Gflow[v][to].c - Gflow[v][to].f));
    if (cur) {
      Gflow[v][to].f += cur;
      Gflow[u][Gflow[v][to].index].f -= cur;
      return cur;
    }
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  srand(time(NULL));
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    G[a].push_back({b, c});
    G[b].push_back({a, c});
    cnt[c]++;
  }
  dfs(1);
  int shift = cycles.size();
  for (int i = 0; i < (int)cycles.size(); i++) {
    Gflow[i + 1].push_back({0, -1, 0, 0, (int)Gflow[0].size()});
    Gflow[0].push_back({i + 1, -1, (int)cycles[i].size() - 1, 0,
                        (int)Gflow[i + 1].size() - 1});
    map<int, int> temp;
    for (int j = 0; j < (int)cycles[i].size(); j++) temp[cycles[i][j]]++;
    for (int j = 0; j < (int)cycles[i].size(); j++) {
      if (!temp[cycles[i][j]]) continue;
      Gflow[shift + cycles[i][j]].push_back(
          {i + 1, -1, 0, 0, (int)Gflow[i + 1].size()});
      Gflow[i + 1].push_back({shift + cycles[i][j], -1, temp[cycles[i][j]], 0,
                              (int)Gflow[shift + cycles[i][j]].size() - 1});
      temp[cycles[i][j]] = 0;
    }
  }
  t = shift + m + 2;
  for (int i = shift + 1; i <= shift + 1 + m; i++) {
    if (!cnt[i - shift]) {
      Gflow[i].push_back({t, -1, 1, 0, (int)Gflow[t].size()});
      Gflow[t].push_back({i, -1, 0, 0, (int)Gflow[i].size() - 1});
    }
  }
  int flow = 0;
  while (true) {
    if (!bfs()) break;
    memset(ptr, 0, sizeof(ptr));
    int c;
    while (c = dfs1(s, 1e9)) {
      flow += c;
    }
  }
  for (int i = shift + 1; i <= shift + 1 + m; i++) {
    for (int j = 0; j < (int)Gflow[i].size(); j++) {
      if (Gflow[i][j].a == t && Gflow[i][j].f) cnt[i - shift]++;
    }
  }
  int ans = 0;
  for (auto it : cnt)
    if (it.second > 0) ans++;
  cout << ans << endl;
  return 0;
}
