#include <bits/stdc++.h>
using namespace std;
int n, m, head[400011], tot, dist[400011], g[400011], pre[400011];
struct Node {
  int u, v, next;
  bool flag, visit;
} edge[400011 << 1], ans[400011];
inline void addedge(int u, int v, bool f) {
  edge[tot].u = u, edge[tot].v = v, edge[tot].flag = f,
  edge[tot].next = head[u], head[u] = tot++;
}
inline void add(int u, int v, bool f) {
  addedge(u, v, f);
  addedge(v, u, f);
}
queue<int> q;
bool inq[400011];
inline void bfs() {
  q.push(1);
  inq[1] = 1;
  memset(inq, 0, sizeof(inq));
  for (int i = 1; i <= n; i++) dist[i] = ~0U >> 2;
  dist[1] = 0;
  while (!q.empty()) {
    int p = q.front();
    q.pop();
    for (int i = head[p]; i != -1; i = edge[i].next) {
      if (dist[edge[i].v] > dist[p] + 1) {
        dist[edge[i].v] = dist[p] + 1;
        if (!edge[i].flag) {
          g[edge[i].v] = g[p] + 1;
          pre[edge[i].v] = i;
        } else {
          g[edge[i].v] = g[p];
          pre[edge[i].v] = i;
        }
        if (!inq[edge[i].v]) {
          q.push(edge[i].v);
          inq[edge[i].v] = 1;
        }
      } else if (dist[edge[i].v] == dist[p] + 1) {
        dist[edge[i].v] = dist[p] + 1;
        if (!edge[i].flag) {
          if (g[edge[i].v] > g[p] + 1) {
            g[edge[i].v] = g[p] + 1;
            pre[edge[i].v] = i;
          }
        } else {
          if (g[edge[i].v] > g[p]) {
            g[edge[i].v] = min(g[edge[i].v], g[p]);
            pre[edge[i].v] = i;
          }
        }
        if (!inq[edge[i].v]) {
          q.push(edge[i].v);
          inq[edge[i].v] = 1;
        }
      }
    }
  }
}
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d%d", &n, &m);
  for (int i = 1, x, y, z; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    add(x, y, z);
  }
  bfs();
  int x = 0;
  for (int i = n; i != 1; i = edge[pre[i]].u) {
    if (edge[pre[i]].flag == 0) {
      ans[++x].u = edge[pre[i]].u;
      ans[x].v = edge[pre[i]].v;
      ans[x].flag = 1;
    }
    edge[pre[i]].visit = edge[pre[i] ^ 1].visit = 1;
  }
  for (int i = 0; i < m * 2; i++) {
    if (edge[i].visit)
      continue;
    else if (edge[i].flag == 1) {
      ans[++x].u = edge[i].u;
      ans[x].v = edge[i].v;
      ans[x].flag = 0;
      edge[i ^ 1].visit = edge[i].visit = 1;
    }
  }
  printf("%d\n", x);
  for (int i = 1; i <= x; i++)
    printf("%d %d %d\n", ans[i].u, ans[i].v, ans[i].flag);
  return 0;
}
