#include <bits/stdc++.h>
using namespace std;
template <typename T, typename T1>
ostream &operator<<(ostream &out, pair<T, T1> obj) {
  out << "(" << obj.first << "," << obj.second << ")";
  return out;
}
template <typename T, typename T1>
ostream &operator<<(ostream &out, map<T, T1> cont) {
  typename map<T, T1>::const_iterator itr = cont.begin();
  typename map<T, T1>::const_iterator ends = cont.end();
  for (; itr != ends; ++itr) out << *itr << " ";
  out << endl;
  return out;
}
template <typename T>
ostream &operator<<(ostream &out, set<T> cont) {
  typename set<T>::const_iterator itr = cont.begin();
  typename set<T>::const_iterator ends = cont.end();
  for (; itr != ends; ++itr) out << *itr << " ";
  out << endl;
  return out;
}
template <typename T>
ostream &operator<<(ostream &out, multiset<T> cont) {
  typename multiset<T>::const_iterator itr = cont.begin();
  typename multiset<T>::const_iterator ends = cont.end();
  for (; itr != ends; ++itr) out << *itr << " ";
  out << endl;
  return out;
}
template <typename T,
          template <typename ELEM, typename ALLOC = allocator<ELEM>> class CONT>
ostream &operator<<(ostream &out, CONT<T> cont) {
  typename CONT<T>::const_iterator itr = cont.begin();
  typename CONT<T>::const_iterator ends = cont.end();
  for (; itr != ends; ++itr) out << *itr << " ";
  out << endl;
  return out;
}
template <typename T, unsigned int N, typename CTy, typename CTr>
typename enable_if<!is_same<T, char>::value, basic_ostream<CTy, CTr> &>::type
operator<<(basic_ostream<CTy, CTr> &out, const T (&arr)[N]) {
  for (auto i = 0; i < N; ++i) out << arr[i] << " ";
  out << endl;
  return out;
}
template <typename T>
T gcd(T a, T b) {
  T min_v = min(a, b);
  T max_v = max(a, b);
  while (min_v) {
    T temp = max_v % min_v;
    max_v = min_v;
    min_v = temp;
  }
  return max_v;
}
template <typename T>
T lcm(T a, T b) {
  return (a * b) / gcd(a, b);
}
template <typename T>
T fast_exp_pow(T base, T exp, T mod) {
  long long res = 1;
  while (exp) {
    if (exp & 1) {
      res *= base;
      res %= mod;
    }
    exp >>= 1;
    base *= base;
    base %= mod;
  }
  return res;
}
int N, M, X, Y, Z;
int dists[100010], repair[100010];
bool visited[100010];
pair<int, int> parent[100010];
queue<int> que;
vector<pair<int, int>> graph[100010];
vector<tuple<int, int, int>> result;
void bfs() {
  memset(visited, false, sizeof(visited));
  visited[1] = true;
  que.push(1);
  while (!que.empty()) {
    int node = que.front();
    que.pop();
    for (auto elem : graph[node]) {
      int conn_node = elem.first;
      int blown = elem.second;
      int new_dist = dists[node] + 1;
      int curr_repair = repair[node] + (blown ^ 1);
      if (!visited[conn_node]) {
        dists[conn_node] = new_dist;
        repair[conn_node] = curr_repair;
        parent[conn_node] = make_pair(node, blown);
        visited[conn_node] = true;
        que.push(conn_node);
      } else if (dists[conn_node] == new_dist &&
                 repair[conn_node] > curr_repair) {
        parent[conn_node] = make_pair(node, blown);
        repair[conn_node] = curr_repair;
      }
    }
  }
}
int main() {
  scanf("%d%d", &N, &M);
  for (auto i = 1; i <= M; ++i) {
    scanf("%d%d%d", &X, &Y, &Z);
    graph[X].emplace_back(Y, Z);
    graph[Y].emplace_back(X, Z);
  }
  bfs();
  int node = N;
  while (node != 1) {
    int prev_node = parent[node].first;
    int blown = parent[node].second;
    if (!blown) result.push_back(make_tuple(prev_node, node, 1));
    auto pos = find(graph[node].begin(), graph[node].end(),
                    make_pair(prev_node, blown));
    graph[node].erase(pos);
    pos = find(graph[prev_node].begin(), graph[prev_node].end(),
               make_pair(node, blown));
    graph[prev_node].erase(pos);
    node = prev_node;
  }
  for (auto i = 1; i <= N; ++i) {
    for (auto elem : graph[i]) {
      if (elem.second) result.push_back(make_tuple(i, elem.first, 0));
      auto pos = find(graph[elem.first].begin(), graph[elem.first].end(),
                      make_pair(i, elem.second));
      graph[elem.first].erase(pos);
    }
  }
  printf("%d\n", result.size());
  for (auto elem : result)
    cout << get<0>(elem) << " " << get<1>(elem) << " " << get<2>(elem) << endl;
  return 0;
}
