#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 3;
vector<pair<int, int> > Adj[MAXN];
int D[MAXN], Par[MAXN], F[MAXN], T[MAXN], C[MAXN], _dp[MAXN], lvl[MAXN],
    vis[MAXN];
void bfs(int start) {
  queue<int> Q;
  Q.push(start);
  memset(lvl, -1, sizeof lvl);
  lvl[start] = 0;
  while (!Q.empty()) {
    int cur = Q.front();
    Q.pop();
    for (int i = 0; i < Adj[cur].size(); i++) {
      pair<int, int> to = Adj[cur][i];
      if (lvl[to.first] == -1) lvl[to.first] = lvl[cur] + 1, Q.push(to.first);
    }
  }
}
void bfs1(int start) {
  memset(_dp, -1, sizeof _dp);
  memset(Par, -1, sizeof Par);
  queue<int> Q;
  Q.push(start);
  _dp[start] = 0;
  vis[start] = 1;
  while (!Q.empty()) {
    int cur = Q.front();
    Q.pop();
    for (int i = 0; i < Adj[cur].size(); i++) {
      pair<int, int> to = Adj[cur][i];
      if (lvl[to.first] == lvl[cur] - 1 &&
          (_dp[to.first] == -1 || _dp[cur] + to.second < _dp[to.first])) {
        _dp[to.first] = _dp[cur] + to.second;
        Par[to.first] = cur;
        if (!vis[to.first]) Q.push(to.first);
        vis[to.first] = 1;
      }
    }
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    F[i] = u, T[i] = v, C[i] = !c;
    Adj[u].push_back(make_pair(v, !c));
    Adj[v].push_back(make_pair(u, !c));
  }
  bfs(1);
  bfs1(n);
  set<pair<int, int> > Ans;
  int x = 1;
  while (Par[x] != -1) {
    int y = Par[x], z = x;
    if (y > z) swap(z, y);
    Ans.insert(make_pair(y, z));
    x = Par[x];
  }
  vector<int> R1, R2, R3;
  for (int i = 0; i < m; i++) {
    int u = F[i], v = T[i], c = C[i];
    if (u > v) swap(u, v);
    if (Ans.count(make_pair(u, v))) {
      if (c) R1.push_back(u), R2.push_back(v), R3.push_back(c);
    } else {
      if (!c) R1.push_back(u), R2.push_back(v), R3.push_back(c);
    }
  }
  printf("%d\n", R1.size());
  for (int i = 0; i < R1.size(); i++) printf("%d %d %d\n", R1[i], R2[i], R3[i]);
}
