#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
map<pair<int, int>, int> M;
vector<int> V[N];
int cnt[N], par[N];
bool vis[N];
queue<int> Q[2];
vector<pair<int, int> > out;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int sum = 0;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    if (w == 1) sum++;
    V[u].push_back(v);
    V[v].push_back(u);
    pair<int, int> g = {min(u, v), max(u, v)};
    M[g] = w;
  }
  Q[0].push(1);
  cnt[1] = 1;
  vis[1] = true;
  int a = 0, b = 1;
  while (!Q[a].empty()) {
    while (!Q[a].empty()) {
      auto p = Q[a].front();
      Q[a].pop();
      for (auto k : V[p]) {
        pair<int, int> g = {min(p, k), max(p, k)};
        int u = M[g] + cnt[p];
        if (!vis[k] && u > cnt[k]) cnt[k] = u, par[k] = p, Q[b].push(k);
      }
    }
    while (!Q[b].empty()) {
      auto g = Q[b].front();
      if (!vis[g]) vis[g] = true, Q[a].push(g);
      Q[b].pop();
    }
  }
  int p = n, ans = 0;
  while (p != 1) {
    pair<int, int> g = {min(p, par[p]), max(p, par[p])};
    if (M[g] == 0)
      out.push_back(g), ans++;
    else
      M[g] = 0, sum--;
    p = par[p];
  }
  cout << sum + ans << '\n';
  for (auto g : M)
    if (g.second == 1)
      cout << g.first.first << ' ' << g.first.second << ' ' << 0 << '\n';
  for (auto g : out) cout << g.first << ' ' << g.second << ' ' << 1 << '\n';
}
