#include <bits/stdc++.h>
using namespace std;
long long bin_pow(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2 == 0) {
    long long t = bin_pow(a, b / 2);
    return t * t % 1000000007;
  } else
    return a * bin_pow(a, b - 1) % 1000000007;
}
long long t = 1, n, m, k = 0, sum = 0, l = 0, r = 0, x = 0, y = 0, z = 0,
          ans = 0, mn = LLONG_MAX, mx = LLONG_MIN;
struct cat {
  long long a, b, c;
};
vector<cat> edges;
vector<long long> graph[100000];
long long z1 = 1, color[100000];
void dfs(long long v) {
  color[v] = 1;
  for (auto u : graph[v]) {
    if (color[u] == 1) {
      z1 = 0;
      return;
    }
    if (color[u] == 0) dfs(u);
  }
  color[v] = 2;
}
bool tr(long long x) {
  z1 = 1;
  for (int i = 0; i < n; i++) graph[i].clear(), color[i] = 0;
  for (int i = 0; i < m; i++) {
    if (edges[i].c <= x) break;
    long long x1 = edges[i].a, y1 = edges[i].b;
    graph[x1].push_back(y1);
  }
  for (int i = 0; i < n; i++) {
    if (color[i] == 0) dfs(i);
  }
  return z1;
}
bool cmp(cat a, cat b) { return a.c > b.c; }
vector<long long> order;
bool used[100000];
void dfs1(long long v) {
  used[v] = true;
  for (auto u : graph[v]) {
    if (used[u]) continue;
    dfs1(u);
  }
  order.push_back(v);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, s1;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y >> z;
    x--, y--;
    cat f;
    f.a = x, f.b = y, f.c = z;
    edges.push_back(f);
  }
  vector<cat> c = edges;
  ans = -1;
  sort(edges.begin(), edges.end(), cmp);
  for (long long b = 1e9; b >= 1; b /= 2) {
    while (!tr(ans + b)) ans += b;
  }
  ans++;
  cout << ans << " ";
  vector<long long> d;
  for (int i = 0; i < n; i++) {
    graph[i].clear();
  }
  for (int i = 0; i < m; i++) {
    if (c[i].c <= ans) continue;
    graph[c[i].a].push_back(c[i].b);
  }
  for (int i = 0; i < n; i++) {
    if (used[i]) continue;
    dfs1(i);
  }
  reverse(order.begin(), order.end());
  vector<long long> pos(n);
  for (int i = 0; i < n; i++) {
    pos[order[i]] = i;
  }
  for (int i = 0; i < m; i++) {
    if (c[i].c <= ans) {
      if (pos[c[i].a] <= pos[c[i].b])
        ;
      else
        d.push_back(i);
    }
  }
  cout << d.size() << "\n";
  for (auto u : d) cout << u + 1 << " ";
  return 0;
}
