#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int>> adj[100001];
vector<pair<int, int>> G[100001];
vector<pair<int, int>> Gb[100001];
int dp[100001];
int par[100001];
int calc(int x) {
  if (dp[x] != -1) return dp[x];
  if (x == 1) {
    return dp[x] = 0;
  }
  int ans = 1e9;
  for (auto i : Gb[x]) {
    int c = calc(i.first) + (1 - i.second);
    if (ans > c) {
      ans = c;
      par[x] = i.first;
    }
  }
  return dp[x] = ans;
}
struct op {
  int a, b, c;
};
int main() {
  set<pair<int, int>> working;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    adj[a].push_back({b, c});
    adj[b].push_back({a, c});
    if (a > b) swap(a, b);
    if (c) working.insert({a, b});
  }
  vector<int> d(n + 1), st(n + 1);
  queue<int> q;
  q.push(1);
  st[1] = 1;
  while (!q.empty()) {
    int fr = q.front();
    q.pop();
    for (auto i : adj[fr]) {
      if (!st[i.first]) {
        d[i.first] = d[fr] + 1;
        st[i.first] = 1;
        q.push(i.first);
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (auto j : adj[i]) {
      if (d[i] + 1 == d[j.first]) {
        G[i].push_back({j.first, j.second});
        Gb[j.first].push_back({i, j.second});
      }
    }
  }
  memset(dp, -1, sizeof dp);
  calc(n);
  int akt = n;
  vector<op> ans;
  while (par[akt] > 0) {
    int from = par[akt], to = akt;
    if (from > to) swap(from, to);
    if (working.find({from, to}) == working.end()) {
      ans.push_back({from, to, 1});
    } else {
      working.erase({from, to});
    }
    akt = par[akt];
  }
  for (auto i : working) {
    ans.push_back({i.first, i.second, 0});
  }
  cout << ans.size() << "\n";
  for (auto i : ans) {
    cout << i.a << " " << i.b << " " << i.c << "\n";
  }
  return 0;
}
