#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, m;
vector<int> g[N];
pair<pair<int, int>, int> edges[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    edges[i] = make_pair(make_pair(u, v), w);
  }
  vector<int> oredered(n + 1), oldOrdered = oredered;
  int low = 0, high = 1e9, ans = 1e9;
  while (low <= high) {
    int k = (low + high) >> 1;
    vector<int> deg(n + 1, 0);
    oldOrdered = oredered;
    for (int i = 1; i <= m; ++i) {
      if (edges[i].second > k) {
        g[edges[i].first.first].push_back(edges[i].first.second);
        ++deg[edges[i].first.second];
      }
    }
    queue<int> qu;
    for (int i = 1; i <= n; ++i)
      if (deg[i] == 0) {
        qu.push(i);
      }
    int cnt = 0;
    while (!qu.empty()) {
      int x = qu.front();
      qu.pop();
      oredered[x] = ++cnt;
      for (int v : g[x])
        if (--deg[v] == 0) {
          qu.push(v);
        }
    }
    if (cnt == n) {
      ans = k;
      high = k - 1;
    } else {
      low = k + 1;
      oredered = oldOrdered;
    }
    for (int i = 1; i <= n; ++i) g[i].clear();
  }
  vector<int> res;
  for (int i = 1; i <= m; ++i) {
    if (edges[i].second <= ans &&
        oredered[edges[i].first.first] > oredered[edges[i].first.second]) {
      res.push_back(i);
    }
  }
  cout << ans << " " << res.size() << endl;
  for (int x : res) cout << x << " ";
  return 0;
}
