#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
vector<pair<int, int> > a[N];
int vis[N], pr[N], pt[N], q[N], d[N], br[N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int gr = 0;
  for (int i = 0; i < m; ++i) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    a[x].push_back(make_pair(y, z));
    a[y].push_back(make_pair(x, z));
    if (z == 1) ++gr;
  }
  for (int u = 1; u <= n; ++u) {
    br[u] = 0;
    vis[u] = 0;
    br[u] = n;
  }
  int b = 0, e = 0;
  q[0] = 1;
  vis[1] = 1;
  d[1] = 0;
  br[1] = 0;
  while (b <= e) {
    int u = q[b];
    int sz = a[u].size();
    for (int i = 0; i < sz; ++i) {
      int v = a[u][i].first;
      int w = (a[u][i].second == 0);
      if (!vis[v]) {
        vis[v] = 1;
        d[v] = d[u] + 1;
        ++e;
        q[e] = v;
      }
      if (d[v] == d[u] + 1 && br[u] + w < br[v]) {
        br[v] = br[u] + (a[u][i].second == 0);
        pr[v] = u;
        pt[v] = i;
      }
    }
    ++b;
  }
  int c = br[n] + gr - (d[n] - br[n]);
  printf("%d\n", c);
  int v = n;
  while (v != 1) {
    int u = pr[v];
    int &w = a[u][pt[v]].second;
    if (w == 0)
      printf("%d %d %d\n", v, u, 1);
    else {
      w = 2;
      int sz = a[v].size();
      for (int i = 0; i < sz; ++i) {
        if (a[v][i].first == u) {
          a[v][i].second = 2;
          break;
        }
      }
    }
    v = u;
  }
  for (int u = 1; u <= n; ++u) {
    int sz = a[u].size();
    for (int i = 0; i < sz; ++i) {
      int v = a[u][i].first;
      int &w = a[u][i].second;
      if (u < v && w == 1) printf("%d %d %d\n", u, v, 0);
      w = 0;
    }
  }
  return 0;
}
