#include <bits/stdc++.h>
using namespace std;
long long int bigm(long long int a, long long int b) {
  if (b == 0) return 1;
  if (b % 2) return (a * bigm(a, b - 1)) % 1000000007;
  long long int c = bigm(a, b / 2);
  return (c * c) % 1000000007;
}
vector<vector<int> > adj;
vector<vector<int> > cost;
vector<vector<int> > link;
struct edges {
  int u, v, w;
  edges() {}
  edges(int a, int b, int c) {
    u = a;
    v = b;
    w = c;
  }
} edge[100010];
int mark[100100];
int main() {
  int n, m;
  cin >> n >> m;
  adj.assign(n + 1, vector<int>());
  cost.assign(n + 1, vector<int>());
  link.assign(n + 1, vector<int>());
  int s1 = 0, s2 = 0;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    c = 1 - c;
    if (c == 1)
      s1++;
    else
      s2++;
    adj[a].push_back(b);
    adj[b].push_back(a);
    cost[a].push_back(c);
    cost[b].push_back(c);
    edge[i] = edges(a, b, c);
    link[a].push_back(i);
    link[b].push_back(i);
  }
  vector<pair<int, int> > dist(n + 1, pair<int, int>(1000000, 1000000));
  vector<int> par(n + 1, 0);
  vector<int> paredge(n + 1, 0);
  priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int> >,
                 greater<pair<pair<int, int>, int> > >
      pq;
  pq.push(pair<pair<int, int>, int>(pair<int, int>(0, 0), 1));
  dist[1] = pair<int, int>(0, 0);
  while (!pq.empty()) {
    pair<pair<int, int>, int> temp = pq.top();
    pq.pop();
    int u = temp.second;
    pair<int, int> c = temp.first;
    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i];
      int w = cost[u][i];
      pair<int, int> dd(c.first + 1, c.second + w);
      if (dd < dist[v]) {
        dist[v] = dd;
        par[v] = u;
        paredge[v] = link[u][i];
        pq.push(pair<pair<int, int>, int>(dd, v));
      }
    }
  }
  int u = n;
  while (u != 1) {
    int v = par[u];
    mark[paredge[u]] = 2;
    if (edge[paredge[u]].w == 1) mark[paredge[u]] = 3;
    u = v;
  }
  for (int i = 0; i < m; i++)
    if (mark[i] == 0 && edge[i].w == 0) mark[i] = 3;
  int ans = 0;
  for (int i = 0; i < m; i++)
    if (mark[i] == 3) ans++;
  cout << ans << endl;
  for (int i = 0; i < m; i++)
    if (mark[i] == 3) {
      printf("%d %d %d\n", edge[i].u, edge[i].v, edge[i].w);
    }
  return 0;
}
