#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, m;
struct node {
  int from, to, w;
} edge[maxn];
int in[maxn];
vector<int> e[maxn];
int top[maxn];
bool topsort(int mid) {
  memset(in, 0, sizeof(in));
  int cnt = 0;
  queue<int> q;
  for (int i = 1; i <= n; ++i) e[i].clear();
  for (int i = 1; i <= m; ++i) {
    if (edge[i].w > mid)
      e[edge[i].from].push_back(edge[i].to), in[edge[i].to]++;
  }
  for (int i = 1; i <= n; ++i) {
    if (!in[i]) {
      q.push(i);
      top[i] = ++cnt;
    }
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto it : e[u]) {
      int v = it;
      in[v]--;
      if (!in[v]) {
        q.push(v);
        top[v] = ++cnt;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (in[i]) return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> edge[i].from >> edge[i].to >> edge[i].w;
  }
  int l = 0, r = 0x3f3f3f3f;
  int ret = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (topsort(mid)) {
      ret = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  topsort(ret);
  vector<int> ans;
  for (int i = 1; i <= m; ++i) {
    if (edge[i].w <= ret && top[edge[i].from] > top[edge[i].to]) {
      ans.push_back(i);
    }
  }
  cout << ret << " " << ans.size() << endl;
  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i] << " ";
  }
  return 0;
}
