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 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';
  ;
}
