#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
int n, m;
vector<pair<int, int>> v[N];
int lev[N], par[N], rp[N];
vector<pair<int, int>> vv[N];
int dp[N];
vector<tuple<int, int, int>> res;
set<pair<int, int>> vis;
void bfs() {
  for (int i = 2; i <= n; i++) lev[i] = 1e9;
  queue<int> qu;
  qu.push(1);
  while (!qu.empty()) {
    int x = qu.front();
    qu.pop();
    for (auto it : v[x]) {
      if (lev[it.first] == 1e9) {
        lev[it.first] = lev[x] + 1;
        qu.push(it.first);
      }
    }
  }
}
int giveres(int s) {
  if (s == 1) return 0;
  int &ret = dp[s];
  if (ret != -1) return ret;
  ret = 1e9;
  for (auto it : v[s]) {
    if (lev[s] - lev[it.first] == 1) {
      int gk = 0;
      if (it.second == 0) gk = 1;
      ret = min(ret, gk + giveres(it.first));
    }
  }
  return ret;
}
void print(int s) {
  if (s == 1) return;
  int &ret = dp[s];
  for (auto it : v[s]) {
    if (lev[s] - lev[it.first] == 1) {
      int gk = 0;
      if (it.second == 0) gk = 1;
      if (ret == gk + giveres(it.first)) {
        if (gk) res.push_back(make_tuple(s, it.first, 1));
        vis.insert({min(s, it.first), max(s, it.first)});
        print(it.first);
        return;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  int ccc = 0;
  set<tuple<int, int, int>> edge;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    edge.insert(make_tuple(min(a, b), max(a, b), c));
    v[a].push_back({b, c});
    v[b].push_back({a, c});
    if (c == 0) ccc++;
  }
  bfs();
  memset(dp, -1, sizeof(dp));
  cout << m - ccc - (lev[n] - giveres(n)) + giveres(n) << '\n';
  print(n);
  for (tuple<int, int, int> it : edge) {
    int x = get<0>(it);
    int y = get<1>(it);
    if (x > y) swap(x, y);
    if (get<2>(it)) {
      if (vis.find({x, y}) == vis.end()) {
        res.push_back(make_tuple(x, y, 0));
      }
    }
  }
  for (auto it : res)
    cout << get<0>(it) << " " << get<1>(it) << " " << get<2>(it) << '\n';
  return 0;
}
