#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9 + 7;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
__attribute__((constructor)) void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> dis(n, vector<int>(n, inf));
  vector<int> to[n];
  map<pair<int, int>, int> mii;
  for (int i = 0; i < (m); i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    mii[{a, b}] = c;
    mii[{b, a}] = c;
    dis[b][a] = c;
    dis[a][b] = c;
  }
  for (int k = 0; k < (n); k++) {
    for (int i = 0; i < (n); i++) {
      for (int j = 0; j < (n); j++) {
        chmin(dis[i][j], dis[i][k] + dis[k][j]);
      }
    }
  }
  int cnt = 0;
  for (auto u : mii) {
    cout << u.first.first << " " << u.first.second << " " << u.second << " "
         << dis[u.first.first][u.first.second] << endl;
    if (dis[u.first.first][u.first.second] < u.second) cnt++;
  }
  cout << cnt / 2 << endl;
  return 0;
}
