#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using vi = vector<int>;
using vll = vector<long long int>;
using vii = vector<vi>;
using pii = pair<int, int>;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  int n, m, tmp1, tmp2, tmp3;
  scanf("%d%d", &n, &m);
  queue<int> DATA;
  vii data(n);
  vector<vector<unsigned int> > min(n);
  for (int(i) = 0; (i) < (n); (i)++) {
    data[i].resize(n, 0);
    min[i].resize(n, -1);
  }
  for (int(i) = 0; (i) < (n); (i)++) {
    scanf("%d%d%d", &tmp1, &tmp2, &tmp3);
    if (tmp1 > tmp2) {
      data[tmp2][tmp1] = tmp3;
      if (tmp1 == tmp2 + 1) {
        min[tmp2][tmp1] = tmp3;
      } else {
        DATA.push(tmp2);
        DATA.push(tmp1);
        DATA.push(tmp3);
      }
    } else {
      data[tmp1][tmp2] = tmp3;
      if (tmp2 == tmp1 + 1) {
        min[tmp1][tmp2] = tmp3;
      } else {
        DATA.push(tmp1);
        DATA.push(tmp2);
        DATA.push(tmp3);
      }
    }
  }
  int k;
  for (int dif = 2; dif < n; dif++) {
    for (int i = 0; i < n; i++) {
      int u = ((dif > n - dif) ? n - dif : dif);
      for (int j = 1; j < u; j++) {
        if (data[i + j][i + dif] != 0) {
          k = min[i][i + j] + data[i + j][i + dif];
          if (k < min[i][i + dif]) {
            min[i][i + dif] = k;
          }
        }
      }
    }
  }
  unsigned int a, b;
  int c, ans = 0;
  bool flag;
  while (!DATA.empty()) {
    a = DATA.front();
    DATA.pop();
    b = DATA.front();
    DATA.pop();
    c = DATA.front();
    DATA.pop();
    flag = true;
    for (int i = 0; i < a; i++) {
      if (c + min[a][b] == min[i][b]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans++;
    }
  }
  cout << ans << "\n";
  return 0;
}
