#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const long long INFL = LLONG_MAX;
const long double pi = acos(-1);
vector<pair<int, int> > adj[100100];
map<int, int> edges[100100];
int N, M;
int X[100100];
int Y[100100];
int original[100100];
int newstate[100100];
int P[100100];
int was[100100];
long long dist[100100];
int main() {
  ios_base::sync_with_stdio(0);
  cout.precision(15);
  cout << fixed;
  cout.tie(0);
  cin >> N >> M;
  for (int(i) = 1, j123 = M; (i) <= j123; (i)++) {
    cin >> X[i] >> Y[i] >> original[i];
    adj[X[i]].push_back(make_pair(Y[i], 100100 + (1 - original[i])));
    adj[Y[i]].push_back(make_pair(X[i], 100100 + (1 - original[i])));
    edges[X[i]][Y[i]] = original[i];
    edges[Y[i]][X[i]] = original[i];
  }
  for (int(i) = 1, j123 = N; (i) <= j123; (i)++) dist[i] = INFL;
  dist[1] = 0;
  priority_queue<pair<long long, int> > pq;
  pq.push(make_pair(-0, 1));
  while (!pq.empty()) {
    int u = pq.top().second;
    pq.pop();
    if (was[u]) continue;
    was[u] = 1;
    for (int(i) = 0, j123 = int(adj[u].size()); (i) < j123; (i)++) {
      int v = adj[u][i].first;
      long long w = adj[u][i].second;
      long long alt = dist[u] + w;
      if (alt < dist[v]) {
        dist[v] = alt;
        P[v] = u;
        pq.push(make_pair(-alt, v));
      }
    }
  }
  vector<int> route;
  int current = N;
  while (current >= 1) {
    route.push_back(current);
    current = P[current];
  }
  reverse(route.begin(), route.end());
  set<pair<int, int> > st;
  for (int(i) = 0, j123 = int(route.size()); (i) < j123; (i)++) {
    if (i + 1 == int(route.size())) break;
    int u = route[i];
    int v = route[i + 1];
    if (u > v) swap(u, v);
    st.insert(make_pair(u, v));
  }
  int cnt = 0;
  stringstream ss;
  for (int(i) = 1, j123 = M; (i) <= j123; (i)++) {
    int u = X[i];
    int v = Y[i];
    if (u > v) swap(u, v);
    if (original[i] == (st.find(make_pair(u, v)) != st.end())) continue;
    cnt++;
    ss << u << " " << v << " " << (1 ^ original[i]) << '\n';
  }
  cout << cnt << '\n' << ss.str();
}
