#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, m;
vector<pair<int, int> > g[100100];
vector<int> level[100100];
int d[100100], p[100100], tip[100100], dp[100100];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0, x, y, z; i < m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    x--;
    y--;
    g[x].push_back(make_pair(y, z));
    g[y].push_back(make_pair(x, z));
  }
  memset(d, -1, sizeof d);
  d[0] = 0;
  level[0].push_back(0);
  tip[0] = 0;
  int sz = 1;
  while (true) {
    for (int i = 0; i < level[sz - 1].size(); i++) {
      int v = level[sz - 1][i];
      for (__typeof(g[v].begin()) it = g[v].begin(); it != g[v].end(); it++) {
        int to = (*it).first;
        if (d[to] == -1) {
          d[to] = d[v] + 1;
          tip[to] = sz;
          level[sz].push_back(to);
        }
      }
    }
    if (level[sz].empty()) break;
    sz++;
  }
  memset(p, -1, sizeof p);
  for (int i = 0; i < n; i++) dp[i] = inf;
  dp[0] = 0;
  for (int i = 0; i < sz - 1; i++) {
    vector<int> &cur = level[i];
    for (__typeof(cur.begin()) it = cur.begin(); it != cur.end(); it++) {
      int v = (*it);
      for (__typeof(g[v].begin()) it2 = g[v].begin(); it2 != g[v].end();
           it2++) {
        int to = (*it2).first;
        if (tip[to] != i + 1) continue;
        int len = (*it2).second;
        len ^= 1;
        if (dp[to] > dp[v] + len) {
          dp[to] = dp[v] + len;
          p[to] = v;
        }
      }
    }
  }
  vector<int> path;
  int last = n - 1;
  while (last != -1) {
    path.push_back(last);
    last = p[last];
  }
  vector<int> a = path;
  reverse(a.begin(), a.end());
  map<pair<int, int>, bool> has;
  for (int i = 1; i < a.size(); i++) {
    has[make_pair(a[i - 1], a[i])] = 1;
  }
  vector<pair<pair<int, int>, int> > ans;
  for (int i = 0; i < n; i++) {
    for (__typeof(g[i].begin()) it = g[i].begin(); it != g[i].end(); it++) {
      int v = i;
      int to = (*it).first;
      int tip = (*it).second;
      if (v > to) continue;
      if (has[make_pair(v, to)] || has[make_pair(to, v)]) {
        if (tip == 0) ans.push_back(make_pair(make_pair(v + 1, to + 1), 1));
      } else {
        if (tip == 1) ans.push_back(make_pair(make_pair(v + 1, to + 1), 0));
      }
    }
  }
  cout << ans.size() << endl;
  for (__typeof(ans.begin()) it = ans.begin(); it != ans.end(); it++) {
    int x = (*it).first.first;
    int y = (*it).first.second;
    int tip = (*it).second;
    printf("%d %d %d\n", x, y, tip);
  }
  return 0;
}
