#include <bits/stdc++.h>
using namespace std;
const long double Pi = 3.14159265359;
const long long MOD = (long long)1e9 + 7;
const long long MAXN = (long long)1e5 + 10;
const long long INF = (long long)9223372036854775;
const long double EPS = (long double)1e-8;
vector<pair<long long, long long> > g[MAXN];
long long vis[MAXN];
long long dp[MAXN];
long long dpfi[MAXN];
long long dpfit[MAXN];
vector<long long> now;
vector<long long> fut;
map<pair<long long, long long>, long long> edge;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  fill(dp, dp + MAXN, INF);
  long long n, m, u, v, z;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> z;
    if (u > v) swap(u, v);
    g[u].push_back(make_pair(v, z));
    g[v].push_back(make_pair(u, z));
    edge[make_pair(u, v)] = z;
  }
  dp[n] = 0;
  now.push_back(n);
  vis[n] = 1;
  while (vis[1] == 0) {
    for (auto par : now) {
      for (auto node : g[par]) {
        if (vis[node.first] == 1) continue;
        if (dp[node.first] >= dp[par] + (1 - node.second)) {
          dpfi[node.first] = par;
          dpfit[node.first] = node.second;
          dp[node.first] = dp[par] + (1 - node.second);
        }
        fut.push_back(node.first);
      }
    }
    for (auto node : fut) vis[node] = 1;
    now.clear();
    for (auto node : fut) now.push_back(node);
    fut.clear();
  }
  long long nod = 1;
  while (nod != n) {
    if (dpfit[nod] == 1)
      edge[make_pair(min(nod, dpfi[nod]), max(nod, dpfi[nod]))] = 0;
    nod = dpfi[nod];
  }
  long long out = dp[1];
  for (map<pair<long long, long long>, long long>::const_iterator it =
           edge.begin();
       it != edge.end(); it++)
    out += (it->second);
  cout << out << endl;
  nod = 1;
  while (nod != n) {
    if (dpfit[nod] == 0)
      cout << min(nod, dpfi[nod]) << " " << max(nod, dpfi[nod]) << " 1" << endl;
    nod = dpfi[nod];
  }
  for (map<pair<long long, long long>, long long>::const_iterator it =
           edge.begin();
       it != edge.end(); it++) {
    if (it->second == 1)
      cout << (it->first).first << " " << (it->first).second << " 0" << endl;
  }
  return 0;
}
