#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int a;
  int b;
  int c;
};
int minPath(int start, int end, vector<Edge>& es, vector<bool>& flag) {
  int t;
  int cost = -1;
  vector<bool> minflag;
  for (int i = 0; i < es.size(); ++i) {
    Edge e = es[i];
    if (e.a == start) {
      t = e.b;
    } else if (e.b == start) {
      t = e.a;
    } else {
      continue;
    }
    if (flag[i]) {
      flag[i] = false;
      int re;
      if (t == end)
        re = e.c;
      else
        re = minPath(t, end, es, flag);
      if (re != -1) {
        if (cost == -1) {
          cost = re;
          minflag = flag;
        } else if (cost > re) {
          cost = re;
          minflag = flag;
        }
      }
      flag[i] = true;
    }
  }
  if (cost != -1) {
    for (int i = 0; i < minflag.size(); ++i) flag[i] = minflag[i];
  }
  return cost;
}
void andflag(vector<bool>& a, vector<bool>& b, vector<bool>& dest) {
  for (int i = 0; i < a.size(); ++i) {
    dest[i] = a[i] && b[i];
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<Edge> es(m);
  for (int i = 0; i < m; ++i) {
    Edge e;
    cin >> e.a >> e.b >> e.c;
    es[i] = e;
  }
  vector<bool> flag(m, true);
  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {
      vector<bool> f(m, true);
      f[i] = false;
      minPath(i, j, es, f);
      andflag(flag, f, flag);
    }
  }
  int count = 0;
  for (bool b : flag) {
    if (b) ++count;
  }
  cout << count;
  return 0;
}
