#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
int64_t fx[4] = {0, 1, 0, -1};
int64_t fy[4] = {1, 0, -1, 0};
const long long M = 3e5 + 10, M2 = 1e6 + 10, oo = 1e9 + 7, mod = 998244353;
const long long MC = (1 << 22) + 5;
int64_t n, m, timein[M], timeout[M], clr[M];
vector<int64_t> adj[M], ans;
vector<pair<int64_t, pair<int64_t, int64_t> > > edges;
int64_t tt;
void init() {
  tt = 1;
  ans.clear();
  for (int64_t i = 0; i <= n; i++) {
    adj[i].clear();
    timein[i] = 0;
    timeout[i] = 0;
    clr[i] = 0;
  }
}
bool dfs(int64_t u) {
  clr[u] = 1;
  timein[u] = tt++;
  bool ret = 1;
  for (int64_t v : adj[u]) {
    if (clr[v] == 2) continue;
    if (clr[v] == 1) {
      ret = 0;
      continue;
    }
    ret &= dfs(v);
  }
  timeout[u] = tt++;
  clr[u] = 2;
  return ret;
}
bool can(int64_t val) {
  init();
  for (pair<int64_t, pair<int64_t, int64_t> > &e : edges) {
    if (e.first > val) {
      int64_t u = (e.second).first, v = (e.second).second;
      adj[u].push_back(v);
    }
  }
  int64_t ok = 1;
  for (int64_t i = 1; i <= n; i++) {
    if (clr[i] == 0) ok &= dfs(i);
  }
  return ok;
}
void getans(int64_t val) {
  can(val);
  int64_t id = 1;
  for (pair<int64_t, pair<int64_t, int64_t> > &e : edges) {
    if (e.first <= val) {
      int64_t u = (e.second).first, v = (e.second).second;
      if (timeout[v] > timeout[u]) {
        ans.push_back(id);
      }
    }
    id++;
  }
}
void precomp() {}
void solve() {
  cin >> n >> m;
  for (int64_t i = 0, u, v, c; i < m; i++) {
    cin >> u >> v >> c;
    edges.push_back(make_pair(c, pair<int64_t, int64_t>(u, v)));
  }
  int64_t lo = 0, hi = oo;
  while (lo < hi) {
    int64_t mid = (lo + hi) / 2;
    if (can(mid)) {
      hi = mid;
    } else
      lo = mid + 1;
  }
  getans(lo);
  cout << lo << " " << ans.size() << '\n';
  for (int64_t o : ans) {
    cout << o << " ";
  }
  cout << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  precomp();
  solve();
  return 0;
}
