#include <bits/stdc++.h>
using namespace std;
struct edge {
  int n, k;
};
vector<edge> g[100005];
int dist[100005], shortest[100005];
bool inq[100005];
edge prev1[100005];
int main() {
  int n, m;
  int bc = 0;
  set<pair<int, int> > good;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b, k;
    scanf("%d%d%d", &a, &b, &k);
    g[a].push_back((edge){b, k});
    g[b].push_back((edge){a, k});
    if (k == 0) {
      bc++;
    } else {
      good.insert((pair<int, int>){min(a, b), max(a, b)});
    }
  }
  for (int i = 0; i < n + 1; i++) dist[i] = shortest[i] = INT_MAX;
  queue<int> q;
  q.push(1);
  shortest[1] = 0;
  dist[1] = 0;
  while (q.size() > 0) {
    int c = q.front();
    q.pop();
    for (auto e : g[c]) {
      dist[e.n] = min(dist[e.n], dist[c] + 1);
      if (dist[e.n] > dist[c]) {
        int pr = shortest[e.n];
        shortest[e.n] = min(shortest[e.n], shortest[c] + (e.k == 0 ? 1 : 0));
        if (shortest[e.n] < pr) {
          prev1[e.n] = (edge){c, e.k};
        }
        if (!inq[e.n]) {
          q.push(e.n);
          inq[e.n] = true;
        }
      }
    }
  }
  int b = shortest[n];
  int ans = b + m - dist[n] - (bc - b);
  printf("%d\n", ans);
  int c = n;
  while (c > 1) {
    int pr = prev1[c].n;
    if (prev1[c].k == 0) {
      printf("%d %d 1\n", pr, c);
    } else {
      good.erase((pair<int, int>){min(c, pr), max(c, pr)});
    }
    c = pr;
  }
  for (auto& e : good) {
    printf("%d %d 0\n", e.first, e.second);
  }
}
