#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to;
  int cap;
} e[10005 * 7];
int n, sk, te, tot, ans;
int vis[10005 * 7];
pair<pair<int, int>, int> fk[10005 * 7];
vector<int> v[10005 * 7], go[10005 * 7], went;
map<int, int> mp;
int ne(int to, int cap) {
  e[te] = {to, cap};
  return te++;
}
int nw() { return ++tot; }
void ae(int from, int to, int cap) {
  v[from].push_back(ne(to, cap));
  v[to].push_back(ne(from, 0));
}
void fcyc(int node) {
  int tut = node;
  int cur = nw();
  int cnt = 0;
  do {
    int edn = went.back();
    ++cnt;
    went.pop_back();
    node = fk[edn].first.first ^ fk[edn].first.second ^ node;
    ae(cur, mp[fk[edn].second], 1);
    if (node == tut) break;
  } while (1);
  ae(0, cur, cnt - 1);
}
void dfs1(int node, int ata) {
  if (vis[node]) {
    if (vis[node] == 1)
      fcyc(node);
    else
      went.pop_back();
    return;
  }
  vis[node] = 1;
  for (int i : go[node]) {
    int to = fk[i].first.first ^ fk[i].first.second ^ node;
    if (to == ata) continue;
    went.push_back(i);
    dfs1(to, node);
    if (((int)went.size()) && went.back() == i) {
      int now = nw();
      ae(0, now, 1);
      ae(now, mp[fk[i].second], 1);
      went.pop_back();
    }
  }
  vis[node] = 2;
}
int dfs(int node, int cap) {
  vis[node] = 1;
  if (node == sk) return cap;
  for (int ed : v[node]) {
    int go = e[ed].to;
    int cp = e[ed].cap;
    int ad;
    if (!vis[go] && cp && (ad = dfs(go, min(cap, cp)))) {
      e[ed].cap -= ad;
      e[ed ^ 1].cap += ad;
      return ad;
    }
  }
  return 0;
}
void flow() {
  int add = 0;
  do {
    ans += add;
    memset(vis, 0, sizeof(vis));
    add = dfs(0, 1000000000);
  } while (add);
  printf("%d", ans);
  exit(0);
}
int main(int argc, char* argv[]) {
  int m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y, c;
    scanf("%d %d %d", &x, &y, &c);
    if (!mp[c]) mp[c] = nw();
    fk[i] = {{x, y}, c};
    go[x].push_back(i);
    go[y].push_back(i);
  }
  dfs1(1, 0);
  sk = nw();
  for (auto x : mp) ae(x.second, sk, 1);
  flow();
}
