#include <bits/stdc++.h>
using namespace std;
pair<int, int> p[100005];
int a[100005];
int h[100005];
int ans[100005];
vector<pair<pair<int, int>, int> > g[100005];
void bfs(int s) {
  queue<int> q;
  q.push(s);
  h[s] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto i : g[u]) {
      int v = i.first.first;
      if (h[v] == 0) {
        h[v] = h[u] + 1;
        ans[v] = ans[u] + (i.first.second);
        p[v] = make_pair(u, i.second);
        q.push(v);
      } else if (h[v] == h[u] + 1) {
        if (ans[v] < ans[u] + (i.first.second)) {
          ans[v] = ans[u] + (i.first.second);
          p[v] = make_pair(u, i.second);
        }
      }
    }
  }
}
int mark[100005];
pair<int, pair<int, int> > edge[100005];
int main() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    g[u].push_back(make_pair(make_pair(v, c), i));
    g[v].push_back(make_pair(make_pair(u, c), i));
    edge[i] = make_pair(c, make_pair(u, v));
    if (c == 1) {
      ans++;
      mark[i] = 1;
    }
  }
  bfs(1);
  int x = n;
  while (x != 1) {
    if (edge[p[x].second].first == 0) {
      mark[p[x].second] = 1;
      ans++;
    } else {
      ans--;
      mark[p[x].second] = 0;
    }
    x = p[x].first;
  }
  cout << ans << "\n";
  for (int i = 1; i <= m; i++) {
    if (mark[i]) {
      printf("%d %d %d\n", edge[i].second.first, edge[i].second.second,
             1 - edge[i].first);
    }
  }
  return 0;
}
