#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1164777216")
using namespace std;
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double pi = acos(-1.0), eps = 1e-15;
const int INF = 1000 * 1000 * 1000 + 5, MAXN = 100005, MOD = 1000007;
const long long INFL = 1000000000000000005;
void prepare(string s) {
  if ((int)s.size() != 0) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
  }
}
struct Edge {
  int u, v, cost;
  Edge() { u = v = cost = 0; }
  Edge(int _u, int _v, int _cost) {
    u = _u;
    v = _v;
    cost = _cost;
  }
  bool operator<(const Edge e) const {
    return u < e.u || u == e.u && v < e.v ||
           u == e.u && v == e.v && cost < e.cost;
  }
  void print() { cout << u << ' ' << v << ' ' << cost << '\n'; }
};
int n, m, d[MAXN], Max[MAXN], p[MAXN], pcost[MAXN], y = 0;
vector<pair<int, int> > g[MAXN];
vector<Edge> e;
void bfs(int s) {
  for (int i = 0; i < MAXN; ++i) d[i] = INF;
  memset(Max, -1, sizeof Max);
  d[s] = 0;
  Max[s] = 0;
  p[s] = -1;
  queue<int> q;
  q.push(s);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < (int)g[v].size(); ++i) {
      int to = g[v][i].first, cost = g[v][i].second;
      if (d[v] + 1 <= d[to]) {
        d[to] = d[v] + 1;
        if (Max[v] + cost > Max[to]) {
          Max[to] = Max[v] + cost;
          p[to] = v;
          pcost[to] = cost;
        }
        q.push(to);
      }
    }
  }
}
void find_path() {
  vector<Edge> ans;
  for (int v = n; v != -1; v = p[v])
    ans.push_back(Edge(min(p[v], v), max(p[v], v), pcost[v]));
  ans.pop_back();
  sort(ans.begin(), ans.end());
  for (int i = 0; i < (int)e.size(); ++i) {
    if (!binary_search(ans.begin(), ans.end(), e[i])) {
      if (e[i].cost == 1) {
        e[i].cost = 0;
        e[i].print();
      }
    } else {
      if (e[i].cost == 0) {
        e[i].cost = 1;
        e[i].print();
      }
    }
  }
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    if (u > v) swap(u, v);
    if (c == 1) y++;
    e.push_back(Edge(u, v, c));
    g[u].push_back(make_pair(v, c));
    g[v].push_back(make_pair(u, c));
  }
  bfs(1);
  cout << d[n] - Max[n] + y - Max[n] << '\n';
  find_path();
}
int main() {
  srand(time(NULL));
  prepare("");
  solve();
  return 0;
}
