#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > edges[100001];
int edgesTravelled[1000000];
int roadsRepaired[1000000];
int from[1000001];
int qctr[1000001];
int n, m;
queue<int> bfs;
int main() {
  for (int i = 0; i < 1000000; i++)
    qctr[i] = 0, edgesTravelled[i] = roadsRepaired[i] = 1000000;
  scanf("%d", &n);
  scanf("%d", &m);
  while (m--) {
    int a, b, c;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    edges[a].insert(make_pair(b, c));
    edges[b].insert(make_pair(a, c));
  }
  bfs.push(1);
  edgesTravelled[1] = roadsRepaired[1] = 0;
  from[1] = 1;
  qctr[1] = 1;
  while (!bfs.empty()) {
    int ele = bfs.front();
    bfs.pop();
    for (set<pair<int, int> >::iterator ii = edges[ele].begin();
         ii != edges[ele].end(); ii++) {
      int u = ele;
      pair<int, int> f = *ii;
      int v = f.first;
      int dist = edgesTravelled[ele] + 1;
      int repairs = roadsRepaired[ele] + (1 - f.second);
      if ((dist < edgesTravelled[v]) or
          (dist == edgesTravelled[v] && repairs < roadsRepaired[v])) {
        edgesTravelled[v] = dist;
        roadsRepaired[v] = repairs;
        from[v] = u;
        if (!qctr[v]) {
          qctr[v] = 1;
          bfs.push(v);
        }
      }
    }
  }
  vector<pair<pair<int, int>, int> > taken;
  int curr = n;
  while (curr != 1) {
    int u = from[curr];
    int v = curr;
    int c = (roadsRepaired[u] == roadsRepaired[v]) ? 1 : 0;
    if (!c) taken.push_back(make_pair(make_pair(u, v), 1 - c));
    edges[u].erase(edges[u].find(make_pair(v, c)));
    edges[v].erase(edges[v].find(make_pair(u, c)));
    curr = u;
  }
  for (int i = 1; i <= n; i++) {
    set<pair<int, int> >::iterator ii;
    for (ii = edges[i].begin(); ii != edges[i].end(); ii = edges[i].begin()) {
      pair<int, int> f = *ii;
      if (f.second) taken.push_back(make_pair(make_pair(i, f.first), 0));
      edges[i].erase(ii);
      edges[f.first].erase(make_pair(i, f.second));
    }
  }
  printf("%d\n", (int)taken.size());
  for (int i = 0; i < (int)taken.size(); i++)
    printf("%d %d %d\n", taken[i].first.first, taken[i].first.second,
           taken[i].second);
  return 0;
}
