#include <bits/stdc++.h>
using namespace std;
int n, m;
int x[100005], y[100005], z[100005];
int tot;
typedef struct {
  int a, b;
  int f;
} AA;
AA ans[100005];
typedef struct {
  int to;
  int f;
  int indexb;
} PP;
vector<PP> bian[100005];
int vis[100005];
int Step[100005];
int Cnt[100005];
struct QQ {
  friend bool operator<(QQ n1, QQ n2) {
    if (n1.step == n2.step) {
      return n1.cnt > n2.cnt;
    } else {
      return n1.step > n2.step;
    }
  }
  int index;
  int cnt;
  int indexn;
  int pre;
  int step;
};
void out(QQ te);
void ini() {
  int i;
  tot = 0;
  memset(vis, 0, sizeof(vis));
  PP te;
  for (i = 1; i <= n; i++) {
    bian[i].clear();
    Step[i] = 100000000;
    Cnt[i] = 100000000;
  }
  Step[1] = 0;
  Cnt[1] = 0;
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d", &x[i], &y[i], &z[i]);
    te.to = y[i];
    te.f = z[i];
    te.indexb = i;
    bian[x[i]].push_back(te);
    te.to = x[i];
    bian[y[i]].push_back(te);
  }
}
typedef struct {
  int in;
  int pre;
} NN;
NN node[100005 * 10];
int totnode;
void bfs() {
  priority_queue<QQ> q;
  QQ te, nt;
  te.index = 1;
  te.cnt = 0;
  te.step = 0;
  totnode = 0;
  te.indexn = -1;
  te.pre = -1;
  q.push(te);
  int st;
  PP yy;
  vector<PP>::iterator it;
  while (q.size() >= 1) {
    te = q.top();
    q.pop();
    if (te.index == n) {
      out(te);
      return;
    }
    if (vis[te.index] == 1) continue;
    vis[te.index] = 1;
    st = te.index;
    for (it = bian[st].begin(); it != bian[st].end(); it++) {
      yy = *it;
      if (vis[yy.to] == 1) continue;
      nt.index = yy.to;
      nt.cnt = te.cnt;
      nt.pre = te.index;
      nt.step = te.step + 1;
      if (yy.f == 0) {
        nt.cnt++;
      }
      if (nt.step > Step[nt.index]) continue;
      if (nt.step == Step[nt.index] && nt.cnt > Cnt[nt.index]) continue;
      Step[nt.index] = nt.step;
      Cnt[nt.index] = nt.cnt;
      nt.indexn = totnode;
      node[totnode].in = yy.indexb;
      node[totnode].pre = te.indexn;
      totnode++;
      q.push(nt);
    }
  }
}
void solve() { bfs(); }
void out(QQ te) {
  int i;
  int vis2[100005];
  memset(vis2, 0, sizeof(vis2));
  i = te.indexn;
  int temp;
  while (i != -1) {
    temp = node[i].in;
    vis2[temp] = 1;
    i = node[i].pre;
  }
  for (i = 1; i <= m; i++) {
    if (vis2[i] == 1) {
      if (z[i] == 0) {
        ans[tot].a = x[i];
        ans[tot].b = y[i];
        ans[tot].f = 1;
        tot++;
      }
    } else {
      if (z[i] == 1) {
        ans[tot].a = x[i];
        ans[tot].b = y[i];
        ans[tot].f = 0;
        tot++;
      }
    }
  }
  printf("%d\n", tot);
  for (i = 0; i < tot; i++) {
    printf("%d %d %d\n", ans[i].a, ans[i].b, ans[i].f);
  }
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    ini();
    solve();
  }
  return 0;
}
