#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const long long MOD = (long long)1000000007;
const long long INF2 = (long long)100000000000000000;
template <typename T>
using Matrix = vector<vector<T> >;
template <typename T>
void warshall_floyd(Matrix<T> &g, T INF) {
  for (int k = 0; k < g.size(); k++) {
    for (int i = 0; i < g.size(); i++) {
      for (int j = 0; j < g.size(); j++) {
        if (g[i][k] == INF || g[k][j] == INF) continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}
int main() {
  int V, E;
  cin >> V >> E;
  Matrix<int> mat(V, vector<int>(V, INT_MAX));
  for (int i = 0; i < V; i++) mat[i][i] = 0;
  vector<int> x(1000);
  vector<int> y(1000);
  vector<int> z(1000);
  for (int i = 0; i < E; i++) {
    cin >> x[i] >> y[i] >> z[i];
    x[i]--;
    y[i]--;
    mat[x[i]][y[i]] = z[i];
  }
  warshall_floyd(mat, INT_MAX);
  int ans = E;
  for (int i = 0; i < E; i++) {
    bool shortest = false;
    if (mat[x[i]][y[i]] == z[i]) shortest = true;
    if (shortest == true) {
      ans--;
    }
  }
  cout << ans << endl;
}
