#include <bits/stdc++.h>
using namespace std;
struct edge {
  int y, stat;
};
struct query {
  int curNode;
  int curLength;
  int curGood;
};
vector<edge> vec[100005];
pair<long long, long long> best[100005];
long long path[100005], pathStatus[100005];
int n, m;
queue<query> q;
set<pair<int, int> > badRoads;
map<pair<int, int>, int> goodRoads;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    if (z == 1) goodRoads[make_pair(min(x, y), max(x, y))]++;
    x--, y--;
    vec[x].push_back({y, z});
    vec[y].push_back({x, z});
  }
  for (int i = 0; i < n; i++) best[i].first = 1e10;
  q.push({0, 0, 0});
  while (!q.empty()) {
    query ab = q.front();
    q.pop();
    if (best[ab.curNode].first < ab.curLength ||
        (best[ab.curNode].first == ab.curLength &&
         best[ab.curNode].second > ab.curGood))
      continue;
    int vSize = vec[ab.curNode].size();
    for (int i = 0; i < vSize; i++) {
      int nextNode = vec[ab.curNode][i].y;
      int nextGood = vec[ab.curNode][i].stat + ab.curGood;
      if (ab.curLength + 1 < best[nextNode].first ||
          (best[nextNode].first == ab.curLength + 1 &&
           nextGood > best[nextNode].second)) {
        best[nextNode].first = ab.curLength + 1;
        best[nextNode].second = nextGood;
        q.push({nextNode, ab.curLength + 1, nextGood});
        path[nextNode] = ab.curNode;
        pathStatus[nextNode] = vec[ab.curNode][i].stat;
      }
    }
  }
  int myNode = n - 1;
  while (myNode) {
    if (pathStatus[myNode]) {
      int minVal = min(path[myNode] + 1, myNode + 1LL);
      int maxVal = max(path[myNode] + 1, myNode + 1LL);
      goodRoads[make_pair(minVal, maxVal)]--;
    } else
      badRoads.insert({path[myNode] + 1, myNode + 1});
    myNode = path[myNode];
  }
  vector<pair<pair<int, int>, int> > ans;
  for (auto it : badRoads)
    ans.push_back(make_pair(make_pair(it.first, it.second), 1));
  for (auto it : goodRoads) {
    if (it.second == 0) continue;
    for (int i = 0; i < it.second; i++)
      ans.push_back(make_pair(make_pair(it.first.first, it.first.second), 0));
  }
  int curSize = ans.size();
  printf("%d\n", curSize);
  for (int i = 0; i < curSize; i++)
    printf("%d %d %d\n", ans[i].first.first, ans[i].first.second,
           ans[i].second);
}
