#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void si(T &x) {
  register int c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c<48 | c> 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
template <class T>
inline T bigmod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
void IN() {
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
}
const int N = 1e5 + 5;
int n, m;
struct Node {
  int dist, val, id;
  bool operator<(const Node &a) const {
    if (dist == a.dist)
      return val > a.val;
    else
      return dist < a.dist;
  }
};
int d[N], da[N];
map<pair<int, int>, bool> path;
vector<Node> T;
int P[N];
bool vis[N];
vector<pair<int, int> > G[N];
void dij() {
  queue<int> q;
  memset(da, 63, sizeof(da));
  q.push(1);
  vis[1] = 1;
  d[1] = 0;
  da[1] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto a : G[u]) {
      if (da[a.first] > 1 + da[u] ||
          (da[a.first] == 1 + da[u] && d[a.first] < a.second + d[u])) {
        da[a.first] = 1 + da[u];
        d[a.first] = a.second + d[u];
        q.push(a.first);
        P[a.first] = u;
      }
    }
  }
  int dest = n;
  while (dest != 1) {
    int k = P[dest];
    if (path[make_pair(dest, k)] == 0) {
      T.push_back({dest, k, 1});
    }
    path.erase(make_pair(dest, k));
    path.erase(make_pair(k, dest));
    dest = k;
  }
}
int main() {
  si(n);
  si(m);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    si(a);
    si(b);
    si(c);
    path[make_pair(a, b)] = c;
    path[make_pair(b, a)] = c;
    G[a].push_back((make_pair(b, c)));
    G[b].push_back((make_pair(a, c)));
  }
  dij();
  set<pair<int, int> > S;
  for (auto a : path)
    if (a.second == 1)
      S.insert(
          make_pair(((a.first.first) > (a.first.second) ? (a.first.second)
                                                        : (a.first.first)),
                    ((a.first.first) > (a.first.second) ? (a.first.first)
                                                        : (a.first.second))));
  cout << T.size() + S.size() << endl;
  for (auto a : T) printf("%d %d %d\n", a.dist, a.val, a.id);
  for (auto a : S)
    printf("%d %d %d\n", a.first, a.second,
           1 - path[make_pair(a.first, a.second)]);
  return 0;
}
