#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n, m, first, second, d[N], f[N], p[N];
vector<pair<int, bool> > a[N];
unordered_map<int, bool> c[N];
queue<int> s;
vector<int> b;
bool z;
struct my {
  int first, second;
  bool 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));
    if (z) c[first][second] = c[second][first] = 1;
  }
  for (int i = 2; i <= n; ++i) d[i] = (int)1e9, f[i] = (int)1e9;
  s.push(1);
  while (!s.empty()) {
    int v = s.front();
    s.pop();
    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])) {
        d[to] = d[v] + 1;
        f[to] = f[v] + a[v][i].second;
        s.push(to);
        p[to] = v;
      }
    }
  }
  second = n;
  while (second != 1) {
    b.push_back(second);
    second = p[second];
  }
  b.push_back(1);
  reverse((b).begin(), (b).end());
  for (int i = 1; i < b.size(); ++i) {
    if (f[b[i]] - f[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));
    }
  printf("%d\n", u.size());
  for (int i = 0; i < u.size(); ++i)
    printf("%d %d %d\n", u[i].first, u[i].second, u[i].z);
}
