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;
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
template <typename T, typename U>
static void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
static void amax(T &x, U y) {
  if (x < y) x = y;
}
struct MaximumFlow {
  static const int InfCapacity = INF;
  struct Edge {
    int to;
    int capacity;
    int rev;
  };
  vector<vector<Edge> > g;
  void init(int n) { g.assign(n, vector<Edge>()); }
  void add(int i, int j, int capacity) {
    Edge e, f;
    e.to = j, f.to = i;
    e.capacity = capacity, f.capacity = 0;
    g[i].push_back(e);
    g[j].push_back(f);
    g[i].back().rev = (int)g[j].size() - 1;
    g[j].back().rev = (int)g[i].size() - 1;
  }
  void addB(int i, int j, int capacity) {
    Edge e, f;
    e.to = j, f.to = i;
    e.capacity = capacity, f.capacity = capacity;
    g[i].push_back(e);
    g[j].push_back(f);
    g[i].back().rev = (int)g[j].size() - 1;
    g[j].back().rev = (int)g[i].size() - 1;
  }
  int maximumFlow(int s, int t) {
    int n = g.size();
    vector<int> level(n);
    int total = 0;
    bool update;
    do {
      update = false;
      fill(level.begin(), level.end(), -1);
      level[s] = 0;
      queue<int> q;
      q.push(s);
      for (int d = n; !q.empty() && level[q.front()] < d;) {
        int u = q.front();
        q.pop();
        if (u == t) d = level[u];
        for (auto e = (g[u]).begin(); e != (g[u]).end(); ++e)
          if (e->capacity > 0 && level[e->to] == -1)
            q.push(e->to), level[e->to] = level[u] + 1;
      }
      vector<int> iter(n);
      for (int i = 0; i < n; i++) iter[i] = (int)g[i].size() - 1;
      while (1) {
        int f = augment(level, iter, s, t, InfCapacity);
        if (f == 0) break;
        total += f;
        update = true;
      }
    } while (update);
    return total;
  }
  int augment(vector<int> &level, vector<int> &iter, int u, int t, int f) {
    if (u == t || f == 0) return f;
    int lv = level[u];
    if (lv == -1) return 0;
    level[u] = -1;
    for (; iter[u] >= 0; --iter[u]) {
      Edge &e = g[u][iter[u]];
      if (level[e.to] <= lv) continue;
      int l = augment(level, iter, e.to, t, min(f, e.capacity));
      if (l == 0) continue;
      e.capacity -= l;
      g[e.to][e.rev].capacity += l;
      level[u] = lv;
      return l;
    }
    return 0;
  }
};
void dfs(int i, int p, vector<int> &vis, int &num,
         vector<pair<int, int> > &path,
         const vector<vector<pair<int, int> > > &gw,
         vector<vector<int> > &cycles, vector<int> &treeEdges) {
  vis[i] = num++;
  for (auto e : gw[i]) {
    int j = e.first;
    if (j == p) continue;
    if (vis[j] == -1) {
      path.push_back(e);
      dfs(j, i, vis, num, path, gw, cycles, treeEdges);
      if (path.back().second != -1) treeEdges.push_back(path.back().second);
      path.pop_back();
    } else if (vis[i] > vis[j]) {
      int k = (int)path.size();
      while (k > 0 && path[k - 1].first != j) --k;
      vector<int> cycle;
      for (; k != path.size(); ++k) {
        cycle.push_back(path[k].second);
        path[k].second = -1;
      }
      cycle.push_back(e.second);
      cycles.emplace_back(cycle);
    }
  }
}
int main() {
  int n;
  int m;
  while (~scanf("%d%d", &n, &m)) {
    vector<vector<pair<int, int> > > gw(n);
    for (int i = 0; i < m; ++i) {
      int u, v, w;
      scanf("%d%d%d", &u, &v, &w), --u, --v, --w;
      gw[u].push_back(make_pair(v, w));
      gw[v].push_back(make_pair(u, w));
    }
    vector<vector<int> > cycles;
    vector<int> treeEdges;
    {
      vector<int> vis(n, -1);
      vector<pair<int, int> > path;
      int num = 0;
      dfs(0, -1, vis, num, path, gw, cycles, treeEdges);
    }
    MaximumFlow mf;
    int src = m + cycles.size(), dst = src + 1;
    mf.init(dst + 1);
    for (int(c) = 0; (c) < (int)(m); ++(c)) mf.add(src, c, 1);
    for (int c : treeEdges) mf.add(c, dst, 1);
    for (int(i) = 0; (i) < (int)(cycles.size()); ++(i)) {
      const vector<int> &cycle = cycles[i];
      for (int c : cycle) mf.add(c, m + i, 1);
      mf.add(m + i, dst, (int)cycle.size() - 1);
    }
    int ans = mf.maximumFlow(src, dst);
    printf("%d\n", ans);
  }
  return 0;
}
