#include <bits/stdc++.h>   using namespace std;   inline int in() {     int x;     scanf( %d , &x);     return x;   }   inline void priv(vector<int> a) {     for (int i = 0; i < ((int)(a).size()); ++i)       printf( %d%c , a[i], i == (int)(a).size() - 1 ?   n  :    );   }   template <typename T>   istream& operator>>(istream& i, vector<T>& v) {     for (int j = 0; j < ((int)(v).size()); ++j) i >> v[j];     return i;   }   template <typename T>   string join(vector<T>& v) {     stringstream s;     for (int i = 0; i < ((int)(v).size()); ++i) s <<     << v[i];     return s.str().substr(1);   }   template <typename T>   ostream& operator<<(ostream& o, vector<T>& v) {     if ((int)(v).size()) o << join(v);     return o;   }   template <typename T1, typename T2>   istream& operator>>(istream& i, pair<T1, T2>& v) {     return i >> v.first >> v.second;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& o, pair<T1, T2>& v) {     return o << v.first <<  ,  << v.second;   }   const int MX = 100005, INF = 1001001001;   const long long int LINF = 1e18;   const double eps = 1e-10;   struct Maxflow {     int n;     vector<int> to, lim, next, head, dist, it;     Maxflow() {}     Maxflow(int n) : n(n), head(n, -1), it(n) {}     void add(int a, int b, int c = 1) {       next.push_back(head[a]);       head[a] = to.size();       to.push_back(b);       lim.push_back(c);       next.push_back(head[b]);       head[b] = to.size();       to.push_back(a);       lim.push_back(0);     }     void bfs(int sv) {       dist = vector<int>(n, INF);       queue<int> q;       dist[sv] = 0;       q.push(sv);       while (!q.empty()) {         int v = q.front();         q.pop();         for (int i = head[v]; i != -1; i = next[i]) {           if (lim[i] && dist[to[i]] == INF) {             dist[to[i]] = dist[v] + 1;             q.push(to[i]);           }         }       }     }     int dfs(int v, int tv, int nf = INF) {       if (v == tv) return nf;       for (; it[v] != -1; it[v] = next[it[v]]) {         int u = to[it[v]], f;         if (!lim[it[v]] || dist[v] >= dist[u]) continue;         if (f = dfs(u, tv, min(nf, lim[it[v]])), f) {           lim[it[v]] -= f;           lim[it[v] ^ 1] += f;           return f;         }       }       return 0;     }     int solve(int sv, int tv) {       int flow = 0, f;       while (1) {         bfs(sv);         if (dist[tv] == INF) return flow;         for (int i = 0; i < (n); ++i) it[i] = head[i];         while (f = dfs(sv, tv), f) flow += f;       }     }   };   int n, m;   vector<vector<int> > to, co;   vector<int> used, vs, es;   vector<vector<int> > g;   void dfs(int v, int p = -1) {     used[v] = 1;     for (int i = 0; i < ((int)(to[v]).size()); ++i) {       int u = to[v][i];       if (u == p) continue;       if (used[u]) {         if (used[u] == 1) {           g.push_back(vector<int>(1, co[v][i]));           for (int i = (int)(vs).size() - 1;; --i) {             g.back().push_back(es[i]);             es[i] = -1;             if (vs[i] == u) break;           }         }       } else {         vs.push_back(v);         es.push_back(co[v][i]);         dfs(u, v);         if (es.back() != -1) g.push_back(vector<int>(1, es.back()));         vs.pop_back();         es.pop_back();       }     }     used[v] = 2;   }   int main() {     scanf( %d%d , &n, &m);     to = co = vector<vector<int> >(n);     for (int i = 0; i < (m); ++i) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       --a;       --b;       --c;       to[a].push_back(b);       co[a].push_back(c);       to[b].push_back(a);       co[b].push_back(c);     }     used = vector<int>(n);     dfs(0);     int l = (int)(g).size(), sv = m + l, tv = sv + 1;     Maxflow mf(tv + 1);     for (int i = 0; i < (m); ++i) mf.add(sv, i);     for (int i = 0; i < (l); ++i)       mf.add(m + i, tv, max(1, (int)(g[i]).size() - 1));     for (int i = 0; i < (l); ++i) {       for (int j : g[i]) mf.add(j, m + i);     }     cout << mf.solve(sv, tv) << endl;     return 0;   }