#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > s;
vector<pair<int, int> > v;
set<pair<long long, int> > Q;
vector<int> g[100005];
int parent[100005];
long long dist[100005];
int n, m;
int main() {
  int i, j, k, x, y, z, ans;
  scanf("%d%d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    if (x > y) swap(x, y);
    g[x].push_back(y);
    g[y].push_back(x);
    if (z) s.insert(make_pair(x, y));
  }
  for (i = 0; i < 100005; i++) dist[i] = 1000000000000007;
  Q.insert(pair<long long, int>(0, 1));
  parent[1] = -1;
  dist[1] = 0;
  while (!Q.empty()) {
    pair<long long, int> p = *Q.begin();
    int nd = p.second;
    Q.erase(Q.begin());
    for (i = 0; i < g[nd].size(); i++) {
      int u = g[nd][i];
      long long d = p.first;
      x = nd;
      y = u;
      if (x > y) swap(x, y);
      if (s.find(make_pair(x, y)) != s.end())
        d += 100000 + 5;
      else
        d += 100000 + 7;
      if (d < dist[u]) {
        if (dist[u] < 1000000000000007)
          (Q.erase(Q.find(pair<long long, int>(dist[u], u))));
        parent[u] = nd;
        dist[u] = d;
        Q.insert(pair<long long, int>(d, u));
      }
    }
  }
  i = n;
  while (parent[i] != -1) {
    x = i;
    y = parent[i];
    pair<int, int> p = make_pair(min(x, y), max(x, y));
    if (s.find(p) == s.end())
      v.push_back(p);
    else
      s.erase(p);
    i = parent[i];
  }
  printf("%d\n", (int)(v.size() + s.size()));
  for (i = 0; i < v.size(); i++) printf("%d %d 1\n", v[i].first, v[i].second);
  for (set<pair<int, int> >::iterator it = s.begin(); it != s.end(); it++)
    printf("%d %d 0\n", (*it).first, (*it).second);
  return 0;
}
