#include <bits/stdc++.h>
using namespace std;
long long n, m, col[200005], fo, cost[200005], done[200005], vis[200005];
vector<pair<long long, long long> > adj[200005];
vector<long long> ts;
void dfs(long long x, long long v) {
  col[x] = 1;
  for (auto &y : adj[x]) {
    if (cost[y.second] > v) {
      if (col[y.first] == 1) {
        fo = 1;
        return;
      } else if (col[y.first] == 0)
        dfs(y.first, v);
    }
  }
  col[x] = 2;
}
long long valid(long long v) {
  fo = 0;
  memset(col, 0, sizeof col);
  for (long long i = 1; i < n + 1; ++i) {
    if (!fo) dfs(i, v);
  }
  return (fo ^ 1);
}
void tsort(long long x, long long v) {
  if (done[x]) return;
  done[x] = 1;
  for (auto &y : adj[x]) {
    if (cost[y.second] > v) {
      tsort(y.first, v);
    }
  }
  ts.push_back(x);
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (long long i = 1; i < m + 1; ++i) {
    long long u, v;
    cin >> u >> v >> cost[i];
    adj[u].push_back({v, i});
  }
  long long lo = 0, hi = (long long)1e18;
  while (lo < hi) {
    long long mid = (lo + hi) / 2;
    if (valid(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  for (long long i = 1; i < n + 1; ++i) tsort(i, lo);
  reverse(ts.begin(), ts.end());
  vector<long long> anss;
  for (long long i = 0; i < (long long)ts.size(); ++i) {
    for (auto &y : adj[ts[i]]) {
      if (cost[y.second] <= lo && vis[y.first]) anss.push_back(y.second);
    }
    vis[ts[i]] = 1;
  }
  cout << lo << " " << (long long)anss.size() << "\n";
  for (auto &x : anss) cout << x << " ";
  return 0;
}
