#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
const int M = 2e5 + 3;
const int inf = 0x3f3f3f3f;
struct edge {
  int u, v, w, fail;
  edge() {}
  edge(int _u, int _v, int _w, int _fail) {
    u = _u;
    v = _v;
    w = _w;
    fail = _fail;
  }
} e[M];
int head[N], len, n, m, dp[N], que[N], hd, tl, dis[N], pre[N];
bool vis[M];
void init() {
  memset(head, 0xff, sizeof head);
  len = 0;
}
void add(int u, int v, int w) {
  e[len] = edge(u, v, w, head[u]);
  head[u] = len++;
}
void add2(int u, int v, int w) {
  add(u, v, w);
  add(v, u, w);
}
void bfs() {
  memset(dp, -1, sizeof dp);
  memset(dis, 0x3f, sizeof dis);
  memset(pre, -1, sizeof pre);
  memset(vis, 0, sizeof vis);
  dis[1] = 0;
  dp[1] = 0;
  que[hd = tl = 1] = 1;
  while (hd >= tl) {
    int u = que[tl++];
    for (int i = head[u]; ~i; i = e[i].fail) {
      int v = e[i].v, w = e[i].w;
      if (dis[v] == inf) {
        dis[v] = dis[u] + 1;
        dp[v] = dp[u] + w;
        if (pre[v] == -1) {
          pre[v] = i;
        } else {
          pre[v] = i;
        }
        que[++hd] = v;
      } else if (dis[v] == dis[u] + 1) {
        if (dp[v] < dp[u] + w) {
          dp[v] = dp[u] + w;
          if (pre[v] == -1) {
            pre[v] = i;
          } else {
            pre[v] = i;
          }
        }
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  init();
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    add2(u, v, w);
  }
  bfs();
  int u = n;
  while (~pre[u]) {
    vis[pre[u]] = vis[pre[u] ^ 1] = 1;
    u = e[pre[u]].u;
  }
  int cnt = 0;
  for (int i = 0; i < len; i += 2) {
    if (vis[i] ^ e[i].w) {
      cnt++;
    }
  }
  printf("%d\n", cnt);
  for (int i = 0; i < len; i += 2) {
    if (vis[i] ^ e[i].w) {
      printf("%d %d %d\n", e[i].u, e[i].v, !e[i].w);
    }
  }
  return 0;
}
