#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  long long l = v.size();
  for (long long i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
template <typename T>
void trace(const char* name, T&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
template <typename T, typename U>
std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) {
  return {l.first + r.first, l.second + r.second};
}
const long long N = 1e5 + 100;
vector<vector<pair<long long, long long> > > g(N);
long long n, m;
vector<pair<long long, long long> > d(N, {1000000000000000001,
                                          1000000000000000001});
vector<long long> p(N);
void dijistra(long long s) {
  set<pair<pair<long long, long long>, long long> > q;
  d[s] = make_pair(0, 0);
  q.insert(make_pair(d[s], s));
  while (!q.empty()) {
    long long v = (*q.begin()).second;
    auto v_d = (*q.begin()).first;
    q.erase(q.begin());
    for (auto t : g[v]) {
      long long to = t.first;
      auto weight = make_pair(1LL, t.second);
      auto get_out = v_d + weight;
      if (get_out < d[to]) {
        d[to] = get_out;
        q.insert(make_pair(get_out, to));
        p[to] = v;
      }
    }
  }
}
int32_t main() {
  cin >> n >> m;
  map<pair<long long, long long>, long long> edg, sp;
  for (long long i = 0; i < m; i++) {
    long long v, u, w;
    cin >> v >> u >> w;
    w ^= 1;
    g[u].push_back({v, w});
    g[v].push_back({u, w});
    edg[{min(v, u), max(v, u)}] = w;
  }
  dijistra(1);
  long long curr = n;
  vector<pair<pair<long long, long long>, long long> > ans;
  while (curr != 1) {
    long long t = p[curr];
    if (edg[{min(curr, t), max(curr, t)}] == 1) {
      ans.push_back(make_pair(make_pair(curr, t), 1));
    }
    sp[{min(curr, t), max(curr, t)}] = 1;
    curr = t;
  }
  for (auto e : edg) {
    if (!sp.count(e.first) && e.second == 0) {
      ans.push_back(make_pair(e.first, 0));
    }
  }
  cout << (long long)ans.size() << "\n";
  for (auto i : ans) {
    cout << i.first.first << " " << i.first.second << " " << i.second << "\n";
  }
}
