#include <bits/stdc++.h>
using namespace std;
signed main() {
  ;
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  int t = 1;
  while (t--) {
    int n, m;
    cin >> n >> m;
    map<pair<int, int>, int> v;
    vector<vector<int> > adj;
    int sahiedge = 0;
    vector<int> t;
    for (int i = 0; i <= n; i++) {
      adj.push_back(t);
    }
    int x, y, z;
    for (int i = 0; i < m; i++) {
      cin >> x >> y >> z;
      v[make_pair(x, y)] = z;
      v[make_pair(y, x)] = z;
      adj[x].push_back(y);
      adj[y].push_back(x);
      if (z) sahiedge++;
    }
    int dist1[n + 1];
    int parent[n + 1];
    memset(dist1, -1, sizeof(dist1));
    queue<int> q;
    int sahi1[n + 1];
    q.push(1);
    dist1[1] = 0;
    parent[1] = 1;
    sahi1[1] = 0;
    while (!q.empty()) {
      int ver = q.front();
      q.pop();
      for (int i = 0; i < adj[ver].size(); i++) {
        if (dist1[adj[ver][i]] == -1) {
          dist1[adj[ver][i]] = dist1[ver] + 1;
          sahi1[adj[ver][i]] = sahi1[ver] + v[make_pair(ver, adj[ver][i])];
          parent[adj[ver][i]] = ver;
          q.push(adj[ver][i]);
        }
      }
    }
    int distn[n + 1];
    int parentp[n + 1];
    memset(distn, -1, sizeof(distn));
    queue<int> que;
    que.push(n);
    distn[n] = 0;
    parentp[n] = n;
    int sahin[n + 1];
    sahin[n] = 0;
    while (!que.empty()) {
      int ver = que.front();
      que.pop();
      for (int i = 0; i < adj[ver].size(); i++) {
        if (distn[adj[ver][i]] == -1) {
          distn[adj[ver][i]] = distn[ver] + 1;
          sahin[adj[ver][i]] = sahin[ver] + v[make_pair(ver, adj[ver][i])];
          parentp[adj[ver][i]] = ver;
          que.push(adj[ver][i]);
        }
      }
    }
    int med = 1;
    int bla = 0;
    for (int i = 1; i <= n; i++) {
      if ((dist1[i] + distn[i]) == dist1[n]) {
        if (sahi1[i] + sahin[i] > bla) {
          bla = sahi1[i] + sahin[i];
          med = i;
        }
      }
    }
    int qwert = med;
    int t1;
    vector<pair<pair<int, int>, bool> > res;
    while (parent[qwert] != qwert) {
      t1 = parent[qwert];
      if (v[make_pair(qwert, t1)] == 0)
        res.push_back(make_pair(make_pair(qwert, t1), 1));
      v.erase(make_pair(qwert, t1));
      v.erase(make_pair(t1, qwert));
      qwert = t1;
    }
    qwert = med;
    while (parentp[qwert] != qwert) {
      t1 = parentp[qwert];
      if (v[make_pair(qwert, t1)] == 0)
        res.push_back(make_pair(make_pair(qwert, t1), 1));
      v.erase(make_pair(qwert, t1));
      v.erase(make_pair(t1, qwert));
      qwert = t1;
    }
    for (auto itr = v.begin(); itr != v.end();) {
      if (itr->second == 1)
        res.push_back(
            make_pair(make_pair(itr->first.first, itr->first.second), 0));
      v.erase(make_pair(itr->first.second, itr->first.first));
      v.erase(itr++);
    }
    cout << res.size() << '\n';
    for (int i = 0; i < res.size(); i++) {
      cout << res[i].first.first << " " << res[i].first.second << " "
           << res[i].second << '\n';
    }
  };
}
