#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
const int MAXM = 100000;
int N, M;
map<pair<int, int>, int> estate;
vector<vector<int> > edges;
int d[MAXN + 1];
int c[MAXN + 1];
bool visited[MAXN + 1];
set<pair<int, int> > path;
int edgeCost(int u, int v) {
  if (u > v) swap(u, v);
  return 1 - estate[make_pair(u, v)];
}
void getDists() {
  for (int i = 1; i <= N; i++) visited[i] = 0;
  queue<int> q;
  q.push(1);
  d[1] = 0;
  c[1] = 0;
  visited[1] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int e = 0; e < (int)edges[u].size(); e++) {
      int v = edges[u][e];
      if (!visited[v]) {
        q.push(v);
        d[v] = d[u] + 1;
        c[v] = c[u] + edgeCost(u, v);
        visited[v] = 1;
      } else if (d[v] == d[u] + 1) {
        c[v] = min(c[v], c[u] + edgeCost(u, v));
      }
    }
  }
}
void backtrack() {
  int u = N;
  while (u != 1) {
    int oldu = u;
    for (int e = 0; e < (int)edges[u].size(); e++) {
      int v = edges[u][e];
      if (d[v] + 1 == d[u] && c[v] + edgeCost(u, v) == c[u]) {
        path.insert(make_pair(min(u, v), max(u, v)));
        u = v;
        break;
      }
    }
    assert(u != oldu);
  }
}
void dispAffectedEdges() {
  map<pair<int, int>, int>::iterator it;
  int k = 0;
  for (it = estate.begin(); it != estate.end(); it++) {
    bool onpath = false;
    if (path.end() != path.find(it->first)) onpath = true;
    if (onpath != it->second) k++;
  }
  cout << k << endl;
  for (it = estate.begin(); it != estate.end(); it++) {
    bool onpath = false;
    if (path.end() != path.find(it->first)) onpath = true;
    if (onpath != it->second)
      cout << it->first.first << " " << it->first.second << " "
           << 1 - it->second << endl;
  }
}
int main() {
  cin >> N >> M;
  edges.resize(N + 1);
  for (int i = 0; i < M; i++) {
    int u, v, z;
    cin >> u >> v >> z;
    if (u > v) swap(u, v);
    estate[make_pair(u, v)] = z;
    edges[u].push_back(v);
    edges[v].push_back(u);
  }
  getDists();
  backtrack();
  dispAffectedEdges();
  return 0;
}
