#include <bits/stdc++.h>
using namespace std;
int n, m;
int dis[100009], par[100009], road[100009];
vector<pair<int, int> > v[100009];
queue<pair<int, int> > q;
set<pair<int, int> > s;
vector<pair<int, int> > res;
pair<int, int> dif(int x, int y) {
  if (x > y) swap(x, y);
  return {x, y};
}
int main() {
  scanf("%d%d", &n, &m);
  while (m--) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    v[a].push_back({b, c});
    v[b].push_back({a, c});
    if (a > b) swap(a, b);
    if (c) s.insert({a, b});
  }
  memset(dis, 0x3f, sizeof(dis));
  q.push({1, 0});
  dis[1] = 0;
  while (!q.empty()) {
    int cur = q.front().first, is = q.front().second;
    q.pop();
    if (cur == n) break;
    for (auto next : v[cur]) {
      int nxt = next.first;
      int is1 = next.second;
      if (dis[nxt] > dis[cur] + 1) {
        dis[nxt] = dis[cur] + 1;
        par[nxt] = cur;
        road[nxt] = is + !is1;
        q.push({nxt, road[nxt]});
      } else if (dis[nxt] == dis[cur] + 1 && road[nxt] > is + !is1) {
        dis[nxt] = dis[cur] + 1;
        par[nxt] = cur;
        road[nxt] = is + !is1;
        q.push({nxt, road[nxt]});
      }
    }
  }
  int x = n;
  while (x != 1) {
    if (s.count(dif(x, par[x])))
      s.erase(dif(x, par[x]));
    else
      res.push_back({x, par[x]});
    x = par[x];
  }
  printf("%d\n", s.size() + res.size());
  for (auto pp : res) printf("%d %d 1\n", pp.first, pp.second);
  for (auto pp : s) printf("%d %d 0\n", pp.first, pp.second);
  return 0;
}
