#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<pair<int, bool> > > v;
queue<int> q;
int mn[100100];
bool vis[100100];
int lv[100100];
pair<int, pair<int, int> > adj[100100];
set<pair<int, pair<int, bool> > > s;
set<pair<int, int> > s1;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  v.clear();
  v.resize(n + 1);
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    adj[i] = {x, {y, z}};
    v[x].push_back({y, z});
    v[y].push_back({x, z});
  }
  for (int i = 0; i <= n; i++) mn[i] = 1e9;
  memset(lv, -1, sizeof lv);
  lv[1] = 1;
  mn[1] = 0;
  q.push(1);
  while (!q.empty()) {
    int node = q.front();
    q.pop();
    if (vis[node]) continue;
    vis[node] = true;
    for (int i = 0; i < v[node].size(); i++) {
      int child = v[node][i].first;
      bool z = v[node][i].second;
      if (lv[child] <= lv[node] && lv[child] + 1) continue;
      lv[child] = lv[node] + 1;
      mn[child] = min(mn[child], mn[node] + !z);
      if (!vis[child]) q.push(child);
    }
  }
  memset(vis, 0, sizeof vis);
  q.push(n);
  while (!q.empty()) {
    int node = q.front();
    q.pop();
    if (vis[node]) continue;
    vis[node] = true;
    for (int i = 0; i < v[node].size(); i++) {
      int child = v[node][i].first;
      bool z = v[node][i].second;
      if (lv[child] >= lv[node]) continue;
      if (mn[node] - !z == mn[child]) {
        q.push(child);
        if (node > child) swap(node, child);
        s.insert({node, {child, z}});
        break;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    int x = adj[i].first;
    int y = adj[i].second.first;
    int z = adj[i].second.second;
    if (x > y) swap(x, y);
    if (z && s.find({x, {y, z}}) == s.end()) s1.insert({x, y});
  }
  cout << s1.size() + mn[n] << endl;
  for (auto x : s) {
    if (!x.second.second)
      cout << x.first << " " << x.second.first << " " << 1 << endl;
  }
  for (auto x : s1) {
    cout << x.first << " " << x.second << " " << 0 << endl;
  }
  return 0;
}
