#include <bits/stdc++.h>
using namespace std;
long long inf = 1e15 + 7;
const long long N = 2e5 + 5;
long long n, k;
long long A[N], d[N], d1[N], p[N];
vector<pair<long long, long long>> adj[N];
map<pair<long long, long long>, long long> m;
std::vector<pair<pair<long long, long long>, long long>> v;
void solve() {
  long long i, j, a = 0, ans = 0, b, c;
  cin >> n >> k;
  set<pair<long long, long long>> st;
  queue<pair<pair<long long, long long>, pair<long long, long long>>> q;
  for (i = 0; i < k; i++) {
    cin >> a >> b >> c;
    adj[a].emplace_back(make_pair(b, 1 - c));
    adj[b].emplace_back(make_pair(a, 1 - c));
    m[make_pair(min(a, b), max(a, b))] = 1 - c;
  }
  fill(d, d + n + 1, n + 1);
  q.push(make_pair(make_pair(1, 0), make_pair(0, 0)));
  while (!q.empty()) {
    auto it = q.front();
    q.pop();
    if (d[it.first.first] < it.second.first ||
        (d[it.first.first] == it.second.first &&
         d1[it.first.first] <= it.second.second))
      ;
    else {
      d[it.first.first] = it.second.first;
      d1[it.first.first] = it.second.second;
      p[it.first.first] = it.first.second;
      for (auto i : adj[it.first.first]) {
        if (d[i.first] < d[it.first.first] + 1 ||
            (d[i.first] == d[it.first.first] + 1 &&
             d1[i.first] <= d1[it.first.first] + i.second))
          ;
        else
          q.push(make_pair(
              make_pair(i.first, it.first.first),
              make_pair(d[it.first.first] + 1, d1[it.first.first] + i.second)));
      }
    }
  }
  long long cur = n;
  while (cur != 1) {
    st.insert(make_pair(min(cur, p[cur]), max(cur, p[cur])));
    cur = p[cur];
  }
  for (auto i : m) {
    if (i.second == 0) {
      if (st.find(i.first) == st.end())
        ans++, v.emplace_back(make_pair(i.first, i.second));
    } else {
      if (st.find(i.first) != st.end())
        ans++, v.emplace_back(make_pair(i.first, i.second));
    }
  }
  cout << ans << "\n";
  for (auto i : v)
    cout << i.first.first << " " << i.first.second << " " << i.second << "\n";
}
signed main() {
  long long i, t = 1, j, first;
  while (t--) solve();
}
