#include <bits/stdc++.h>
using namespace std;
struct node {
  int a, v, c, next;
  node() {}
  node(int a, int v, int c, int next) : a(a), v(v), c(c), next(next) {}
} edge[200010];
struct pp {
  int v, d1, d2;
};
queue<int> q;
int n, m, tot;
int dis[100010], d[100010], pre[100010], ans[100010], head[100010];
int vis[100010];
void add(int x, int y, int z) {
  edge[++tot] = node(x, y, z, head[x]);
  head[x] = tot;
}
void SPFA() {
  memset(d, 0, sizeof d);
  memset(ans, 0, sizeof ans);
  memset(vis, 0, sizeof vis);
  for (int i = 1; i <= 100010; i++) dis[i] = 111111;
  dis[1] = 0;
  vis[1] = 1;
  q.push(1);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    vis[v] = 0;
    for (int i = head[v]; i != -1; i = edge[i].next)
      if (dis[v] + 1 < dis[edge[i].v] ||
          (dis[v] + 1 == dis[edge[i].v] && d[v] + edge[i].c > d[edge[i].v])) {
        dis[edge[i].v] = dis[v] + 1;
        d[edge[i].v] = d[v] + edge[i].c;
        pre[edge[i].v] = i;
        if (!vis[edge[i].v]) {
          q.push(edge[i].v);
          vis[edge[i].v] = 1;
        }
      }
  }
  int xx = n;
  while (xx != 1) {
    ans[(pre[xx] + 1) / 2] = 1;
    xx = edge[pre[xx]].a;
  }
}
int main() {
  while (scanf("%d %d", &n, &m) != EOF) {
    tot = 0;
    int sum = 0, x, y, z;
    memset(head, -1, sizeof head);
    for (int i = 1; i <= m; i++) {
      scanf("%d %d %d", &x, &y, &z);
      add(y, x, z);
      add(x, y, z);
      if (z) sum++;
    }
    SPFA();
    printf("%d\n", sum + dis[n] - 2 * d[n]);
    for (int i = 2; i <= 2 * m; i += 2)
      if (ans[i / 2] ^ edge[i].c)
        printf("%d %d %d\n", edge[i].a, edge[i].v, edge[i].c ^ 1);
  }
  return 0;
}
