#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const long long maxn = 100005;
bool vis[maxn];
long long order[maxn];
long long temp;
long long n, m;
vector<pair<long long, long long> > adj[maxn];
pair<pair<long long, long long>, long long> edges[maxn];
bool detect_cycle(long long s, long long md) {
  vis[s] = true;
  for (auto x : adj[s]) {
    if (x.second >= md) {
      if (vis[x.first] && !order[x.first])
        return false;
      else if (!vis[x.first]) {
        if (!detect_cycle(x.first, md)) return false;
      }
    }
  }
  order[s] = temp;
  temp--;
  return true;
}
bool detect_cycle(long long md) {
  for (long long i = 0, _n = (maxn); i < _n; i++) {
    vis[i] = false;
    order[i] = 0;
  }
  temp = n;
  for (long long i = 0, _n = (n); i < _n; i++) {
    if (!vis[i]) {
      if (!detect_cycle(i, md)) return false;
    }
  }
  return true;
}
int main() {
  ;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(10);
  cin.exceptions(cin.failbit);
  int t = 1;
  while (t--) {
    cin >> n >> m;
    long long x, y, v;
    for (long long i = 0, _n = (m); i < _n; i++) {
      cin >> x >> y >> v;
      x--;
      y--;
      edges[i] = (make_pair(make_pair(x, y), v));
      adj[x].push_back({y, v});
    }
    long long l = 1, r = 1000000001, mid;
    while (l < r) {
      mid = (l + r) / 2;
      if (detect_cycle(mid)) {
        r = mid;
      } else {
        l = mid + 1;
      }
    }
    detect_cycle(l);
    vector<long long> ans;
    for (long long i = 0, _n = (m); i < _n; i++) {
      long long w = edges[i].second;
      long long fr = edges[i].first.first;
      long long to = edges[i].first.second;
      if (order[to] < order[fr]) {
        ans.push_back(i);
      }
    }
    cout << l - 1 << " " << ans.size() << '\n';
    for (auto x : ans) {
      cout << x + 1 << " ";
    }
  };
}
