#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int n, m, in[maxn], top[maxn];
vector<int> ee[maxn];
struct node {
  int s, e, w;
} ed[maxn];
bool pd(int mid) {
  int cnt = 0;
  queue<int> q;
  for (int i = 1; i <= n; ++i) ee[i].clear();
  memset(in, 0, sizeof(in));
  for (int i = 1; i <= m; ++i) {
    if (ed[i].w > mid) {
      ee[ed[i].s].push_back(ed[i].e);
      in[ed[i].e]++;
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (!in[i]) {
      q.push(i);
      top[i] = ++cnt;
    }
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < (int)ee[u].size(); ++i) {
      int t = ee[u][i];
      --in[t];
      if (!in[t]) q.push(t), top[t] = ++cnt;
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (in[i]) return false;
  }
  return true;
}
int main() {
  std::ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> ed[i].s >> ed[i].e >> ed[i].w;
  }
  int l = 0, r = 0x3f3f3f3f, res;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (pd(mid))
      r = mid - 1, res = mid;
    else
      l = mid + 1;
  }
  pd(res);
  vector<int> ans;
  for (int i = 1; i <= m; ++i) {
    if (ed[i].w <= res && top[ed[i].s] > top[ed[i].e]) {
      ans.push_back(i);
    }
  }
  cout << res << " " << (int)ans.size() << endl;
  for (int i = 0; i < (int)ans.size(); ++i) {
    cout << ans[i] << " ";
  }
  return 0;
}
