#include <bits/stdc++.h>
using namespace std;
int const lim = 3e5 + 3;
pair<pair<int, int>, pair<int, int> > inp[lim + 3];
vector<int> adj[lim + 3], dir[lim + 3];
bool vis[lim + 3];
int n, m;
bool is_cycle = false;
int rnk[lim + 3], cnt = 0;
void dfs(int u) {
  vis[u] = true;
  for (int i = 0; i < adj[u].size(); i++) {
    if (vis[adj[u][i]] && rnk[adj[u][i]] == 0) {
      is_cycle = true;
      return;
    }
    if (!vis[adj[u][i]]) dfs(adj[u][i]);
  }
  rnk[u] = ++cnt;
}
bool check(int ind) {
  for (int i = 1; i <= n; i++) adj[i].clear(), vis[i] = false, rnk[i] = 0;
  is_cycle = false;
  cnt = 0;
  for (int i = ind + 1; i <= m; i++) {
    int a = inp[i].second.first, b = inp[i].second.second;
    adj[a].push_back(b);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i);
    if (is_cycle) break;
  }
  return !is_cycle;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b, x;
    scanf("%d %d %d", &a, &b, &x);
    inp[i] = make_pair(make_pair(x, i), make_pair(a, b));
  }
  sort(inp + 1, inp + m + 1);
  int l = 0, r = m;
  while (l < r) {
    if (l == r - 1) {
      if (check(l)) r = l;
      break;
    }
    int mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  check(r);
  vector<int> ans;
  for (int i = 1; i <= r; i++) {
    int a = inp[i].second.first, b = inp[i].second.second;
    if (rnk[a] < rnk[b]) ans.push_back(inp[i].first.second);
  }
  cout << inp[r].first.first << " " << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
}
