#include <bits/stdc++.h>
using namespace std;
long long oo = 0x3f3f3f3f3f3f3f3f;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int>>> g(n);
  vector<pair<pair<int, int>, int>> edges;
  for (int i = 0, a, b, c; i < m; ++i) {
    cin >> a >> b >> c;
    --a, --b;
    edges.emplace_back(pair<int, int>{a, b}, c);
    g[a].push_back({b, c});
  }
  bool ok = true;
  long long mid = oo;
  vector<int> order;
  function<bool()> valid = [&]() {
    order.clear();
    stack<int> empty;
    vector<int> indeg(n);
    for (int i = 0; i < n; ++i) {
      for (auto &p : g[i])
        if (p.second > mid) indeg[p.first]++;
    }
    for (int i = 0; i < n; ++i)
      if (indeg[i] == 0) empty.push(i);
    int cnt = 0;
    while ((int)empty.size()) {
      int t = empty.top();
      empty.pop();
      order.push_back(t);
      ++cnt;
      for (auto &p : g[t]) {
        if (p.second > mid) {
          indeg[p.first]--;
          if (indeg[p.first] == 0) empty.push(p.first);
        }
      }
    }
    return cnt == n;
  };
  long long lo = 0, hi = oo;
  while (lo < hi) {
    mid = (lo + hi) / 2;
    if (valid())
      hi = mid;
    else
      lo = mid + 1;
  }
  mid = lo;
  valid();
  int t = 0;
  vector<int> inverse(n);
  for (int i = 0; i < n; ++i) inverse[order[i]] = i;
  vector<int> ans;
  for (int i = 0, a, b, c; i < (int)edges.size(); ++i) {
    a = edges[i].first.first;
    b = edges[i].first.second;
    c = edges[i].second;
    if (inverse[a] > inverse[b] && c <= lo) ans.push_back(i);
  }
  cout << lo << " " << ans.size() << '\n';
  for (int i = 0; i < (int)ans.size(); ++i)
    cout << ans[i] + 1 << " \n"[i + 1 == (int)ans.size()];
}
