#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > graph[100001];
int w[100001], vis[100001], mid, rk[100001];
vector<int> ord;
bool dfs(int u, bool save) {
  vis[u] = 1;
  for (int i = 0; i < graph[u].size(); i++) {
    int v = graph[u][i].first, c = w[graph[u][i].second];
    if (c <= mid) continue;
    if ((!vis[v] && !dfs(v, save)) || vis[v] == 1) return false;
  }
  vis[u] = 2;
  if (save) ord.push_back(u);
  return true;
}
bool solve(bool save = false) {
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    if (!vis[i] && !dfs(i, save)) return false;
  }
  return true;
}
int main(void) {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    graph[u].push_back(make_pair(v, i));
    w[i] = c;
  }
  int l = 0, r = 1000000001L;
  while (l < r) {
    mid = (l + r) / 2;
    if (solve()) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  mid = r;
  solve(true);
  for (int i = 0; i < ord.size(); i++) rk[ord[i]] = i;
  vector<int> ans;
  for (int u = 1; u <= n; u++) {
    for (int x = 0; x < graph[u].size(); x++) {
      int v = graph[u][x].first, id = graph[u][x].second;
      int c = w[id];
      if (c <= r && rk[v] > rk[u]) ans.push_back(id);
    }
  }
  cout << r << " " << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) cout << (ans[i] + 1) << " ";
  cout << endl;
}
