#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch - '0' < 0 || ch - '0' > 9) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch - '0' >= 0 && ch - '0' <= 9) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, m;
struct P {
  int u, v, w;
} e[100010];
int head[100010], nxt[100010 * 2], to[100010 * 2], c[100010 * 2],
    id[100010 * 2], tot;
void add(int u, int v, int x, int y) {
  tot++;
  nxt[tot] = head[u];
  head[u] = tot;
  to[tot] = v;
  c[tot] = x;
  id[tot] = y;
}
int dis[100010];
queue<int> q;
void get_dis() {
  for (int i = 2; i <= n; i++) dis[i] = -1;
  q.push(1);
  while (q.size()) {
    int now = q.front();
    q.pop();
    for (int i = head[now]; i; i = nxt[i]) {
      if (dis[to[i]] < 0) {
        dis[to[i]] = dis[now] + 1;
        q.push(to[i]);
      }
    }
  }
}
int f[100010], las[100010], las_id[100010], deg[100010];
void DP() {
  for (int i = 1; i <= n; i++) f[i] = 1000000007;
  f[1] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = head[i]; j; j = nxt[j]) {
      if (dis[to[j]] == dis[i] + 1) deg[to[j]]++;
    }
  }
  q.push(1);
  while (q.size()) {
    int now = q.front();
    q.pop();
    for (int i = head[now]; i; i = nxt[i]) {
      if (dis[to[i]] == dis[now] + 1) {
        deg[to[i]]--;
        if (f[to[i]] > f[now] + (c[i] ^ 1)) {
          f[to[i]] = f[now] + (c[i] ^ 1);
          las[to[i]] = now;
          las_id[to[i]] = id[i];
        }
        if (!deg[to[i]]) q.push(to[i]);
      }
    }
  }
}
int ans[100010], res;
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    e[i].u = read();
    e[i].v = read();
    e[i].w = read();
    add(e[i].u, e[i].v, e[i].w, i);
    add(e[i].v, e[i].u, e[i].w, i);
  }
  get_dis();
  DP();
  for (int i = n; i != 1; i = las[i]) ans[las_id[i]] = 1;
  for (int i = 1; i <= m; i++)
    if (e[i].w ^ ans[i]) res++;
  printf("%d\n", res);
  for (int i = 1; i <= m; i++) {
    if (e[i].w ^ ans[i]) printf("%d %d %d\n", e[i].u, e[i].v, ans[i]);
  }
  return 0;
}
