#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
vector<pair<int, int>> G[N];
struct info {
  int node, val;
  bool operator<(const info &A) const { return A.val < val; }
};
priority_queue<info> Q;
int n, m, dis[N], dis2[N], pr[N];
void run1() {
  for (int i = 1; i <= n; i++) dis[i] = 1e9;
  Q.push({1, 0});
  dis[1] = 0;
  while (!Q.empty()) {
    info P = Q.top();
    Q.pop();
    if (dis[P.node] != P.val) continue;
    for (int i = 0; i < G[P.node].size(); i++) {
      int go = G[P.node][i].first;
      if (dis[P.node] + 1 < dis[go]) {
        dis[go] = dis[P.node] + 1;
        Q.push({go, dis[go]});
      }
    }
  }
}
void run2() {
  for (int i = 1; i <= n; i++) dis2[i] = 1e9;
  Q.push({n, 0});
  dis2[n] = 0;
  while (!Q.empty()) {
    info P = Q.top();
    Q.pop();
    if (dis2[P.node] != P.val) continue;
    for (int i = 0; i < G[P.node].size(); i++) {
      int go = G[P.node][i].first;
      int c = 1 - G[P.node][i].second;
      if (dis[P.node] - 1 != dis[go]) continue;
      if (dis2[P.node] + c < dis2[go]) {
        dis2[go] = dis2[P.node] + c;
        Q.push({go, dis2[go]});
        pr[go] = P.node;
      }
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y, z;
    ;
    scanf("%d %d %d", &x, &y, &z);
    G[x].push_back(make_pair(y, z));
    G[y].push_back(make_pair(x, z));
  }
  run1();
  run2();
  int node = 1;
  map<int, map<int, int>> mp;
  vector<pair<pair<int, int>, int>> ans;
  while (node != n) {
    int go = pr[node];
    mp[node][go] = mp[go][node] = 1;
    if (dis2[go] != dis2[node])
      ans.push_back(make_pair(make_pair(node, go), 1));
    node = go;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < G[i].size(); j++) {
      int go = G[i][j].first;
      if (G[i][j].second == 0) continue;
      if (mp[go][i]) continue;
      mp[go][i] = mp[i][go] = 1;
      ans.push_back(make_pair(make_pair(i, go), 0));
    }
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++) {
    printf("%d %d %d\n", ans[i].first.first, ans[i].first.second,
           ans[i].second);
  }
}
