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;
struct MaxFlowDinic {
  struct Edge {
    int t, rev, cap, f;
    Edge(int t, int rev, int cap) {
      this->t = t;
      this->rev = rev;
      this->cap = cap;
      f = 0;
    }
  };
  vector<vector<Edge> > createGraph(int nodes) {
    vector<vector<Edge> > graph(nodes);
    return graph;
  }
  void addEdge(vector<vector<Edge> > &graph, int s, int t, int cap) {
    graph[s].push_back(Edge(t, graph[t].size(), cap));
    graph[t].push_back(Edge(s, graph[s].size() - 1, 0));
  }
  bool dinicBfs(vector<vector<Edge> > &graph, int src, int dest,
                vector<int> &dist) {
    for (int i = 0; i < int(dist.size()); i++) dist[i] = -1;
    dist[src] = 0;
    vector<int> Q(graph.size());
    int sizeQ = 0;
    Q[sizeQ++] = src;
    for (int round = 0; round < sizeQ; round++) {
      int u = Q[round];
      for (int i = 0; i < int(graph[u].size()); i++) {
        if (dist[graph[u][i].t] < 0 && graph[u][i].f < graph[u][i].cap) {
          dist[graph[u][i].t] = dist[u] + 1;
          Q[sizeQ++] = graph[u][i].t;
        }
      }
    }
    return dist[dest] >= 0;
  }
  int dinicDfs(vector<vector<Edge> > &graph, vector<int> &ptr,
               vector<int> &dist, int dest, int u, int f) {
    if (u == dest) return f;
    for (; ptr[u] < int(graph[u].size()); ++ptr[u]) {
      Edge &e = graph[u][ptr[u]];
      if (dist[e.t] == dist[u] + 1 && e.f < e.cap) {
        int df = dinicDfs(graph, ptr, dist, dest, e.t, min(f, e.cap - e.f));
        if (df > 0) {
          e.f += df;
          graph[e.t][e.rev].f -= df;
          return df;
        }
      }
    }
    return 0;
  }
  int maxFlow(vector<vector<Edge> > &graph, int src, int dest) {
    int flow = 0;
    vector<int> dist(graph.size());
    while (dinicBfs(graph, src, dest, dist)) {
      vector<int> ptr(graph.size());
      while (true) {
        int df = dinicDfs(graph, ptr, dist, dest, src, 2000000000);
        if (df == 0) break;
        flow += df;
      }
    }
    return flow;
  }
};
struct Edge {
  int from, to, color;
  Edge() { from = to = color = -1; }
  Edge(int from, int to, int color) {
    this->from = from;
    this->to = to;
    this->color = color;
  }
};
vector<Edge> path;
vector<int> pathInd;
bool vis[10005];
vector<vector<int> > components;
vector<pair<int, int> > g[100005];
vector<int> gg[100005];
vector<int> edgeColors;
void dfs(int node, int prv, int color) {
  if (vis[node]) {
    int ind = path.size() - 1;
    vector<int> component;
    while (path[ind].from != node) {
      component.push_back(path[ind].color);
      edgeColors[pathInd[ind]] = -1;
      --ind;
    }
    component.push_back(path[ind].color);
    edgeColors[pathInd[ind]] = -1;
    components.push_back(component);
    return;
  }
  vis[node] = true;
  for (int i = 0; i < int(g[node].size()); i++) {
    int child = g[node][i].first;
    int col = g[node][i].second;
    if (child == prv) continue;
    if (edgeColors[gg[node][i]] == -1) continue;
    pathInd.push_back(gg[node][i]);
    path.push_back(Edge(node, child, col));
    dfs(child, node, col);
    pathInd.pop_back();
    path.pop_back();
  }
}
map<int, int> colors;
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    --u;
    --v;
    g[u].push_back(make_pair(v, c));
    g[v].push_back(make_pair(u, c));
    gg[u].push_back(i);
    gg[v].push_back(i);
    if (colors.find(c) == colors.end()) {
      int ind = colors.size();
      colors[c] = ind;
    }
    edgeColors.push_back(c);
  }
  dfs(0, -1, -1);
  MaxFlowDinic p;
  vector<vector<MaxFlowDinic::Edge> > pg =
      p.createGraph(2 + components.size() + colors.size());
  int src = components.size() + colors.size();
  int dst = components.size() + colors.size() + 1;
  for (int i = 0; i < int(components.size()); i++) {
    p.addEdge(pg, src, i, components[i].size() - 1);
    sort(components[i].begin(), components[i].end());
    for (int j = 0; j < int(components[i].size()); j++) {
      if (j == 0 || components[i][j] != components[i][j - 1])
        p.addEdge(pg, i, colors[components[i][j]] + components.size(), 1);
    }
  }
  for (map<int, int>::iterator it = colors.begin(); it != colors.end(); it++) {
    p.addEdge(pg, it->second + components.size(), dst, 1);
  }
  for (int i = 0; i < m; i++)
    if (edgeColors[i] != -1)
      p.addEdge(pg, src, colors[edgeColors[i]] + components.size(), 1);
  cout << p.maxFlow(pg, src, dst) << endl;
  return 0;
}
