#include <bits/stdc++.h>
using namespace std;
const long long int md = 1e9 + 7;
const long long int inf = 1e9;
const long long int N = 100005;
vector<pair<long long int, bool>> g[N];
long long int val[N], depth[N];
set<pair<long long int, long long int>> s;
bitset<N> vis;
vector<pair<pair<long long int, long long int>, long long int>> ans;
signed main() {
  long long int n, m;
  scanf("%lld %lld", &n, &m);
  for (long long int i = 1; i <= m; i++) {
    long long int u, v, w;
    scanf("%lld %lld %lld", &u, &v, &w);
    w ^= 1;
    g[u].emplace_back(v, w);
    g[v].emplace_back(u, w);
  }
  queue<long long int> q;
  q.push(n);
  fill(val + 1, val + n + 1, inf);
  val[n] = 0;
  depth[n] = 0;
  vis[n] = 1;
  while (!q.empty()) {
    long long int u = q.front();
    q.pop();
    for (auto v : g[u]) {
      if (!vis[v.first]) {
        q.emplace(v.first);
        vis[v.first] = 1;
        depth[v.first] = depth[u] + 1;
      }
      if (depth[v.first] == depth[u] + 1)
        val[v.first] = min(val[v.first], val[u] + v.second);
    }
  }
  long long int u = 1;
  while (u != n) {
    for (auto v : g[u]) {
      if (depth[v.first] == depth[u] - 1 && val[u] == val[v.first] + v.second) {
        s.insert({u, v.first});
        s.insert({v.first, u});
        u = v.first;
        break;
      }
    }
  }
  s.insert({u, n});
  s.insert({n, u});
  for (long long int i = 1; i <= n; i++) {
    for (auto v : g[i]) {
      if (v.first > i) {
        if (s.count({i, v.first}) && v.second == 1)
          ans.emplace_back(pair<long long int, long long int>(i, v.first), 1);
        else if (!s.count({i, v.first}) && v.second == 0)
          ans.emplace_back(pair<long long int, long long int>(i, v.first), 0);
      }
    }
  }
  printf("%d\n", ans.size());
  for (auto v : ans)
    printf("%lld %lld %lld\n", v.first.first, v.first.second, v.second);
  return 0;
}
