#include <bits/stdc++.h>
using namespace std;
template <typename T>
void DEBUG(T e) {
  if (true == false) return;
  std::cout << e << " ";
}
template <typename T>
void DEBUG(const std::vector<T>& v) {
  if (true == false) return;
  for (const auto& e : v) {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
template <typename T>
void DEBUG(const std::vector<std::vector<T> >& vv) {
  if (true == false) return;
  for (const auto& v : vv) {
    DEBUG(v);
  }
}
template <class T, class... Ts>
void DEBUG(T d, Ts... e) {
  if (true == false) return;
  DEBUG(d);
  DEBUG(e...);
}
template <class T>
void corner(bool flg, T hoge) {
  if (flg) {
    cout << hoge << endl;
    abort();
  }
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b) {
  return a > b && (a = b, true);
}
template <typename T>
using Matrix = vector<vector<T> >;
template <typename T>
void warshall_floyd(Matrix<T>& g) {
  for (long long k = 0; k < g.size(); k++) {
    for (long long i = 0; i < g.size(); i++) {
      for (long long j = 0; j < g.size(); j++) {
        if (g[i][k] == 1223372036854775807LL ||
            g[k][j] == 1223372036854775807LL)
          continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}
void solve(void) {
  long long N, M;
  cin >> N >> M;
  Matrix<long long> MAT(N, vector<long long>(N, 1223372036854775807LL));
  for (long long i = 0; i < M; i++) {
    long long A, B, C;
    cin >> A >> B >> C;
    A--;
    B--;
    MAT[A][B] = C;
    MAT[B][A] = C;
  }
  auto cpMAT = MAT;
  for (long long i = 0; i < N; i++) {
    MAT[i][i] = 0;
  }
  warshall_floyd(MAT);
  long long cnt = 0;
  for (long long i = 0; i < N; i++) {
    for (long long j = 0; j < M; j++) {
      if (cpMAT[i][j] != 1223372036854775807LL) {
        if (cpMAT[i][j] != MAT[i][j]) cnt++;
      }
    }
  }
  cout << cnt / 2 << endl;
  warshall_floyd(MAT);
  return;
}
int32_t main(int32_t argc, const char* argv[]) {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  return 0;
}
