Tree is a connected undirected graph that has no cycles. Edge cactus is a connected undirected graph without loops and parallel edges, such that each edge belongs to at most one cycle.

Vasya has an edge cactus, each edge of this graph has some color.

Vasya would like to remove the minimal number of edges in such way that his cactus turned to a tree. Vasya wants to make it in such a way that there were edges of as many different colors in the resulting tree, as possible. Help him to find how many different colors can the resulting tree have.

Input

The first line contains two integers: n, m (2 ≤ n ≤ 10 000) — the number of vertices and the number of edges in Vasya's graph, respectively.

The following m lines contain three integers each: u, v, c (1 ≤ u, v ≤ n, u ≠ v, 1 ≤ c ≤ m) — the numbers of vertices connected by the corresponding edge, and its color. It is guaranteed that the described graph is indeed an edge cactus.

Output

Output one integer: the maximal number of different colors that the resulting tree can have.

Examples

Input

4 4
1 2 4
2 3 1
3 4 2
4 2 3


Output

3


Input

7 9
1 2 1
2 3 4
3 1 5
1 4 5
4 5 2
5 1 6
1 6 4
6 7 6
7 1 3


Output

6
#include <bits/stdc++.h>
using namespace std;
const long long MX = 10011;
const long long MX_color = 20011;
struct FlowEdge {
  long long v, u;
  long long cap, flow = 0;
  FlowEdge(long long v, long long u, long long cap) : v(v), u(u), cap(cap) {}
};
struct Dinic {
  const long long flow_INF = 1e18;
  vector<FlowEdge> edges;
  vector<vector<long long> > adj;
  long long n, m = 0, s, t;
  vector<long long> level, ptr;
  queue<long long> q;
  Dinic(long long n, long long s, long long t) : n(n), s(s), t(t) {
    adj.resize(n);
    level.resize(n);
    ptr.resize(n);
  }
  void add_edge(long long v, long long 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()) {
      long long v = q.front();
      q.pop();
      for (long long 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(long long v, long long pushed) {
    if (pushed == 0) return 0;
    if (v == t) return pushed;
    for (long long& cid = ptr[v]; cid < (long long)adj[v].size(); cid++) {
      long long id = adj[v][cid];
      long long 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;
  }
};
bool vis[MX];
long long dist[MX];
pair<long long, long long> parent[MX];
vector<pair<long long, long long> > adj[MX];
multiset<pair<pair<long long, long long>, long long> > ari;
vector<vector<long long> > ciclos;
long long queda[MX_color];
void quita(long long u, long long v, long long c) {
  queda[c]--;
  ciclos.push_back({});
  long long sz = ciclos.size();
  ciclos[sz - 1].push_back(c);
  while (u != v) {
    long long c1 = parent[u].second;
    long long c2 = parent[v].second;
    if (dist[u] > dist[v]) {
      queda[c1]--;
      u = parent[u].first;
      ciclos[sz - 1].push_back(c1);
    } else if (dist[u] < dist[v]) {
      queda[c2]--;
      v = parent[v].first;
      ciclos[sz - 1].push_back(c2);
    } else {
      queda[c1]--;
      queda[c2]--;
      v = parent[v].first;
      u = parent[u].first;
      ciclos[sz - 1].push_back(c1);
      ciclos[sz - 1].push_back(c2);
    }
  }
  return;
}
void dfs(long long u, long long d) {
  dist[u] = d;
  vis[u] = true;
  for (auto par : adj[u]) {
    long long v = par.first;
    long long c = par.second;
    auto it = ari.find({{min(u, v), max(u, v)}, c});
    if (it != ari.end()) {
      ari.erase(it);
      if (!vis[v]) {
        parent[v] = {u, c};
        dfs(v, d + 1);
      } else {
        quita(u, v, c);
      }
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(10);
  cout << fixed;
  set<long long> colores_tot;
  long long n, m, x, y, c;
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    cin >> x >> y >> c;
    adj[x].push_back({y, c});
    adj[y].push_back({x, c});
    ari.insert({{min(x, y), max(x, y)}, c});
    queda[c]++;
    colores_tot.insert(c);
  }
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i, 0);
  }
  long long nn = MX_color + ciclos.size() + 2;
  long long s = 0;
  long long t = nn - 1;
  Dinic G(nn, s, t);
  for (long long i = 0; i < ciclos.size(); i++) {
    long long sz = ciclos[i].size();
    G.add_edge(s, MX_color + i, sz - 1);
    for (long long j = 0; j < sz; j++) {
      G.add_edge(MX_color + i, ciclos[i][j], 1);
    }
  }
  for (long long i = 1; i < MX_color; i++) {
    if (queda[i] != 0) {
      G.add_edge(s, i, queda[i]);
    }
  }
  for (long long x : colores_tot) {
    G.add_edge(x, t, 1);
  }
  cout << G.flow() << "\n";
  return 0;
}
