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 int iinf = 0x7fffffff;
const long long linf = ~(1LL << 63);
template <typename T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  if (a < b) return gcd(b, a);
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long qpow(long long a, long long n, long long mod) {
  a %= mod;
  long long ans = 1LL;
  while (n) {
    if (n & 1) ans = (ans * a % mod);
    a = (a * a % mod);
    n >>= 1;
  }
  return ans;
}
inline long long rev(long long a, long long p) { return qpow(a, p - 2, p); }
inline int in() {
  int x;
  cin >> x;
  return x;
}
const int maxn = 10100;
struct MaximumFlow {
  static const int INF = 0x3f3f3f3f;
  static const int InfCapacity = INF;
  struct Edge {
    int to, rev;
    int capacity;
  };
  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 = g[j].size() - 1;
    g[j].back().rev = 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) 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;
  }
} mf;
bool color_vis[maxn];
struct edge {
  int to;
  int c;
  int rev;
  bool bridge;
};
vector<edge> E[maxn];
vector<int> color[maxn];
set<int> colorbr;
int blksz[maxn];
bool vis[maxn];
int blkid = 1;
pair<int, int> stk[maxn];
int sz = 0;
int dfn[maxn];
int low[maxn];
int stamp = 1;
void addedge(int u, int v, int c) {
  E[u].push_back({v, c, (int)E[v].size(), false});
  E[v].push_back({u, c, (int)E[u].size() - 1, false});
}
void dfs(int n, int fa = -1) {
  low[n] = dfn[n] = stamp++;
  for (auto e : E[n]) {
    int v = e.to;
    if (v == fa) continue;
    if (dfn[v]) {
      if (dfn[v] < dfn[n]) {
        color[blkid].push_back(e.c);
        int p = sz - 1;
        int bsz = 1;
        while (true) {
          bsz++;
          color[blkid].push_back(stk[p].second);
          if (stk[p].first == v) break;
          p--;
        }
        blksz[blkid] = bsz;
        blkid++;
      }
      low[n] = min(low[n], dfn[v]);
    } else {
      stk[sz++] = make_pair(n, e.c);
      dfs(v, n);
      low[n] = min(low[n], low[v]);
      if (low[v] > dfn[n]) {
        colorbr.insert(e.c);
      }
      sz--;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  int u, v, c;
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> c;
    addedge(u, v, c);
  }
  memset(dfn, 0, sizeof dfn);
  dfs(1);
  int s = 0, t = m + maxn + 5;
  mf.init(t + 1);
  set<int> cc;
  for (int i = 1; i < blkid; i++) {
    mf.add(s, i, blksz[i] - 1);
    for (auto c : color[i]) {
      if (colorbr.find(c) == colorbr.end()) {
        mf.add(i, c + maxn, 1);
        cc.insert(c);
      }
    }
  }
  for (auto c : cc) {
    mf.add(c + maxn, t, 1);
  }
  int ans = mf.maximumFlow(s, t);
  cout << ans + colorbr.size() << endl;
  return 0;
}
