#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, m, x, y, c;
vector<pair<long long, long long> > A[111];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ;
  cin >> n >> m;
  for (int i = 0; i < (int)(m); ++i) {
    cin >> x >> y >> c;
    A[x].push_back({y, c});
    A[y].push_back({x, c});
  }
  cout << m - (n - 1) << endl;
  return 0;
}
