#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 50;
vector<pair<int, pair<int, int> > > graph[N];
vector<pair<pair<int, int>, pair<int, int> > > edges;
bool inpath[N];
int who[N];
int number[N];
map<pair<int, int>, int> present;
void solve(int n) {
  int ans[n + 1];
  for (int i = 0; i <= n; i++) ans[i] = INT_MAX;
  int dist[n + 1];
  for (int i = 0; i <= n; i++) dist[i] = INT_MAX;
  ans[1] = 0;
  dist[1] = 0;
  queue<pair<int, int> > q;
  q.push({1, 0});
  while (!q.empty()) {
    pair<int, int> temp = q.front();
    q.pop();
    int node = temp.first;
    int d = temp.second;
    for (auto it : graph[node]) {
      int to = it.first;
      int no = it.second.second;
      int work = it.second.first;
      if (dist[to] < dist[node] + 1) continue;
      if (dist[to] > dist[node] + 1) {
        dist[to] = dist[node] + 1;
        who[to] = node;
        ans[to] = ans[node] + (1 - work);
        q.push({to, dist[to]});
      } else if (dist[to] == dist[node] + 1) {
        if (ans[to] < ans[node] + 1 - work) {
          continue;
        } else {
          who[to] = node;
          ans[to] = ans[node] + 1 - work;
        }
      }
    }
  }
  int u = n;
  while (u != 1) {
    present[{u, who[u]}] = 1;
    present[{who[u], u}] = 1;
    u = who[u];
  }
}
int main(void) {
  int n, m;
  cin >> n >> m;
  int u, v, x;
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> x;
    graph[u].push_back({v, make_pair(x, i)});
    graph[v].push_back({u, make_pair(x, i)});
    edges.push_back(make_pair(make_pair(u, v), make_pair(x, i)));
  }
  solve(n);
  int k = 0;
  vector<pair<pair<int, int>, int> > ans;
  for (int i = 0; i < edges.size(); i++) {
    int u = edges[i].first.first;
    int v = edges[i].first.second;
    int work = edges[i].second.first;
    if (present.find({u, v}) == present.end()) {
      if (work == 1) {
        ans.push_back(make_pair(make_pair(u, v), 0));
        k++;
      }
    } else {
      if (work == 0) {
        ans.push_back(make_pair(make_pair(u, v), 1));
        k++;
      }
    }
  }
  cout << k << endl;
  for (int i = 0; i < k; i++) {
    cout << ans[i].first.first << " " << ans[i].first.second << " "
         << ans[i].second << endl;
  }
  return 0;
}
