#include <bits/stdc++.h>
using namespace std;
const int N = 3e4 + 15;
const int inf = 1e9;
struct Edge {
  int v, cap, rev;
  Edge() {}
  Edge(int v, int cap, int rev) : v(v), cap(cap), rev(rev) {}
};
vector<Edge> vt[N];
void addEdge(int s, int e, int c) {
  vt[s].push_back(Edge(e, c, (int)vt[e].size()));
  vt[e].push_back(Edge(s, 0, (int)vt[s].size() - 1));
  assert(vt[s].back().v == e);
  assert(vt[e].back().v == s);
}
int level[N];
int work[N];
int source, sink;
bool bfs() {
  memset(level, -1, sizeof(level));
  queue<int> q;
  q.push(source);
  level[source] = 0;
  int here, there, i;
  Edge x;
  while (!q.empty()) {
    here = q.front();
    q.pop();
    for (i = 0; i < vt[here].size(); ++i) {
      x = vt[here][i];
      there = x.v;
      int cap = x.cap;
      if (level[there] == -1 && cap > 0) {
        level[there] = level[here] + 1;
        q.push(there);
      }
    }
  }
  return level[sink] != -1;
}
int dfs(int here, int mcap) {
  if (here == sink) return mcap;
  for (int &i = work[here]; i < vt[here].size(); ++i) {
    Edge x = vt[here][i];
    int there = x.v;
    int cap = x.cap;
    if (level[there] == level[here] + 1 && cap > 0) {
      int flow = dfs(there, min(mcap, cap));
      if (flow > 0) {
        vt[here][i].cap -= flow;
        vt[there][x.rev].cap += flow;
        return flow;
      }
    }
  }
  return 0;
}
int maxFlow() {
  int ret = 0;
  while (bfs()) {
    memset(work, 0, sizeof(work));
    while (1) {
      int flow = dfs(source, inf);
      if (!flow) break;
      ret += flow;
    }
  }
  return ret;
}
vector<int> adj[N];
int a[N], b[N], c[N], par[N];
vector<vector<int> > colorList;
int depth[N];
void dfs2(int node, int p) {
  for (int i = 0; i < adj[node].size(); ++i) {
    int id = adj[node][i];
    int ch = a[id] ^ b[id] ^ node;
    if (ch == p) {
      continue;
    }
    if (depth[ch] == 0) {
      depth[ch] = depth[node] + 1;
      par[ch] = id;
      dfs2(ch, node);
    } else if (depth[ch] < depth[node]) {
      colorList.push_back(vector<int>());
      colorList.back().push_back(id);
      int u = node;
      while (u != ch) {
        int gid = par[u];
        par[u] = -1;
        colorList.back().push_back(gid);
        u ^= a[gid] ^ b[gid];
      }
    }
  }
}
int cc[N];
vector<int> graph[N];
int maxMatching(int n, int m) {
  int ret = 0;
  return ret;
}
void solve() {
  memset(par, -1, sizeof(par));
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d %d", &a[i], &b[i], &c[i]);
    adj[a[i]].push_back(i);
    adj[b[i]].push_back(i);
  }
  depth[1] = 12;
  dfs2(1, 0);
  for (int i = 1; i <= n; ++i) {
    if (par[i] != -1) {
      ++cc[c[par[i]]];
    }
  }
  sink = n + m + 1;
  int ret = 0;
  for (int i = 1; i <= m; ++i) {
    if (cc[i] == 0) {
      addEdge(i + n, sink, 1);
    } else {
      ++ret;
    }
  }
  source = 0;
  for (int i = 0; i < colorList.size(); ++i) {
    int id = i + 1, rem = colorList[i].size();
    addEdge(source, id, rem - 1);
    for (int j = 0; j < colorList[i].size(); ++j) {
      int color = c[colorList[i][j]];
      if (cc[color] == 0) {
        addEdge(id, color + n, 1);
      }
    }
  }
  ret += maxFlow();
  printf("%d\n", ret);
}
int main() { solve(); }
