#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int M = 1e5 + 5;
vector<pair<int, int>> graph[N];
struct NodeInfo {
  int x, y, z;
  bool operator<(const NodeInfo& b) const {
    if (x < b.x)
      return true;
    else if (x > b.x)
      return false;
    if (y < b.y)
      return true;
    else if (y > b.y)
      return false;
    return z < b.z;
  }
};
set<NodeInfo> path[N];
bool visited[N];
set<pair<int, int>> pathEdges;
int edgeWeight[M];
pair<int, int> edges[M];
void printPath() {
  cout << "Path size: " << (int)pathEdges.size() << "\n";
  for (auto x : pathEdges) {
    cout << "(" << x.first << ", " << x.second << ")\n";
  }
}
struct Result {
  int x, y, z;
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    graph[x].push_back({y, z});
    graph[y].push_back({x, z});
    edges[i] = {min(x, y), max(x, y)};
    edgeWeight[i] = z;
  }
  queue<int> q;
  q.push(1);
  visited[1] = true;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    int ptime, pzero;
    NodeInfo info = *(path[v].begin());
    ptime = info.x;
    pzero = info.y;
    for (auto x : graph[v]) {
      int u = x.first, w = x.second;
      path[u].insert(NodeInfo{ptime + 1, pzero + (w == 0 ? 1 : 0), v});
      if (!visited[u]) {
        visited[u] = true;
        q.push(u);
      }
    }
  }
  int backNode = n;
  while (backNode != 1) {
    int prev;
    NodeInfo info = *(path[backNode].begin());
    prev = info.z;
    pathEdges.insert({min(prev, backNode), max(prev, backNode)});
    backNode = prev;
  }
  vector<Result> path;
  for (int i = 0; i < m; ++i) {
    if (pathEdges.find(edges[i]) != pathEdges.end()) {
      if (edgeWeight[i] == 0) {
        path.push_back(Result{edges[i].first, edges[i].second, 1});
      }
    } else {
      if (edgeWeight[i] == 1) {
        path.push_back(Result{edges[i].first, edges[i].second, 0});
      }
    }
  }
  cout << (int)path.size() << "\n";
  for (auto x : path) {
    cout << x.x << " " << x.y << " " << x.z << "\n";
  }
  return 0;
}
