#include <bits/stdc++.h>
using namespace std;
struct Road {
  int from, to;
  bool working, change;
};
struct CityRoad {
  int city, index;
  bool working;
};
struct City {
  vector<CityRoad> roads;
  int distance = -1, working, previous, road;
};
int main() {
  ios::sync_with_stdio(false);
  int cities, roads, workingRoads = 0;
  cin >> cities >> roads;
  vector<City> graph(cities + 1);
  vector<Road> allRoads(roads);
  for (int index = 0; index < roads; ++index) {
    cin >> allRoads[index].from >> allRoads[index].to >>
        allRoads[index].working;
    allRoads[index].change = allRoads[index].working;
    graph[allRoads[index].from].roads.push_back(
        {allRoads[index].to, index, allRoads[index].working});
    graph[allRoads[index].to].roads.push_back(
        {allRoads[index].from, index, allRoads[index].working});
    workingRoads += allRoads[index].working;
  }
  graph[1].distance = 0;
  queue<int> toVisit;
  toVisit.push(1);
  int shortest = 0, mostWorking = 0;
  while (!toVisit.empty()) {
    if (shortest && graph[toVisit.front()].distance > shortest) {
      break;
    }
    if (toVisit.front() == cities) {
      shortest = graph[toVisit.front()].distance;
      if (!mostWorking ||
          graph[toVisit.front()].working > graph[mostWorking].working) {
        mostWorking = toVisit.front();
      }
    }
    for (CityRoad& road : graph[toVisit.front()].roads) {
      if (graph[road.city].distance < 0) {
        graph[road.city].distance = graph[toVisit.front()].distance + 1;
        graph[road.city].working =
            graph[toVisit.front()].working + road.working;
        graph[road.city].previous = toVisit.front();
        graph[road.city].road = road.index;
        toVisit.push(road.city);
      } else if (graph[road.city].distance ==
                     graph[toVisit.front()].distance + 1 &&
                 graph[toVisit.front()].working + road.working >
                     graph[road.city].working) {
        graph[road.city].working =
            graph[toVisit.front()].working + road.working;
        graph[road.city].previous = toVisit.front();
        graph[road.city].road = road.index;
      }
    }
    toVisit.pop();
  }
  for (int city = mostWorking; city != 1; city = graph[city].previous) {
    allRoads[graph[city].road].change = !allRoads[graph[city].road].working;
  }
  cout << workingRoads - graph[mostWorking].working + shortest -
              graph[mostWorking].working
       << '\n';
  for (Road& road : allRoads) {
    if (road.change) {
      cout << road.from << ' ' << road.to << ' ' << !road.working << '\n';
    }
  }
  return 0;
}
