#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int>>> g;
vector<int> used;
vector<int> tout;
int timer = 0;
bool dfs(int v, int cost) {
  timer++;
  used[v] = 1;
  for (auto to : g[v]) {
    if (to.second > cost) {
      if (used[to.first] == 0) {
        if (!dfs(to.first, cost)) {
          return false;
        }
      } else {
        if (used[to.first] == 1) {
          return false;
        }
      }
    }
  }
  used[v] = 2;
  ++timer;
  tout[v] = timer;
  return true;
}
struct edge {
  int a, b, c, index;
};
int main() {
  int n, m;
  int a, b, c;
  cin >> n >> m;
  g.resize(n);
  tout.resize(n);
  vector<pair<int, int>> index;
  vector<edge> E;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c;
    --a;
    --b;
    g[a].push_back(make_pair(b, c));
    index.push_back(make_pair(i + 1, c));
    edge e;
    e.a = a;
    e.b = b;
    e.c = c;
    e.index = i + 1;
    E.push_back(e);
  }
  int L = -1;
  int R = 1e9;
  while (R - L > 1) {
    int M = (R + L) / 2;
    used.clear();
    used.resize(n, 0);
    bool q = true;
    for (int i = 0; i < n; i++) {
      if (used[i] == 0) {
        if (!dfs(i, M)) {
          q = false;
          break;
        }
      }
    }
    if (q) {
      R = M;
    } else {
      L = M;
    }
  }
  int k = 0;
  timer = 0;
  used.clear();
  used.resize(n, 0);
  bool q = true;
  for (int i = 0; i < n; i++) {
    if (used[i] == 0) {
      if (!dfs(i, R)) {
        q = false;
        break;
      }
    }
  }
  vector<int> ans;
  for (int i = 0; i < m; i++) {
    if (E[i].c <= R && tout[E[i].a] <= tout[E[i].b]) {
      k += 1;
      ans.push_back(E[i].index);
    }
  }
  cout << R << " " << k << endl;
  for (int i = 0; i < k; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
