#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
const int MAXN = 1e5 + 100;
int n, m, maks, mins;
vector<pair<int, int> > v[MAXN];
vector<int> idx[MAXN];
int kon[MAXN];
bool bisa;
vector<int> tmp[MAXN];
vector<pair<int, int> > res;
int nmr[MAXN], tot;
void dfs(int x) {
  if (bisa == false || kon[x] == 2) return;
  if (kon[x] == 1) {
    bisa = false;
    return;
  }
  kon[x] = 1;
  for (int i = 0; i < tmp[x].size(); i++) {
    dfs(tmp[x][i]);
  }
  kon[x] = 2;
  res.push_back(make_pair(x, 0));
}
bool proses(int x) {
  for (int i = 0; i < n; i++) tmp[i].clear();
  for (int i = 0; i < n; i++)
    for (int j = 0; j < v[i].size(); j++) {
      if (v[i][j].second > x) tmp[i].push_back(v[i][j].first);
    }
  memset(kon, 0, sizeof kon);
  bisa = true;
  res.clear();
  for (int i = 0; i < n; i++)
    if (kon[i] == 0 && bisa) dfs(i);
  reverse(res.begin(), res.end());
  for (int i = 0; i < res.size(); i++) nmr[res[i].first] = i;
  tot = 0;
  res.clear();
  for (int i = 0; i < n; i++)
    for (int j = 0; j < v[i].size(); j++) {
      if (nmr[i] < nmr[v[i][j].first]) continue;
      tot++;
      res.push_back(make_pair(idx[i][j], 0));
    }
  return bisa;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  int eaea = 1;
  while (m--) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    v[a].push_back(make_pair(b, c));
    idx[a].push_back(eaea++);
    maks = max(maks, c);
  }
  int kiri = 0, kanan = maks;
  int ree = 0, total;
  vector<pair<int, int> > ans;
  while (kiri <= kanan) {
    int tengah = (kiri + kanan) >> 1;
    if (proses(tengah)) {
      total = tot;
      ans = res;
      ree = tengah;
      kanan = tengah - 1;
    } else
      kiri = tengah + 1;
  }
  cout << ree << ' ' << total << '\n';
  for (int i = 0; i < total; i++) cout << ans[i].first << ' ';
}
