#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\t";
  err(++it, args...);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& c, pair<T1, T2>& v) {
  c << "(" << v.first << "," << v.second << ")";
  return c;
}
template <template <class...> class TT, class... T>
ostream& operator<<(ostream& out, TT<T...>& c) {
  out << "{ ";
  for (auto& x : c) out << x << " ";
  out << "}";
  return out;
}
const int LIM = 20000 + 5, MOD = 1e9 + 7;
const long double EPS = 1e-9;
int read() {
  int xx = 0, ff = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') ff = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    xx = (xx << 3) + (xx << 1) + ch - '0';
    ch = getchar();
  }
  return xx * ff;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<pair<int, int>> adj[LIM];
int visited[LIM];
pair<int, int> par[LIM];
vector<int> cyc[LIM];
int num_cyc;
vector<bool> done[LIM];
vector<int> conv[LIM];
void dfs(int node, int p) {
  visited[node] = 1;
  int cnt = -1;
  for (auto& r : adj[node]) {
    int nxt = r.first;
    int col = r.second;
    cnt += 1;
    if (done[node][cnt]) continue;
    if (nxt == p) continue;
    if (visited[nxt]) {
      cyc[num_cyc].push_back(col);
      int last = node;
      done[node][cnt] = 1;
      int oth = conv[node][cnt];
      done[nxt][oth] = 1;
      while (last != nxt) {
        oth = conv[par[last].first][par[last].second];
        int lll = adj[par[last].first][par[last].second].first;
        done[lll][oth] = 1;
        done[par[last].first][par[last].second] = 1;
        int add_col = adj[par[last].first][par[last].second].second;
        cyc[num_cyc].push_back(add_col);
        last = par[last].first;
      }
      num_cyc++;
      continue;
    }
    par[nxt] = make_pair(node, cnt);
    dfs(nxt, node);
  }
}
struct FlowEdge {
  int v, u;
  long long cap, flow = 0;
  FlowEdge(int v, int u, long long cap) : v(v), u(u), cap(cap) {}
};
struct Dinic {
  const long long flow_inf = 1e18;
  vector<FlowEdge> edges;
  vector<vector<int>> adj;
  int n, m = 0;
  int s, t;
  vector<int> level, ptr;
  queue<int> q;
  Dinic(int n, int s, int t) : n(n), s(s), t(t) {
    adj.resize(n);
    level.resize(n);
    ptr.resize(n);
  }
  void add_edge(int v, int u, long long cap) {
    edges.emplace_back(v, u, cap);
    edges.emplace_back(u, v, 0);
    adj[v].push_back(m);
    adj[u].push_back(m + 1);
    m += 2;
  }
  bool bfs() {
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (int id : adj[v]) {
        if (edges[id].cap - edges[id].flow < 1) continue;
        if (level[edges[id].u] != -1) continue;
        level[edges[id].u] = level[v] + 1;
        q.push(edges[id].u);
      }
    }
    return level[t] != -1;
  }
  long long dfs(int v, long long pushed) {
    if (pushed == 0) return 0;
    if (v == t) return pushed;
    for (int& cid = ptr[v]; cid < (int)adj[v].size(); cid++) {
      int id = adj[v][cid];
      int u = edges[id].u;
      if (level[v] + 1 != level[u] || edges[id].cap - edges[id].flow < 1)
        continue;
      long long tr = dfs(u, min(pushed, edges[id].cap - edges[id].flow));
      if (tr == 0) continue;
      edges[id].flow += tr;
      edges[id ^ 1].flow -= tr;
      return tr;
    }
    return 0;
  }
  long long flow() {
    long long f = 0;
    while (true) {
      fill(level.begin(), level.end(), -1);
      level[s] = 0;
      q.push(s);
      if (!bfs()) break;
      fill(ptr.begin(), ptr.end(), 0);
      while (long long pushed = dfs(s, flow_inf)) {
        f += pushed;
      }
    }
    return f;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    u--;
    v--;
    conv[u].push_back(adj[v].size());
    conv[v].push_back(adj[u].size());
    adj[u].push_back(make_pair(v, c));
    adj[v].push_back(make_pair(u, c));
    done[u].push_back(0);
    done[v].push_back(0);
  }
  par[0] = make_pair(0, 0);
  dfs(0, -1);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < adj[i].size(); ++j) {
      if (done[i][j]) continue;
      done[i][j] = 1;
      int nxt = adj[i][j].first;
      int oth = conv[i][j];
      done[nxt][oth] = 1;
      cyc[num_cyc].push_back(adj[i][j].second);
      num_cyc++;
    }
  }
  for (int i = 0; i < m; ++i) {
    assert(cyc[i].size() != 2);
  }
  int s = 0, t = 2 * m + 1;
  map<int, int> cap[2 * m + 2];
  for (int i = 1; i < m + 1; ++i) {
    cap[0][i] = 1;
  }
  for (int i = 0; i < m; ++i) {
    int z = cyc[i].size();
    if (z <= 2)
      cap[m + 1 + i][t] = z;
    else
      cap[m + 1 + i][t] = z - 1;
  }
  for (int i = 0; i < m; ++i) {
    for (auto& r : cyc[i]) {
      cap[r][m + 1 + i]++;
    }
  }
  Dinic d(2 * m + 2, s, t);
  for (int i = 0; i < 2 * m + 2; i++) {
    for (auto& r : cap[i]) {
      d.add_edge(i, r.first, r.second);
    }
  }
  cout << d.flow() << '\n';
  return 0;
}
