#include <bits/stdc++.h>
#pragma comment(linker, "/stack:30000000")
using namespace std;
using namespace std;
int i, j, k, n, t, m, u, v, x;
int dis[100010], par[100010], change[100010], vis[100010], dp[100010];
vector<pair<int, int> > X[100010];
vector<pair<pair<int, int>, int> > edge;
void bfs(int u) {
  queue<int> Q;
  Q.push(u);
  for (int i = 0; i < 100010; i++) dis[i] = 2000000000;
  par[1] = -1;
  dis[1] = 0;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i = 0; i < X[u].size(); i++) {
      int indx = X[u][i].second;
      int v = X[u][i].first;
      if (dis[v] > dis[u] + 1) {
        par[v] = u;
        dis[v] = dis[u] + 1;
        change[v] = indx;
        dp[v] = dp[u] + edge[indx].second;
        Q.push(v);
      } else if (dis[v] == dis[u] + 1 && dp[v] < dp[u] + edge[indx].second) {
        par[v] = u;
        change[v] = indx;
        dp[v] = dp[u] + edge[indx].second;
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &u, &v, &x);
    X[u].push_back(make_pair(v, i));
    X[v].push_back(make_pair(u, i));
    edge.push_back(make_pair(make_pair(u, v), x));
  }
  bfs(1);
  int end = n;
  while (par[end] > -1) {
    vis[change[end]] = 1;
    end = par[end];
  }
  vector<pair<pair<int, int>, int> > ans;
  for (int i = 0; i < m; i++)
    if (vis[i] != edge[i].second)
      ans.push_back(edge[i]), ans.back().second ^= 1;
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first.first << " " << ans[i].first.second << " "
         << ans[i].second << endl;
}
