#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 15;
int a[N], b[N], z[N];
bool is[N];
vector<int> adj[N];
pair<int, int> p[N];
void sp(int n) {
  int v, x, y, u, i, j, ny;
  for (i = 1; i <= n; ++i) p[i] = make_pair(1e9, 0);
  queue<int> q;
  q.push(1);
  p[1] = make_pair(0, 0);
  while (!q.empty()) {
    u = q.front();
    q.pop();
    x = p[u].first, y = p[u].second;
    for (i = 0; i < adj[u].size(); ++i) {
      v = adj[u][i];
      ny = a[v] ^ b[v] ^ u;
      if (p[ny] > make_pair(x + 1, y - z[v])) {
        q.push(ny), p[ny] = make_pair(x + 1, y - z[v]);
      }
    }
  }
  u = n;
  x = p[n].first, y = p[n].second;
  while (u != 1) {
    for (i = 0; i < adj[u].size(); ++i) {
      j = adj[u][i];
      v = a[j] ^ b[j] ^ u;
      if (p[v].first == x - 1 && p[v].second == y + z[j]) {
        is[j] = 1;
        x = x - 1, y = y + z[j];
        u = v;
        break;
      }
    }
  }
}
int main() {
  int n, m, i, j;
  cin >> n >> m;
  for (i = 0; i < m; ++i)
    scanf("%d%d%d", &a[i], &b[i], &z[i]), adj[a[i]].push_back(i),
        adj[b[i]].push_back(i);
  sp(n);
  vector<int> r;
  for (i = 0; i < m; ++i)
    if (is[i] ^ z[i]) r.push_back(i);
  cout << r.size() << endl;
  for (i = 0; i < r.size(); ++i) {
    j = r[i];
    printf("%d %d %d\n", a[j], b[j], is[j]);
  }
}
