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>
const int inf = 1e9;
const int oo = 1e9;
const long long infll = (1LL << 60) - 1;
namespace network_flow {
const int max0 = 100000, max1 = 100000;
struct edge {
  int id, g, nxt;
  edge() {}
  edge(int id, int g, int nxt) : id(id), g(g), nxt(nxt) {}
};
int st[max0 + 5], en = 0;
edge e[max1 + 5];
inline void add_edge(int x, int y, int z) {
  e[en] = edge(y, z, st[x]);
  st[x] = en++;
}
inline void add_biedge(int x, int y, int z) {
  add_edge(x, y, z);
  add_edge(y, x, 0);
}
int S, T, N;
int dis[max0 + 5];
inline bool bfs() {
  static int q[max0 + 5];
  static bool vis[max0 + 5];
  int head = 0, rear = 0;
  memset(dis, -1, sizeof(dis[0]) * N);
  memset(vis, 0, sizeof(vis[0]) * N);
  vis[q[rear++] = S] = 1;
  dis[S] = 0;
  while (head != rear) {
    int x = q[head++];
    for (int i = st[x]; i != -1; i = e[i].nxt) {
      if (!e[i].g) continue;
      int y = e[i].id;
      if (!vis[y]) {
        dis[y] = dis[x] + 1;
        if (y == T) return 1;
        q[rear++] = y;
        vis[y] = 1;
      }
    }
  }
  return 0;
}
int cur[max0 + 5];
inline int dfs(int x, int flow) {
  if (x == T) return flow;
  int res = flow;
  for (int &i = cur[x]; i != -1; i = e[i].nxt) {
    if (!e[i].g) continue;
    int y = e[i].id;
    if (dis[y] == dis[x] + 1) {
      int F = dfs(y, std::min(e[i].g, res));
      res -= F;
      e[i].g -= F;
      e[i ^ 1].g += F;
      if (res <= 0) return flow;
    }
  }
  dis[x] = -1;
  return flow - res;
}
int work() {
  if (S == T) return oo;
  int ret = 0;
  for (; bfs();) {
    for (int i = 0; i < N; i++) cur[i] = st[i];
    ret += dfs(S, oo);
  }
  return ret;
}
}  // namespace network_flow
using network_flow::add_biedge;
using network_flow::add_edge;
using network_flow::en;
using network_flow::N;
using network_flow::S;
using network_flow::st;
using network_flow::T;
using network_flow::work;
const int maxn = 10100, maxm = (maxn << 1);
int n, m;
std::vector<std::pair<int, int> > adj[maxn + 5];
int dfn[maxn + 5], dfs_cnt;
int belong[maxm + 5];
int pre[maxn + 5];
int dfs_fa[maxn + 5];
int lim[maxn + 5];
void dfs(int x) {
  dfn[x] = dfs_cnt++;
  for (int i = 0; i < adj[x].size(); i++) {
    int y = adj[x][i].first, id = adj[x][i].second;
    if (id == dfs_fa[x]) continue;
    if (dfn[y] == -1) {
      dfs_fa[y] = id;
      pre[y] = x;
      dfs(y);
    } else if (dfn[y] < dfn[x]) {
      int u = x;
      lim[N] = 0;
      belong[id] = N;
      do {
        ++lim[N];
        belong[dfs_fa[u]] = N;
        u = pre[u];
      } while (u != y);
      N++;
    }
  }
}
int col[maxm + 5];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    u--;
    v--;
    w--;
    belong[i] = 2;
    col[i] = w;
    adj[u].push_back(std::make_pair(v, i));
    adj[v].push_back(std::make_pair(u, i));
  }
  pre[0] = dfs_fa[0] = -1;
  dfs_cnt = 0;
  S = 0, T = 1;
  lim[2] = oo;
  N = 3;
  memset(dfn, -1, sizeof(dfn));
  dfs(0);
  memset(st, -1, sizeof(st));
  for (int i = 2; i < N; i++) add_biedge(i, T, lim[i]);
  for (int i = 0; i < m; i++) add_biedge(S, N + i, 1);
  for (int i = 0; i < m; i++) add_biedge(N + col[i], belong[i], 1);
  N += m;
  printf("%d\n", work());
  return 0;
}
