#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n, m, first, second, z, d[N], f[N], p[N];
vector<pair<int, int> > a[N];
unordered_map<int, int> c[N];
set<pair<int, int> > s;
vector<int> b;
struct my {
  int first, second, z;
};
vector<my> u;
my make_my(int first, int second, int z) {
  my a;
  a.first = first;
  a.second = second;
  a.z = z;
  return a;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> first >> second >> z;
    z = !z;
    a[first].push_back(make_pair(second, z));
    a[second].push_back(make_pair(first, z));
    c[first][second] = z;
    c[second][first] = z;
  }
  for (int i = 1; i <= n; i++) d[i] = (int)1e9, f[i] = (int)1e9;
  d[1] = f[1] = 0;
  s.insert(make_pair(0, 1));
  while (!s.empty()) {
    int v = s.begin()->second;
    s.erase(s.begin());
    for (int i = 0; i < a[v].size(); i++) {
      int to = a[v][i].first;
      if (d[v] + 1 < d[to] ||
          (d[v] + 1 == d[to] && f[v] + a[v][i].second < f[to])) {
        s.erase(make_pair(d[to], to));
        d[to] = d[v] + 1;
        f[to] = f[v] + a[v][i].second;
        s.insert(make_pair(d[to], to));
        p[to] = v;
      }
    }
  }
  z = n;
  while (z != 1) {
    b.push_back(z);
    z = p[z];
  }
  b.push_back(1);
  reverse((b).begin(), (b).end());
  for (int i = 1; i < b.size(); i++) {
    if (c[b[i]][b[i - 1]] == 1) u.push_back(make_my(b[i], b[i - 1], 1));
    c[b[i]][b[i - 1]] = c[b[i - 1]][b[i]] = 1;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < a[i].size(); j++) {
      int to = a[i][j].first;
      if (c[i][to] == 0) c[to][i] = 1, u.push_back(make_my(i, to, 0));
    }
  cout << u.size() << "\n";
  for (int i = 0; i < u.size(); i++)
    cout << u[i].first << ' ' << u[i].second << ' ' << u[i].z << "\n";
}
