#include <bits/stdc++.h>
using namespace std;
bool check(int cost, vector<int> &a, vector<int> &b, vector<int> &c, int m,
           int end1, int end2);
int main() {
  int n, m, in;
  cin >> n >> m;
  vector<int> a, b, c;
  for (int i = 0; i < m; i++) {
    cin >> in;
    a.push_back(in - 1);
    cin >> in;
    b.push_back(in - 1);
    cin >> in;
    c.push_back(in);
  }
  int answer = 0;
  for (int i = 0; i < m; i++) {
    if (check(c[i] - 1, a, b, c, m, a[i], b[i]) == true) {
      answer = answer + 1;
    }
  }
  cout << answer << endl;
  return 0;
}
bool check(int cost, vector<int> &a, vector<int> &b, vector<int> &c, int m,
           int end1, int end2) {
  if (cost < 0) {
    return false;
  }
  if (end1 == end2) {
    return true;
  }
  for (int k = 0; k < m; k++) {
    if (end1 == a[k]) {
      if (check(cost - c[k], a, b, c, m, b[k], end2) == true) {
        return true;
      }
    }
    if (end1 == b[k]) {
      if (check(cost - c[k], a, b, c, m, a[k], end2) == true) {
        return true;
      }
    }
    if (end2 == a[k]) {
      if (check(cost - c[k], a, b, c, m, b[k], end1) == true) {
        return true;
      }
    }
    if (end2 == b[k]) {
      if (check(cost - c[k], a, b, c, m, a[k], end1) == true) {
        return true;
      }
    }
  }
  return false;
}
