#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int d0[100][100], d[100][100];
  cin >> n >> m;
  for (int j = 0; j < 100; j++) {
    for (int k = 0; k < 100; k++) {
      d[j][k] = 1000 * 1000 * 1000;
      d0[j][k] = -1;
    }
    d[j][j] = 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    d0[a - 1][b - 1] = d[a - 1][b - 1] = c;
    d[b - 1][a - 1] = c;
  }
  for (int j = 0; j < n; j++) {
    for (int k = 0; k < n; k++) {
      for (int l = 0; l < n; l++) {
        d[k][l] = min(d[k][l], d[k][j] + d[j][l]);
      }
    }
  }
  int r = 0;
  for (int j = 0; j < n; j++) {
    for (int k = 0; k < n; k++) {
      cout << j << k << d[j][k] << endl;
      if (d0[j][k] != -1 && d[j][k] < d0[j][k]) {
        r++;
      }
    }
  }
  cout << r << endl;
  return 0;
}
