#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
inline void gn(long long &first) {
  int sg = 1;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  c == '-' ? (sg = -1, first = 0) : (first = c - '0');
  while ((c = getchar()) >= '0' && c <= '9') first = first * 10 + c - '0';
  first *= sg;
}
inline void gn(int &first) {
  long long t;
  gn(t);
  first = t;
}
inline void gn(unsigned long long &first) {
  long long t;
  gn(t);
  first = t;
}
inline void gn(double &first) {
  double t;
  scanf("%lf", &t);
  first = t;
}
inline void gn(long double &first) {
  double t;
  scanf("%lf", &t);
  first = t;
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
int N, M, E, W;
int dis[101000];
queue<int> Q;
int pre[101000], edg[101000][3], cnt[101000], val[101000];
map<pair<int, int>, int> state, flag;
vector<int> adj[101000];
int len = 0x3f3f3f3f, tot;
void Dijk(int s) {
  memset(dis, 0x3f, sizeof(dis));
  Q.push(s);
  dis[s] = 0;
  cnt[s] = 0;
  val[s] = W;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i], k;
      if (!state[pair<int, int>(u, v)])
        k = val[u] + 1;
      else
        k = val[u] - 1;
      if (dis[v] > dis[u] + 1) {
        dis[v] = dis[u] + 1;
        pre[v] = u;
        val[v] = k;
        Q.push(v);
      } else if (dis[v] == dis[u] + 1 && val[v] > k) {
        val[v] = k;
        pre[v] = u;
        Q.push(v);
      }
    }
  }
}
int main() {
  int u, v, w;
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; i++) {
    scanf("%d%d%d", &u, &v, &w);
    adj[u].push_back(v);
    adj[v].push_back(u);
    state[pair<int, int>(u, v)] = w;
    state[pair<int, int>(v, u)] = w;
    edg[i][0] = u;
    edg[i][1] = v;
    edg[i][2] = w;
    W += w;
  }
  Dijk(1);
  u = N;
  while (u != 1) {
    flag[pair<int, int>(u, pre[u])] = 1;
    flag[pair<int, int>(pre[u], u)] = 1;
    u = pre[u];
  }
  tot = 0;
  for (int i = 0; i < M; i++) {
    u = edg[i][0];
    v = edg[i][1];
    w = edg[i][2];
    if (!flag[pair<int, int>(u, v)] && w == 1)
      tot++;
    else if (flag[pair<int, int>(u, v)] && w == 0)
      tot++;
  }
  printf("%d\n", tot);
  for (int i = 0; i < M; i++) {
    u = edg[i][0];
    v = edg[i][1];
    w = edg[i][2];
    if (!flag[pair<int, int>(u, v)] && w == 1) {
      printf("%d %d 0\n", u, v);
    } else if (flag[pair<int, int>(u, v)] && w == 0) {
      printf("%d %d 1\n", u, v);
    }
  }
  return 0;
}
