#include <bits/stdc++.h>
using namespace std;
long long int n, m;
long long int dist[100005];
pair<long long int, long long int> from[100005];
long long int func[100005];
vector<long long int> atdist[100005], path, change;
vector<pair<long long int, long long int> > adj[100005], adj1[100005];
struct road {
  long long int x;
  long long int y;
  long long int z;
};
road e[100005];
queue<long long int> q;
void bfs() {
  for (int i = 1; i <= n; i++) dist[i] = 1e18;
  dist[1] = 0;
  atdist[0].push_back(1);
  q.push(1);
  while (!q.empty()) {
    long long int i = q.front();
    long long int d = dist[i];
    q.pop();
    for (auto j : adj[i]) {
      if (dist[j.first] > d + 1) {
        dist[j.first] = d + 1;
        atdist[dist[j.first]].push_back(j.first);
        q.push(j.first);
      }
    }
  }
}
int main() {
  scanf("%lld", &n);
  scanf("%lld", &m);
  for (int i = 1; i <= m; i++) {
    long long int x, y, z;
    scanf("%lld", &x);
    scanf("%lld", &y);
    scanf("%lld", &z);
    adj[x].push_back(make_pair(y, i));
    adj[y].push_back(make_pair(x, i));
    e[i] = {x, y, z};
  }
  bfs();
  for (int i = 0; i <= n; i++)
    for (auto j : atdist[i])
      for (auto j1 : adj[j])
        if (dist[j1.first] == dist[j] + 1)
          adj1[j1.first].push_back(make_pair(j, j1.second));
  for (int i = 1; i <= n; i++) {
    for (auto j : atdist[i]) {
      for (auto j1 : adj1[j]) {
        long long int f, to, in;
        f = j1.first;
        to = j;
        in = j1.second;
        if (func[f] + e[in].z >= func[to]) {
          func[to] = func[f] + e[in].z;
          from[to] = make_pair(f, in);
        }
      }
    }
  }
  long long int cur = n;
  while (cur != 1) {
    path.push_back(from[cur].second);
    cur = from[cur].first;
  }
  for (auto j : path) {
    if (!e[j].z)
      change.push_back(j);
    else
      e[j].z = 2;
  }
  for (int i = 1; i <= m; i++) {
    if (e[i].z == 1) change.push_back(i);
  }
  long long int an = change.size();
  printf("%lld\n", an);
  for (auto j : change)
    printf("%lld %lld %lld\n", e[j].x, e[j].y, (e[j].z ^ 1));
  return 0;
}
