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 INF = 1e9;
class TFlowFinder {
 public:
  TFlowFinder(const vector<int>& levelSizes, const pair<int, int>& start,
              const pair<int, int>& finish)
      : LevelSizes(levelSizes) {
    N = 0;
    for (int sz : levelSizes) {
      N += sz;
    }
    Head.assign(N, -1);
    for (int i = 1; i < (int)LevelSizes.size(); ++i) {
      LevelSizes[i] += LevelSizes[i - 1];
    }
    Start = GetVertex(start);
    Finish = GetVertex(finish);
  }
  void AddEdge(const pair<int, int>& v1, const pair<int, int>& v2, int cap) {
    AddEdge(GetVertex(v1), GetVertex(v2), cap);
  }
  int GetFlow() {
    int result = 0;
    while (Bfs()) {
      Ptr.resize(N);
      for (int i = 0; i < N; ++i) {
        Ptr[i] = Head[i];
      }
      while (true) {
        int curDfsFlow = Dfs(Start, INF);
        if (curDfsFlow == 0) {
          break;
        } else {
          result += curDfsFlow;
        }
      }
    }
    return result;
  }

 private:
  struct TEdge {
    int From;
    int To;
    int Flow;
    int Cap;
    int Next;
  };
  int N;
  vector<int> LevelSizes;
  int Start;
  int Finish;
  vector<TEdge> Edges;
  vector<int> Head;
  vector<int> Ptr;
  vector<int> Dist;
  void AddEdge(int v1, int v2, int cap) {
    Edges.push_back(TEdge{v1, v2, 0, cap, Head[v1]});
    Head[v1] = (int)Edges.size() - 1;
    Edges.push_back(TEdge{v2, v1, 0, 0, Head[v2]});
    Head[v2] = (int)Edges.size() - 1;
  }
  inline int GetVertex(const pair<int, int>& v) {
    return (v.first == 0 ? 0 : LevelSizes[v.first - 1]) + v.second;
  }
  bool Bfs() {
    Dist.assign(N, INF);
    Dist[Start] = 0;
    queue<int> q;
    q.push(Start);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (int i = Head[v]; i != -1; i = Edges[i].Next) {
        const TEdge& e = Edges[i];
        if (Dist[e.To] == INF && e.Flow < e.Cap) {
          Dist[e.To] = Dist[v] + 1;
          q.push(e.To);
        }
      }
    }
    return Dist[Finish] < INF;
  }
  int Dfs(int v, int flow) {
    if (v == Finish) {
      return flow;
    }
    for (int& i = Ptr[v]; i != -1; i = Edges[i].Next) {
      const TEdge& e = Edges[i];
      if (Dist[e.To] == Dist[v] + 1 && e.Flow < e.Cap) {
        int resultFlow = Dfs(e.To, min(flow, e.Cap - e.Flow));
        if (resultFlow > 0) {
          RelaxAlongEdge(i, resultFlow);
          return resultFlow;
        }
      }
    }
    return 0;
  }
  void RelaxAlongEdge(int id, int flow) {
    Edges[id].Flow += flow;
    Edges[id ^ 1].Flow -= flow;
  }
};
struct TEdge {
  int From;
  int To;
  int Id;
  int Next;
};
int n;
vector<int> head;
vector<TEdge> edges;
vector<int> color;
vector<bool> inCycle;
void AddEdge(int v1, int v2, int id, int c) {
  color.push_back(c);
  edges.push_back(TEdge{v1, v2, id, head[v1]});
  head[v1] = (int)edges.size() - 1;
  edges.push_back(TEdge{v2, v1, id, head[v2]});
  head[v2] = (int)edges.size() - 1;
}
vector<vector<int>> cycles;
vector<int> used;
vector<int> pr;
void Dfs(int v) {
  used[v] = 1;
  for (int i = head[v]; i != -1; i = edges[i].Next) {
    const TEdge& e = edges[i];
    if (pr[v] != -1 && edges[pr[v]].Id == e.Id) {
      continue;
    }
    if (used[e.To] == 0) {
      pr[e.To] = i;
      Dfs(e.To);
    } else if (used[e.To] == 1) {
      cycles.push_back(vector<int>());
      int u = v;
      cycles.back().push_back(color[e.Id]);
      inCycle[e.Id] = true;
      while (u != e.To) {
        cycles.back().push_back(color[edges[pr[u]].Id]);
        inCycle[edges[pr[u]].Id] = true;
        u = edges[pr[u]].From;
      }
    }
  }
  used[v] = 2;
}
int main() {
  int m;
  scanf("%d%d", &n, &m);
  head.assign(n, -1);
  edges.reserve(2 * m);
  for (int i = 0; i < m; ++i) {
    int v1, v2, c;
    scanf("%d%d%d", &v1, &v2, &c);
    --v1;
    --v2;
    --c;
    AddEdge(v1, v2, i, c);
  }
  inCycle.assign(m, false);
  used.assign(n, 0);
  pr.assign(n, -1);
  Dfs(0);
  TFlowFinder ff({1, (int)cycles.size(), m, 1}, make_pair(0, 0),
                 make_pair(3, 0));
  for (int cycleId = 0; cycleId < (int)cycles.size(); ++cycleId) {
    ff.AddEdge(make_pair(0, 0), make_pair(1, cycleId),
               (int)cycles[cycleId].size() - 1);
    for (int c : cycles[cycleId]) {
      ff.AddEdge(make_pair(1, cycleId), make_pair(2, c), 1);
    }
  }
  for (int i = 0; i < m; ++i) {
    if (!inCycle[i]) {
      const int c = color[i];
      ff.AddEdge(make_pair(0, 0), make_pair(2, c), 1);
    }
  }
  for (int c = 0; c < m; ++c) {
    ff.AddEdge(make_pair(2, c), make_pair(3, 0), 1);
  }
  printf("%d\n", ff.GetFlow());
  return 0;
}
