#include <bits/stdc++.h>
using namespace std;
int n, m, d[100005], n_affected[100005];
pair<int, int> parent[100005];
set<pair<int, int> > G[100005];
void dijkstra() {
  set<pair<int, int> > q;
  for (int u = 1; u <= n; u++) {
    parent[u] = pair<int, int>(-1, -1);
    d[u] = 1000000000;
    n_affected[u] = 0;
  }
  d[1] = 0;
  parent[1] = pair<int, int>(1, 0);
  q.insert(pair<int, int>(0, 1));
  while (!q.empty()) {
    int u = q.begin()->second;
    q.erase(q.begin());
    for (set<pair<int, int> >::iterator it = G[u].begin(); it != G[u].end();
         it++) {
      int v = it->first;
      int w = it->second;
      if (d[v] > d[u] + 1) {
        if (d[v] != 1000000000) q.erase(q.find(pair<int, int>(d[v], v)));
        d[v] = d[u] + 1;
        parent[v] = pair<int, int>(u, 1 - w);
        n_affected[v] = n_affected[u] + w;
        q.insert(pair<int, int>(d[v], v));
      } else if (d[v] == d[u] + 1) {
        if (n_affected[u] + w < n_affected[v]) {
          n_affected[v] = n_affected[u] + w;
          parent[v] = pair<int, int>(u, 1 - w);
        }
      }
    }
  }
}
int main() {
  set<pair<int, int> > blow_up, fixed;
  set<pair<int, int> >::iterator it;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    if (u > v) swap(u, v);
    G[u].insert(pair<int, int>(v, 1 - w));
    G[v].insert(pair<int, int>(u, 1 - w));
    if (w == 1) blow_up.insert(pair<int, int>(u, v));
  }
  dijkstra();
  for (int i = n; i != 1; i = parent[i].first) {
    int u = i, v = parent[i].first, w = parent[i].second;
    if (u > v) swap(u, v);
    if (w == 0) {
      fixed.insert(pair<int, int>(u, v));
    } else {
      blow_up.erase(pair<int, int>(u, v));
    }
  }
  printf("%d\n", int(blow_up.size() + fixed.size()));
  for (it = blow_up.begin(); it != blow_up.end(); it++)
    printf("%d %d 0\n", it->first, it->second);
  for (it = fixed.begin(); it != fixed.end(); it++)
    printf("%d %d 1\n", it->first, it->second);
  return 0;
}
