#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
struct edge {
  int u, v, id, w, next;
} e[maxn * 2];
struct heap {
  int v, d, w;
  heap(int v, int d, int w) : v(v), d(d), w(w) {}
  bool operator<(const heap& rhs) const {
    if (d != rhs.d) return d > rhs.d;
    return w > rhs.w;
  }
};
int first[maxn], cnt;
int a[maxn], b[maxn], c[maxn], flag[maxn];
int d[maxn], d2[maxn], vis[maxn], p[maxn];
void AddEdge(int u, int v, int w, int id) {
  e[cnt].u = u;
  e[cnt].v = v;
  e[cnt].id = id;
  e[cnt].w = w;
  e[cnt].next = first[u];
  first[u] = cnt++;
  e[cnt].u = v;
  e[cnt].v = u;
  e[cnt].id = id;
  e[cnt].w = w;
  e[cnt].next = first[v];
  first[v] = cnt++;
}
void Dijkstra(int n) {
  priority_queue<heap> Q;
  Q.push(heap(1, 0, 0));
  for (int i = 0; i <= n; i++) {
    d[i] = 9999999;
    d2[i] = 9999999;
    vis[i] = 0;
    p[i] = -1;
  }
  d[1] = d2[1] = 0;
  while (!Q.empty()) {
    heap x = Q.top();
    Q.pop();
    int u = x.v;
    if (vis[u]) continue;
    vis[u] = true;
    for (int i = first[u]; i != -1; i = e[i].next) {
      int v = e[i].v;
      if (d[v] > d[u] + 1 || d[v] == d[u] + 1 && d2[v] > d2[u] + e[i].w) {
        d[v] = d[u] + 1;
        d2[v] = d2[u] + e[i].w;
        p[v] = i;
        Q.push(heap(v, d[v], d2[v]));
      }
    }
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  memset(first, -1, sizeof(first));
  cnt = 0;
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &a[i], &b[i], &c[i]);
    c[i] ^= 1;
    AddEdge(a[i], b[i], c[i], i);
  }
  Dijkstra(n);
  int tmp = n;
  while (1) {
    int id = p[tmp];
    flag[e[id].id] = 1;
    tmp = e[id].u;
    if (tmp == 1) break;
  }
  int sum = 0;
  for (int i = 0; i < m; i++) {
    c[i] ^= 1;
    if (flag[i]) {
      if (c[i] == 0) {
        c[i] = 1;
        sum++;
      } else {
        flag[i] = 0;
      }
    } else {
      if (c[i] == 1) {
        c[i] = 0;
        sum++;
        flag[i] = 1;
      }
    }
  }
  printf("%d\n", sum);
  for (int i = 0; i < m; i++)
    if (flag[i]) printf("%d %d %d\n", a[i], b[i], c[i]);
  return 0;
}
