#include <bits/stdc++.h>
using namespace std;
const int maxn = 101111;
struct node {
  int u, v, w;
};
vector<node> out;
int n, m, dis[maxn], val[maxn], pre[maxn], cant[maxn];
bool vis[maxn];
vector<pair<int, int> > G[maxn], tmp;
map<pair<int, int>, int> mp;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    G[x].push_back(make_pair(y, z));
    G[y].push_back(make_pair(x, z));
    if (x > y) swap(x, y);
    mp[make_pair(x, y)] = z;
  }
  memset(dis, 0x3f3f3f3f, sizeof dis);
  queue<int> q;
  while (!q.empty()) q.pop();
  q.push(1);
  dis[1] = 0;
  vis[1] = true;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = false;
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i].first, w = G[u][i].second;
      if (dis[v] > dis[u] + 1) {
        pre[v] = u;
        dis[v] = dis[u] + 1;
        val[v] = val[u] + w;
        if (!vis[v]) {
          vis[v] = true;
          q.push(v);
        }
      } else if (dis[v] == dis[u] + 1) {
        if (val[v] < val[u] + w) {
          val[v] = val[u] + w;
          pre[v] = u;
        }
      }
    }
  }
  int u = n;
  while (u != 1) {
    int aa = u, bb = pre[u];
    if (aa > bb) swap(aa, bb);
    if (mp[make_pair(aa, bb)] == 0) {
      if (u < pre[u])
        out.push_back((node){u, pre[u], 1});
      else
        out.push_back((node){pre[u], u, 1});
    }
    cant[u] = pre[u];
    u = pre[u];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < G[i].size(); j++) {
      int v = G[i][j].first;
      if (cant[i] != v && cant[v] != i) {
        if (G[i][j].second == 1) {
          if (i < v)
            tmp.push_back(make_pair(i, v));
          else
            tmp.push_back(make_pair(v, i));
        }
      }
    }
  }
  sort(tmp.begin(), tmp.end());
  for (int i = 0; i < tmp.size(); i++) {
    int x = tmp[i].first, y = tmp[i].second;
    if (i == 0)
      out.push_back((node){x, y, 0});
    else {
      if (x != tmp[i - 1].first || y != tmp[i - 1].second) {
        out.push_back((node){x, y, 0});
      }
    }
  }
  cout << out.size() << endl;
  for (int i = 0; i < out.size(); i++) {
    cout << out[i].u << " " << out[i].v << " " << out[i].w << endl;
  }
  return 0;
}
