#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int mod = (int)1e9 + 7;
struct edge {
  int u, v, c, f;
  edge() {}
  edge(int u, int v, int c) : u(u), v(v), c(c), f(0) {}
  int nxt(int x) { return x ^ u ^ v; }
};
struct FLOW {
  int N, s, t, d[maxn], cur[maxn];
  vector<edge> E;
  vector<int> G[maxn];
  void add_edge(int u, int v, int c) {
    G[u].push_back(E.size());
    E.push_back(edge(u, v, c));
    G[v].push_back(E.size());
    E.push_back(edge(v, u, 0));
  }
  bool bfs() {
    for (int i = 0; i < N; i++) d[i] = -1;
    queue<int> Q;
    d[s] = 0;
    Q.push(s);
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      for (int i = 0; i < G[u].size(); i++) {
        int id = G[u][i], v = E[id].v;
        if (d[v] == -1 && E[id].f < E[id].c) {
          d[v] = d[u] + 1;
          Q.push(v);
        }
      }
    }
    return (d[t] != -1);
  }
  int dfs(int u, int flow) {
    if (u == t) return flow;
    for (int &i = cur[u]; i < G[u].size(); i++) {
      int id = G[u][i], v = E[id].v;
      if (d[v] == d[u] + 1 && E[id].c > E[id].f) {
        int val = dfs(v, min(flow, E[id].c - E[id].f));
        if (val) {
          E[id].f += val;
          E[id ^ 1].f -= val;
          return val;
        }
      }
    }
    return 0;
  }
  int get_ans() {
    int ans = 0, x;
    while (bfs()) {
      for (int i = 0; i < N; i++) cur[i] = 0;
      while (x = dfs(s, mod)) {
        ans += x;
      }
    }
    return ans;
  }
};
FLOW FF;
vector<edge> E;
vector<int> G[maxn];
int n, m, p[maxn], f[maxn], vis[maxn], sz[maxn], have[maxn], cur;
void dfs(int u) {
  vis[u] = 1;
  for (int i = 0; i < G[u].size(); i++) {
    int id = G[u][i];
    if (f[id]) continue;
    f[id] = 1;
    int v = E[id].nxt(u);
    if (vis[v]) {
      cur++;
      int t = u, sz = 0;
      while (t != v) {
        f[p[t]] = 2;
        FF.add_edge(cur, E[p[t]].c + n, mod);
        t = E[p[t]].nxt(t);
        sz++;
      }
      FF.add_edge(cur, E[id].c + n, mod);
      f[id] = 2;
      FF.add_edge(FF.s, cur, sz);
    } else {
      p[v] = id;
      dfs(v);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    E.push_back(edge(u, v, c));
    G[u].push_back(i);
    G[v].push_back(i);
  }
  FF.N = n + m + 2, FF.s = 0, FF.t = n + m + 1;
  dfs(1);
  for (int i = 0; i < m; i++)
    if (f[i] == 1) FF.add_edge(FF.s, E[i].c + n, mod);
  for (int i = 1; i <= m; i++) {
    FF.add_edge(n + i, FF.t, 1);
  }
  cout << FF.get_ans() << '\n';
}
