#include <bits/stdc++.h>
const long long MAX_N = 1e5 + 100;
const long long MOD = 1e9 + 7;
using namespace std;
vector<pair<int, int>> g[MAX_N];
int n, m;
pair<int, int> dis[MAX_N];
int p[MAX_N];
void bfs(int v) {
  for (int i = 1; i <= n; ++i) dis[i] = {1e9, 0};
  dis[v] = {0, 0};
  vector<int> vc;
  p[v] = v;
  vc.push_back(v);
  for (int i = 0; i < vc.size(); ++i) {
    int u = vc[i];
    for (auto x : g[u]) {
      if (dis[x.first].first > dis[u].first + 1) {
        p[x.first] = u;
        dis[x.first].first = dis[u].first + 1;
        dis[x.first].second = dis[u].second + x.second;
        vc.push_back(x.first);
      } else if (dis[x.first].first == dis[u].first + 1 and
                 dis[x.first].second > dis[u].second + x.second) {
        p[x.first] = u;
        dis[x.first].second = dis[u].second + x.second;
        vc.push_back(x.first);
      }
    }
  }
}
map<pair<int, int>, bool> bad;
map<pair<int, int>, bool> best;
int main() {
  cin >> n >> m;
  vector<pair<int, int>> goods;
  for (int i = 0; i < m; ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    z = 1 - z;
    g[x].push_back({y, z});
    g[y].push_back({x, z});
    if (z)
      bad[{x, y}] = bad[{y, x}] = true;
    else
      goods.push_back({x, y});
  }
  bfs(1);
  vector<int> vers;
  int now = n;
  while (p[now] != now) {
    vers.push_back(now);
    now = p[now];
  }
  vector<pair<pair<int, int>, int>> ans;
  vers.push_back(1);
  for (int i = 0; i < vers.size() - 1; ++i) {
    if (bad[{vers[i], vers[i + 1]}])
      ans.push_back({{vers[i], vers[i + 1]}, 1});
    else
      best[{vers[i], vers[i + 1]}] = best[{vers[i + 1], vers[i]}] = true;
  }
  for (auto x : goods) {
    if (!best[x]) ans.push_back({x, 0});
  }
  cout << ans.size() << "\n";
  for (auto x : ans)
    cout << x.first.first << " " << x.first.second << " " << x.second << "\n";
  return 0;
}
