#include <bits/stdc++.h>
using namespace std;
const int inf = 1e5 + 100;
struct node {
  int u, v, w;
} sn[inf];
int n, m, vis[inf], h[inf];
vector<int> ans, G[inf];
int times = 0;
void dfs(int x) {
  vis[x] = 1;
  for (int i = 0; i < G[x].size(); i++) {
    int e = G[x][i];
    if (!vis[e]) dfs(e);
  }
  h[x] = (++times);
}
bool check(int x) {
  ans.clear();
  for (int i = 1; i <= n; i++) G[i].clear();
  memset(vis, 0, sizeof(vis));
  memset(h, 0, sizeof(h));
  for (int i = 0; i < m; i++) {
    if (sn[i].w > x) {
      G[sn[i].u].push_back(sn[i].v);
    }
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs(i);
  for (int i = 0; i < m; i++) {
    if (h[sn[i].u] < h[sn[i].v]) {
      if (sn[i].w > x) return 0;
      ans.push_back(i + 1);
    }
  }
  return 1;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> sn[i].u >> sn[i].v >> sn[i].w;
  int l = 0, r = 1e9, mid;
  while (l < r) {
    mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  check(l);
  cout << l << " " << ans.size() << '\n';
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i] << (i == ans.size() - 1 ? '\n' : ' ');
  return 0;
}
