#include <bits/stdc++.h>
using namespace std;
struct st {
  int pa;
  int za;
} parent1[100001], parent2[100001];
vector<pair<int, int> > adjlist[100001];
int d1[100001], d2[100001], cnt1[100001], cnt2[100001];
void bfs(int s, int d[], int cnt[], struct st parent[]) {
  queue<int> q;
  q.push(s);
  d[s] = 0;
  cnt[s] = 0;
  int vis[100001] = {0};
  vis[s] = 1;
  parent[s].pa = -1;
  parent[s].za = -1;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int j = 0; j < adjlist[x].size(); j++) {
      if (!vis[adjlist[x][j].first]) {
        q.push(adjlist[x][j].first);
        vis[adjlist[x][j].first] = 1;
        d[adjlist[x][j].first] = d[x] + 1;
        cnt[adjlist[x][j].first] = cnt[x];
        if (adjlist[x][j].second) cnt[adjlist[x][j].first]++;
        parent[adjlist[x][j].first].pa = x;
        parent[adjlist[x][j].first].za = adjlist[x][j].second;
      }
    }
  }
}
set<pair<int, int> > anoth;
int main() {
  int n, m, x, y, z, X = 0, ans = 1e9 + 100, i, br;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> x >> y >> z;
    adjlist[x].push_back({y, z});
    adjlist[y].push_back({x, z});
    if (z) X++;
  }
  bfs(n, d2, cnt1, parent2);
  bfs(1, d1, cnt2, parent1);
  for (i = 1; i <= n; i++) {
    if (d1[i] + d2[i] == d1[n]) {
      if (ans > d1[i] - 2 * cnt1[i] + d2[i] - 2 * cnt2[i] + X) {
        ans = d1[i] - 2 * cnt1[i] + d2[i] - 2 * cnt2[i] + X;
        br = i;
      }
    }
  }
  cout << ans << endl;
  int temp = br;
  stack<int> st;
  while (temp != 1) {
    if (!parent1[temp].za) {
      st.push(parent1[temp].za);
      st.push(temp);
      st.push(parent1[temp].pa);
    }
    anoth.insert(make_pair(parent1[temp].pa, temp));
    anoth.insert(make_pair(temp, parent1[temp].pa));
    temp = parent1[temp].pa;
  }
  while (!st.empty()) {
    temp = st.top();
    st.pop();
    cout << temp << " ";
    temp = st.top();
    st.pop();
    cout << temp << " ";
    temp = st.top();
    st.pop();
    cout << !temp << endl;
  }
  temp = br;
  while (temp != n) {
    if (!parent2[temp].za) {
      cout << temp << " " << parent2[temp].pa << " " << 1 << endl;
    }
    anoth.insert(make_pair(parent2[temp].pa, temp));
    anoth.insert(make_pair(temp, parent2[temp].pa));
    temp = parent2[temp].pa;
  }
  for (i = 1; i <= n; i++) {
    for (int j = 0; j < adjlist[i].size(); j++) {
      if (anoth.find(make_pair(i, adjlist[i][j].first)) == anoth.end() &&
          adjlist[i][j].second == 1) {
        anoth.insert(make_pair(adjlist[i][j].first, i));
        cout << i << " " << adjlist[i][j].first << " " << 0 << endl;
      }
    }
  }
  return 0;
}
