#include <bits/stdc++.h>
const int maxBufSize = (10000000);
using namespace std;
long long int n, m;
vector<pair<long long int, long long int> > v[100005];
pair<long long int, long long int> p[100005], pred[100005];
queue<long long int> q;
long long int vis[100005];
pair<pair<long long int, long long int>, long long int> ans[100005];
set<pair<pair<long long int, long long int>, long long int> > S;
int main() {
  long long int i, j, a, b, c, h, n, d, tot;
  pair<long long int, long long int> temp;
  cin >> n >> m;
  tot = 0;
  for (i = 1; i <= m; ++i) {
    cin >> a >> b >> c;
    temp.first = b, temp.second = c;
    v[a].push_back(temp);
    temp.first = a;
    v[b].push_back(temp);
    if (c == 0) {
      tot++;
    }
  }
  for (i = 1; i <= n; ++i) {
    p[i].first = 1000000000000000000ll, p[i].second = 0;
  }
  q.push(n);
  p[n].first = 0, p[n].second = 0;
  while (!q.empty()) {
    a = q.front();
    q.pop();
    b = v[a].size();
    for (i = 0; i <= b - 1; ++i) {
      if (p[v[a][i].first].first > (p[a].first + 1)) {
        p[v[a][i].first].first = p[a].first + 1;
        p[v[a][i].first].second = p[a].second;
        pred[v[a][i].first].first = a;
        pred[v[a][i].first].second = v[a][i].second;
        if (v[a][i].second == 0) {
          p[v[a][i].first].second++;
        }
        q.push(v[a][i].first);
      } else if (p[v[a][i].first].first == (p[a].first + 1)) {
        c = p[v[a][i].first].second;
        d = p[a].second;
        if (v[a][i].second == 0) {
          d++;
        }
        if (d < c) {
          p[v[a][i].first].second = d;
          pred[v[a][i].first].first = a;
          pred[v[a][i].first].second = v[a][i].second;
        }
      }
    }
  }
  long long int r1, r2;
  r1 = r2 = 0;
  a = 1;
  j = 0;
  while (pred[a].first != 0) {
    b = pred[a].first;
    c = pred[a].second;
    if (c == 0) {
      r1++;
    } else {
      r2++;
    }
    ans[j + 1].first.first = b, ans[j + 1].first.second = a;
    ans[j + 1].second = c;
    a = b;
    j++;
  }
  pair<pair<long long int, long long int>, long long int> tp, tp1, tp2;
  for (i = 1; i <= j; ++i) {
    tp.first.first = ans[i].first.first;
    tp.first.second = ans[i].first.second;
    tp.second = ans[i].second;
    S.insert(tp);
  }
  cout << m - tot + r1 - r2 << "\n";
  for (i = 1; i <= n; ++i) {
    b = v[i].size();
    for (j = 0; j <= b - 1; ++j) {
      if (v[i][j].first > i) {
        tp1.first.first = i, tp1.first.second = v[i][j].first,
        tp1.second = v[i][j].second;
        tp2.first.second = i, tp2.first.first = v[i][j].first,
        tp2.second = v[i][j].second;
        if ((v[i][j].second == 0)) {
          if ((S.find(tp1) != S.end()) || (S.find(tp2) != S.end())) {
            cout << i << " " << v[i][j].first << " " << (v[i][j].second + 1) % 2
                 << "\n";
          }
        } else if (v[i][j].second == 1) {
          if ((S.find(tp1) == S.end()) && (S.find(tp2) == S.end())) {
            cout << i << " " << v[i][j].first << " " << (v[i][j].second + 1) % 2
                 << "\n";
          }
        }
      }
    }
  }
  return 0;
}
