#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
const long long N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long power(long long a, long long b = mod - 2) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
long long n, m, cyc = 0, sink, mx = 0;
vector<pair<long long, long long> > adjo[10005], path;
vector<long long> vis(10005);
vector<vector<long long> > cycles(10005);
map<long long, long long> mp;
void dfso(long long cur, long long prev) {
  vis[cur] = 1;
  for (pair<long long, long long> i : adjo[cur])
    if (!vis[i.first])
      path.push_back(i), dfso(i.first, cur);
    else if (vis[i.first] == 1 && i.first != prev) {
      cycles[++cyc].push_back(i.second);
      mp[i.second]--;
      for (long long k = ((long long)(path.size()) - 1); k >= (0); k--) {
        long long v = path[k].first, c = path[k].second;
        if (v == i.first) break;
        cycles[cyc].push_back(c);
        mp[c]--;
      }
    }
  path.pop_back();
  vis[cur] = 2;
}
struct edge {
  long long x, y, cap;
};
vector<edge> e;
vector<vector<long long> > adj;
void createEdge(long long x, long long y, long long cap) {
  e.push_back({x, y, cap});
  adj[x].push_back((long long)(e.size()) - 1);
  e.push_back({y, x, 0});
  adj[y].push_back((long long)(e.size()) - 1);
}
void createGraph() {
  sink = cyc + mx + 2;
  adj.resize(sink + 1);
  for (long long i = (1); i <= (cyc); i++)
    createEdge(1, i + 1, (long long)(cycles[i].size()) - 1);
  for (long long i = (1); i <= (cyc); i++) {
    for (long long j : cycles[i]) createEdge(i + 1, j + cyc + 1, 1);
  }
  for (long long i = (1); i <= (mx); i++) createEdge(cyc + i + 1, sink, 1);
  for (pair<long long, long long> i : mp)
    if (i.second) createEdge(1, i.first + cyc + 1, 1);
}
vector<long long> d, counter;
bool shortest_path() {
  d.assign(sink + 1, -1);
  queue<long long> q;
  q.push(1);
  d[1] = 0;
  while (!q.empty()) {
    long long u = q.front();
    q.pop();
    for (long long i : adj[u]) {
      long long v = e[i].y;
      if (e[i].cap > 0 && d[v] < 0) {
        q.push(v);
        d[v] = d[u] + 1;
      }
    }
  }
  return (d[sink] > -1) ? true : false;
}
long long dfs(long long cur, long long mincap) {
  if (cur == sink) return mincap;
  for (long long& i = counter[cur]; i < (long long)(adj[cur].size()); i++) {
    long long id = adj[cur][i], v = e[id].y;
    if (d[v] != d[cur] + 1 || !e[id].cap) continue;
    long long to_augment = dfs(v, min(mincap, e[id].cap));
    if (to_augment) {
      e[id].cap -= to_augment;
      e[id ^ 1].cap += to_augment;
      return to_augment;
    }
  }
  return 0;
}
long long max_flow() {
  long long flow = 0;
  while (true) {
    if (!shortest_path()) break;
    counter.assign(sink + 1, 0);
    while (true) {
      long long newflow = dfs(1, inf);
      if (!newflow) break;
      flow += newflow;
    }
  }
  return flow;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  ;
  for (long long i = (1); i <= (m); i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    ;
    adjo[x].push_back({y, z});
    adjo[y].push_back({x, z});
    mx = max(mx, z);
    mp[z]++;
  }
  dfso(1, 0);
  createGraph();
  cout << max_flow() << '\n';
  ;
}
