#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > G;
vector<vector<int> > d;
int V;
void washall() {
  for (int i = 1; i <= V; i++) {
    for (int j = 1; j <= V; j++) {
      for (int k = 1; k <= V; k++) {
        if (d[i][j] > d[i][k] + G[k][j]) {
          d[i][j] = d[i][k] + G[k][j];
        }
      }
    }
  }
}
void print_d() {
  if (!0) return;
  for (int i = int(1); i < int(V + 1); i++) {
    for (int j = int(1); j < int(V + 1); j++) {
      cout << d[i][j] << " ";
    }
    cout << endl;
  }
}
bool check(int i, int j) {
  for (int s = int(1); s < int(V + 1); s++) {
    for (int t = int(1); t < int(V + 1); t++) {
      if (d[s][i] + G[i][j] + d[j][t] == d[s][t] || d[i][j] == G[i][j]) {
        return true;
      }
    }
  }
  return false;
}
int main() {
  int N, M;
  cin >> N >> M;
  V = N;
  G = vector<vector<int> >(N + 1, vector<int>(N + 1, (1 << 20)));
  d = vector<vector<int> >(N + 1, vector<int>(N + 1, (1 << 20)));
  for (int i = int(0); i < int(M); i++) {
    int a, b, c;
    cin >> a >> b >> c;
    G[a][b] = c;
    G[b][a] = c;
    d[a][b] = c;
    d[b][a] = c;
  }
  washall();
  int need = 0;
  for (int i = int(1); i < int(V + 1); i++) {
    for (int j = int(1); j < int(V + 1); j++) {
      if (i == j) continue;
      if (check(i, j)) {
        need++;
      }
    }
  }
  print_d();
  need /= 2;
  cout << M - need << endl;
  return 0;
}
