#include <bits/stdc++.h>
using std::multiset;
const int N = 100010, M = N << 1;
int tot = 1, head[N], next[M], to[M], c[M], f1[N], f2[N];
int n, m, fa[N], fe[N];
void add(int x, int y, int z) {
  to[++tot] = y;
  next[tot] = head[x];
  head[x] = tot;
  c[tot] = z;
}
struct lr {
  int x, f1, f2;
  bool operator<(const lr &a) const {
    return f1 != a.f1 ? f1 < a.f1 : f2 < a.f2;
  }
} t;
struct E {
  int x, y, ty;
  void print() { printf("%d %d %d\n", x, y, ty); }
} e[N];
multiset<lr> info;
bool vis[N];
int main() {
  int ans = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int x, y, ty;
    scanf("%d%d%d", &x, &y, &ty);
    add(x, y, !ty);
    add(y, x, !ty);
    ans += ty;
    e[i] = (E){x, y, !ty};
  }
  memset(f1, 63, sizeof f1);
  memset(f2, 63, sizeof f2);
  int S = 1;
  info.insert((lr){S, f1[S] = 0, f2[S] = 0});
  while (!info.empty()) {
    auto it = info.begin();
    t = *it;
    info.erase(it);
    if (vis[t.x]) continue;
    vis[t.x] = 1;
    for (int i = head[t.x]; i; i = next[i]) {
      if (f1[to[i]] > f1[t.x] + 1) {
        info.insert(
            (lr){to[i], f1[to[i]] = f1[t.x] + 1, f2[to[i]] = f2[t.x] + c[i]});
        fa[to[i]] = t.x;
        fe[to[i]] = i >> 1;
      } else if (f1[to[i]] == f1[t.x] + 1 && f2[to[i]] > f2[t.x] + c[i]) {
        info.insert((lr){to[i], f1[to[i]], f2[to[i]] = f2[t.x] + c[i]});
        fa[to[i]] = t.x;
        fe[to[i]] = i >> 1;
      }
    }
  }
  memset(vis, 0, sizeof vis);
  for (int i = n; i != 1; i = fa[i]) vis[fe[i]] = 1;
  printf("%d\n", ans - f1[n] + 2 * f2[n]);
  for (int i = 1; i <= m; ++i) {
    if (!vis[i] && !e[i].ty)
      e[i].print();
    else if (vis[i] && e[i].ty)
      e[i].print();
  }
}
