#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("avx")
int mf;
struct edge {
  int v, c;
  edge(int _v, int _c) : v(_v), c(_c) {}
};
vector<edge> e;
vector<vector<int> > g;
inline void add(const int& u, const int& v, const int& c = 1) {
  g[u].push_back(e.size());
  e.push_back({v, c});
  g[v].push_back(e.size());
  e.push_back({u, 0});
}
int st, sink;
vector<int> d, p;
bool bfs() {
  for (int i = (0); i < (mf); ++i) d[i] = -1, p[i] = 0;
  queue<int> q;
  q.push(st);
  d[st] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int& i : g[u])
      if (e[i].c) {
        int v = e[i].v;
        if (d[v] < 0) d[v] = d[u] + 1, q.push(v);
      }
  }
  return d[sink] >= 0;
}
int push(const int& u, const int& f) {
  if (u == sink || !f) return f;
  for (int& i = p[u]; i < (int)g[u].size(); ++i) {
    int j = g[u][i];
    int v = e[j].v;
    if (e[j].c && d[v] == d[u] + 1) {
      int res = push(v, min(e[j].c, f));
      if (res) {
        e[j].c -= res, e[j ^ 1].c += res;
        return res;
      }
    }
  }
  return 0;
}
int maxflow() {
  int ans = 0;
  while (bfs())
    while (int cur = push(st, INT_MAX)) ans += cur;
  return ans;
}
int n, m;
int col(const int& i) { return i; }
int gr(const int& i) { return i + m + m; }
int eno(const int& i) { return i + m; }
vector<pair<int, int> > adjlist[10005];
int id[10005], par[10005];
bool ind[10005], met[10005], used[20005];
inline void dfs(const int& u) {
  ind[u] = met[u] = true;
  for (pair<int, int>& i : adjlist[u])
    if (i.first != par[u]) {
      int v = i.first;
      if (ind[v]) {
        int curr = u, cunt = 0;
        add(eno(i.second), gr(i.second));
        used[i.second] = true;
        while (curr != v) {
          add(eno(id[curr]), gr(i.second));
          used[id[curr]] = true;
          curr = par[curr], ++cunt;
        }
        add(gr(i.second), sink, cunt);
      } else if (!met[v]) {
        id[v] = i.second, par[v] = u;
        dfs(v);
      }
    }
  ind[u] = false;
  return;
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cin >> n >> m;
  st = 0, sink = m + m + m + 2;
  mf = sink + 1;
  g.resize(mf), d.resize(mf), p.resize(mf);
  for (int i = 1; i <= (m); ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    adjlist[x].push_back({y, i}), adjlist[y].push_back({x, i});
    add(st, col(i)), add(col(z), eno(i));
  }
  par[1] = -1;
  dfs(1);
  for (int i = 1; i <= (m); ++i)
    if (!used[i]) {
      add(eno(i), sink);
    }
  cout << maxflow() << "\n";
  return 0;
}
