#include <bits/stdc++.h>
using namespace std;
long long n, m, dist[200010];
vector<pair<long long, long long> > vertice[200010], ida[200010];
pair<long long, long long> memo[200010];
map<pair<long long, long long>, long long> estado;
set<pair<long long, long long> > tem;
void bfs() {
  memset(dist, -1, sizeof(dist));
  dist[n] = 0;
  queue<long long> q;
  q.push(n);
  while (q.size() != 0) {
    long long u = q.front();
    q.pop();
    for (long long i = 0; i < vertice[u].size(); i++) {
      long long v = vertice[u][i].first;
      if (dist[v] == -1) {
        dist[v] = dist[u] + 1;
        q.push(v);
      }
    }
  }
}
pair<long long, long long> dfs(long long obj) {
  if (memo[obj].first != -1) return memo[obj];
  if (obj == n) return {0, 0};
  pair<long long, long long> ans = {-9123456789, 0};
  for (long long i = 0; i < ida[obj].size(); i++) {
    long long u = ida[obj][i].first, bit = ida[obj][i].second;
    pair<long long, long long> aux = dfs(u);
    if (aux.first + bit > ans.first) {
      ans = {aux.first + bit, u};
    }
  }
  return memo[obj] = ans;
}
void solve() {
  memset(memo, -1, sizeof(memo));
  cin >> n >> m;
  long long tot = 0;
  for (long long i = 1; i <= m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    vertice[a].push_back({b, c});
    vertice[b].push_back({a, c});
    tot += c;
    if (a > b) swap(a, b);
    estado[{a, b}] = c;
    tem.insert({a, b});
  }
  bfs();
  for (long long u = 1; u < n; u++) {
    for (long long j = 0; j < vertice[u].size(); j++) {
      long long v = vertice[u][j].first, bit = vertice[u][j].second;
      if (dist[v] + 1 == dist[u]) ida[u].push_back({v, bit});
    }
  }
  dfs(1);
  long long obj = 1;
  vector<pair<pair<long long, long long>, long long> > resp;
  while (obj != n) {
    long long esq = obj, dir = dfs(obj).second;
    if (esq > dir) swap(esq, dir);
    if (estado[{esq, dir}] == 0) resp.push_back({{esq, dir}, 1});
    tem.erase({esq, dir});
    obj = dfs(obj).second;
  }
  for (auto it = tem.begin(); it != tem.end(); it++) {
    pair<long long, long long> aux = *it;
    if (estado[aux] == 1) {
      resp.push_back({aux, 0});
    }
  }
  cout << resp.size() << "\n";
  for (long long i = 0; i < resp.size(); i++)
    cout << resp[i].first.first << " " << resp[i].first.second << " "
         << resp[i].second << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
}
