#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<pair<int, int> > G[N];
int vis[N], ile[N], skad[N], jak[N];
pair<int, int> kra[N];
bool z[N], used[N];
queue<int> kol;
void bfs() {
  vis[1] = 1;
  kol.push(1);
  while (!kol.empty()) {
    int v = kol.front();
    kol.pop();
    for (int i = 0; i < G[v].size(); i++)
      if (vis[G[v][i].first] == 0 ||
          (vis[G[v][i].first] == vis[v] + 1 &&
           ile[G[v][i].first] < ile[v] + z[G[v][i].second])) {
        if (vis[G[v][i].first] == 0) kol.push(G[v][i].first);
        vis[G[v][i].first] = vis[v] + 1;
        ile[G[v][i].first] = ile[v] + z[G[v][i].second];
        skad[G[v][i].first] = v;
        jak[G[v][i].first] = G[v][i].second;
      }
  }
}
int main() {
  int n, m, a, b, c;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &a, &b, &c);
    G[a].push_back(make_pair(b, i));
    G[b].push_back(make_pair(a, i));
    kra[i] = make_pair(a, b);
    z[i] = c;
  }
  bfs();
  int x = n;
  while (x > 1) {
    used[jak[x]] = 1;
    x = skad[x];
  }
  int ile = 0;
  for (int i = 0; i < m; i++)
    if (z[i] != used[i]) ile++;
  printf("%d\n", ile);
  for (int i = 0; i < m; i++)
    if (z[i] != used[i])
      printf("%d %d %d\n", kra[i].first, kra[i].second, used[i]);
}
