#include <bits/stdc++.h>
using namespace std;
const int oo = int(2e9) + 9;
const double eps = 1e-9;
const double pi = 3.14159265358979323846264338327950;
vector<vector<pair<int, int> > > AdjList(100005);
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > dist(100005);
  map<pair<int, int>, int> is;
  int y = 0;
  for (int i = 0; i <= 100004; i++) dist[i] = make_pair(oo, oo);
  for (int i = 1; i <= m; i++) {
    int u, v, f;
    cin >> u >> v >> f;
    AdjList[u].push_back(make_pair(v, f));
    AdjList[v].push_back(make_pair(u, f));
    y += (f == 1);
  }
  vector<pair<int, int> > parent(100005);
  parent[1] = make_pair(0, -1);
  priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int> >,
                 greater<pair<pair<int, int>, int> > >
      pq;
  pq.push(make_pair(make_pair(0, 0), 1));
  dist[1] = make_pair(0, 0);
  while (!pq.empty()) {
    int d1 = pq.top().first.first;
    int d2 = pq.top().first.second;
    int u = pq.top().second;
    pq.pop();
    if (d1 != dist[u].first) continue;
    for (vector<pair<int, int> >::iterator v = (AdjList[u]).begin();
         v != (AdjList[u]).end(); v++) {
      if (dist[v->first].first > d1 + 1) {
        dist[v->first].first = d1 + 1;
        dist[v->first].second = d2 + v->second;
        pq.push(make_pair(dist[v->first], v->first));
        parent[v->first] = make_pair(u, 1 - v->second);
        continue;
      }
      if (dist[v->first].first == d1 + 1)
        if (dist[v->first].second < d2 + v->second) {
          dist[v->first].second = d2 + v->second;
          pq.push(make_pair(dist[v->first], v->first));
          parent[v->first] = make_pair(u, 1 - v->second);
        }
    }
  }
  cout << dist[n].first + y - 2 * dist[n].second << endl;
  int t = n;
  int color[100005];
  memset(color, 00, sizeof(color));
  color[t] = 1;
  while (t != 0) {
    if (parent[t].second == 1)
      cout << parent[t].first << " " << t << " " << parent[t].second << endl;
    t = parent[t].first;
    color[t] = 1;
  }
  for (int u = 1; u <= n; u++)
    for (vector<pair<int, int> >::iterator v = (AdjList[u]).begin();
         v != (AdjList[u]).end(); v++)
      if (!is[make_pair(u, v->first)])
        if (!(color[v->first] == 1 && color[u] == 1))
          if (v->second == 1) {
            cout << u << " " << v->first << " "
                 << "0\n";
            is[make_pair(u, v->first)] = true;
            is[make_pair(v->first, u)] = true;
          }
  return 0;
}
