#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
int n, m;
vector<pair<int, int>> g[N];
int U[N], V[N], W[N];
int top[N];
bool can(int MAX) {
  vector<int> in(n + 1);
  vector<vector<int>> g(n + 1);
  for (int i = 0; i < m; i++) {
    if (W[i] <= MAX) {
      continue;
    }
    g[U[i]].push_back(V[i]);
    in[V[i]]++;
  }
  int l = 0, r = 0;
  for (int i = 1; i <= n; i++) {
    if (in[i] == 0) {
      top[r++] = i;
    }
  }
  while (l < r) {
    int u = top[l++];
    for (auto v : g[u]) {
      in[v]--;
      if (in[v] == 0) {
        top[r++] = v;
      }
    }
  }
  return r == n;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> U[i] >> V[i] >> W[i];
  }
  int lo = 0, hi = 2e9;
  while (lo < hi) {
    int m = (lo + hi) / 2;
    if (can(m)) {
      hi = m;
    } else {
      lo = m + 1;
    }
  }
  can(lo);
  vector<int> pos(n + 1);
  for (int i = 0; i < n; i++) {
    pos[top[i]] = i;
  }
  vector<int> ch;
  cout << lo << " ";
  for (int i = 0; i < m; i++) {
    if (W[i] <= lo) {
      if (pos[U[i]] > pos[V[i]]) {
        ch.push_back(i + 1);
      }
    }
  }
  cout << ch.size() << '\n';
  for (auto v : ch) {
    cout << v << " ";
  }
  cout << '\n';
}
