#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<pair<int, int> > > adjList;
map<pair<int, int>, bool> Map;
int from[100001];
bool vis[100001];
int INF = 1000000000;
int dist[100001];
int g[100001];
void bfs() {
  memset(vis, false, sizeof(vis));
  memset(g, 0, sizeof(g));
  memset(from, -1, sizeof(from));
  for (int i = 0; i < n + 1; i++) dist[i] = INF;
  queue<pair<int, int> > q;
  q.push(pair<int, int>(1, 0));
  vis[1] = true;
  dist[1] = 0;
  while (!q.empty()) {
    pair<int, int> front = q.front();
    q.pop();
    int u = front.first;
    int good = front.second;
    if (!(g[u] == good)) {
      continue;
    }
    for (int i = 0; i < adjList[u].size(); i++) {
      int v = adjList[u][i].first;
      int _z = adjList[u][i].second;
      if (!vis[v]) {
        vis[v] = true;
        dist[v] = dist[u] + 1;
        g[v] = _z + good;
        from[v] = u;
        q.push(pair<int, int>(v, _z + good));
      } else if (dist[u] + 1 <= dist[v]) {
        if (g[v] < good + _z) {
          g[v] = _z + good;
          from[v] = u;
          q.push(pair<int, int>(v, _z + good));
        }
      }
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  adjList.resize(n + 1);
  for (int i = 0; i < m; i++) {
    int u, v, z;
    scanf("%d %d %d", &u, &v, &z);
    adjList[u].push_back(pair<int, int>(v, z));
    adjList[v].push_back(pair<int, int>(u, z));
    Map[pair<int, int>(u, v)] = Map[pair<int, int>(v, u)] = z;
  }
  bfs();
  vector<pair<int, pair<int, int> > > res;
  map<pair<int, int>, bool> pass;
  int v = n;
  while (from[v] != -1) {
    int u = from[v];
    pass[pair<int, int>(u, v)] = pass[pair<int, int>(v, u)] = true;
    if (!Map[pair<int, int>(u, v)]) {
      res.push_back(pair<int, pair<int, int> >(u, pair<int, int>(v, 1)));
    }
    v = u;
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = 0; j < adjList[i].size(); j++) {
      int v = adjList[i][j].first;
      if (pass[pair<int, int>(i, v)]) continue;
      if (Map[pair<int, int>(i, v)]) {
        res.push_back(pair<int, pair<int, int> >(i, pair<int, int>(v, 0)));
        pass[pair<int, int>(i, v)] = pass[pair<int, int>(v, i)] = true;
      }
    }
  }
  printf("%ld\n", res.size());
  for (int i = 0; i < res.size(); i++) {
    printf("%d %d %d\n", res[i].first, res[i].second.first,
           res[i].second.second);
  }
  return 0;
}
