#include <bits/stdc++.h>
using namespace std;
int n, m, cnt, num[10010], low[10010];
int lv[10010], pr[10010], cpr[10010];
vector<pair<int, int> > a[10010];
vector<pair<int, int> > edge;
vector<int> nnode[10010], colorEdge;
int numnode = 0;
bool visited[10010];
void dfs(int u, int p) {
  num[u] = low[u] = ++cnt;
  for (int i = 0; i < a[u].size(); i++) {
    int v = a[u][i].first;
    if (v == p) continue;
    if (num[v]) {
      low[u] = min(low[u], num[v]);
    } else {
      dfs(v, u);
      low[u] = min(low[u], low[v]);
      if (low[v] >= num[v]) {
        nnode[++numnode].push_back(a[u][i].second);
      }
    }
  }
}
void dfs2(int u, int p, int level) {
  lv[u] = level;
  visited[u] = 1;
  for (int i = 0; i < a[u].size(); i++) {
    int v = a[u][i].first;
    if (v == p) continue;
    if (visited[v]) {
      if (u < v) continue;
      edge.push_back(pair<int, int>(u, v));
      colorEdge.push_back(a[u][i].second);
      continue;
    }
    dfs2(v, u, level + 1);
    pr[v] = u;
    cpr[v] = a[u][i].second;
  }
}
void getColor(int u, int v) {
  while (lv[u] > lv[v]) {
    nnode[numnode].push_back(cpr[u]);
    u = pr[u];
  }
  while (lv[v] > lv[u]) {
    nnode[numnode].push_back(cpr[v]);
    v = pr[v];
  }
  while (u != v) {
    nnode[numnode].push_back(cpr[u]);
    nnode[numnode].push_back(cpr[v]);
    u = pr[u], v = pr[v];
  }
}
struct Flows {
  static const int inf = 1e9 + 7;
  int numNode, numEdge;
  vector<int> dist, work, head;
  vector<int> point, flow, capa, next;
  Flows(int n = 0) {
    numNode = n;
    numEdge = 0;
    dist.assign(n + 7, 0);
    head.assign(n + 7, -1);
    work.assign(n + 7, 0);
  }
  int addEdge(int u, int v, int c1, int c2 = 0) {
    int ret = numEdge;
    point.push_back(v);
    capa.push_back(c1);
    flow.push_back(0);
    next.push_back(head[u]);
    head[u] = numEdge++;
    point.push_back(u);
    capa.push_back(c2);
    flow.push_back(0);
    next.push_back(head[v]);
    head[v] = numEdge++;
    return ret;
  }
  bool bfs(int s, int t) {
    queue<int> q;
    for (int i = 1; i <= numNode; i++) dist[i] = -1;
    dist[s] = 0;
    q.push(s);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i = head[u]; i >= 0; i = next[i])
        if (flow[i] < capa[i] && dist[point[i]] < 0) {
          dist[point[i]] = dist[u] + 1;
          q.push(point[i]);
        }
    }
    return dist[t] >= 0;
  }
  int dfs(int s, int t, int f) {
    if (s == t) return f;
    for (int &i = work[s]; i >= 0; i = next[i])
      if (flow[i] < capa[i] && dist[point[i]] == dist[s] + 1) {
        int d = dfs(point[i], t, min(f, capa[i] - flow[i]));
        if (d > 0) {
          flow[i] += d;
          flow[i ^ 1] -= d;
          return d;
        }
      }
    return 0;
  }
  int maxFlow(int s, int t) {
    for (int i = 1; i <= numNode; i++) flow[i] = 0;
    int totFlow = 0;
    while (bfs(s, t)) {
      for (int i = 1; i <= numNode; i++) work[i] = head[i];
      while (true) {
        int d = dfs(s, t, inf);
        if (d == 0) break;
        totFlow += d;
      }
    }
    return totFlow;
  }
  int getFlow(int id) const { return flow[id]; }
};
int maxcolor = 0;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    a[u].push_back(pair<int, int>(v, w));
    a[v].push_back(pair<int, int>(u, w));
    maxcolor = max(w, maxcolor);
  }
  dfs(1, 0);
  dfs2(1, 0, 1);
  for (int i = 0; i < edge.size(); i++) {
    int u = edge[i].first;
    int v = edge[i].second;
    numnode++;
    nnode[numnode].push_back(colorEdge[i]);
    getColor(u, v);
  }
  Flows df(n + m + 2);
  int st = n + m + 1, ed = n + m + 2;
  for (int i = 1; i <= numnode; i++) {
    if (nnode[i].size() == 1)
      df.addEdge(st, i, 1);
    else
      df.addEdge(st, i, nnode[i].size() - 1);
  }
  for (int i = 1; i <= numnode; i++) {
    for (int j = 0; j < nnode[i].size(); j++) {
      df.addEdge(i, numnode + nnode[i][j], 1);
    }
  }
  for (int i = 1; i <= maxcolor; i++) df.addEdge(i + numnode, ed, 1);
  cout << df.maxFlow(st, ed);
}
