#include <bits/stdc++.h>
using namespace std;
const long long infi = 1000000000000000009;
int n, m;
vector<pair<int, int> > v[100009 + 4];
int visited[100009 + 4];
map<pair<int, int>, int> mapp;
int parent[100009 + 4];
int edges[100009 + 4][3];
int ans[100009 + 4];
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  int i, j, a, b, c, tot = 0;
  for (i = 1; i <= m; i++) {
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    edges[i][0] = a;
    edges[i][1] = b;
    edges[i][2] = c;
    mapp[make_pair(a, b)] = c;
    mapp[make_pair(b, a)] = c;
    tot += c;
    v[a].push_back(make_pair(b, c));
    v[b].push_back(make_pair(a, c));
  }
  queue<int> q;
  q.push(1);
  visited[1] = 1;
  parent[1] = -1;
  ans[1] = 0;
  while (!q.empty()) {
    a = q.front();
    q.pop();
    for (i = 0; i < v[a].size(); i++) {
      int ed = v[a][i].first;
      if (visited[ed] == 0) {
        visited[ed] = visited[a] + 1;
        parent[ed] = a;
        ans[ed] = v[a][i].second + ans[a];
        q.push(ed);
      } else if (visited[ed] == visited[a] + 1) {
        if (ans[ed] < v[a][i].second + ans[a]) {
          ans[ed] = v[a][i].second + ans[a];
          parent[ed] = a;
        }
      }
    }
  }
  int k = visited[n] - 1 - ans[n] + (tot - ans[n]);
  printf("%d\n", k);
  int p = parent[n];
  c = n;
  while (p != -1) {
    if (mapp[make_pair(p, c)] == 0) {
      printf("%d %d 1\n", p, c);
    }
    mapp[make_pair(p, c)] = 0;
    mapp[make_pair(c, p)] = 0;
    c = p;
    p = parent[p];
  }
  for (i = 1; i <= m; i++) {
    a = edges[i][0];
    b = edges[i][1];
    if (mapp[make_pair(a, b)] == 1) {
      printf("%d %d 0\n", a, b);
    }
  }
  return 0;
}
