#include <bits/stdc++.h>
using namespace std;
long long visited[100001] = {0};
long long sh[100001];
long long from[100001];
vector<pair<int, int>> graph[100001];
int path[100001];
int pp = 0;
struct data {
  int from;
  int to;
};
struct compar {
  bool operator()(const data& a, const data& b) const {
    if (a.from != b.from)
      return a.from < b.from;
    else
      return a.to < b.to;
  }
};
int bsz, gsz, csz;
set<data, compar> broads, groads, croads;
int main() {
  long long n, m, i, j;
  data D;
  cin >> n >> m;
  sh[1] = 0;
  for (i = 2; i <= n; i++) sh[i] = 99999999999999;
  int x, y, z;
  for (i = 1; i <= m; i++) {
    cin >> x >> y >> z;
    if (x > y) swap(x, y);
    D.from = x;
    D.to = y;
    if (z == 0)
      broads.insert(D);
    else
      groads.insert(D);
    graph[x].push_back(make_pair(y, z));
    graph[y].push_back(make_pair(x, z));
  }
  priority_queue<pair<long long, int>, vector<pair<long long, int>>,
                 greater<pair<long long, int>>>
      Q;
  Q.push({0, 1});
  int p;
  visited[1] = 1;
  while (!Q.empty()) {
    pair<long long, int> pr = Q.top();
    Q.pop();
    int p = pr.second;
    if (pr.first != sh[p]) continue;
    for (i = 0; i < graph[p].size(); i++) {
      if (sh[graph[p][i].first] >
          sh[p] + 100005 + (graph[p][i].second ? -1 : 1)) {
        sh[graph[p][i].first] = sh[p] + 100005 + (graph[p][i].second ? -1 : 1);
        Q.push({sh[graph[p][i].first], graph[p][i].first});
        from[graph[p][i].first] = p;
      }
    }
  }
  pp = -1;
  path[++pp] = n;
  while (path[pp] != 1) path[++pp] = from[path[pp - 1]];
  pp++;
  reverse(path, path + pp);
  bsz = broads.size();
  gsz = groads.size();
  csz = 0;
  for (i = 1; i < pp; i++) {
    D.from = path[i - 1];
    D.to = path[i];
    if (D.from > D.to) swap(D.from, D.to);
    if (broads.count(D) == 1) {
      broads.erase(D);
      bsz--;
      croads.insert(D);
      csz++;
    } else {
      groads.erase(D);
      gsz--;
    }
  }
  cout << csz + gsz << endl;
  for (auto it = croads.begin(); it != croads.end(); it++) {
    cout << it->from << " " << it->to << " "
         << "1" << endl;
  }
  for (auto it = groads.begin(); it != groads.end(); it++) {
    cout << it->from << " " << it->to << " "
         << "0" << endl;
  }
  return 0;
}
