#include <bits/stdc++.h>
using namespace std;
int LIM = 1e5 + 10;
int n;
map<long long int, map<long long int, long long int> > inde;
vector<vector<pair<long long int, long long int> > > adj(LIM);
bool f = true;
void dfs(int n, int x, vector<long long int>& color) {
  color[n] = 1;
  for (int i = 0; i < adj[n].size(); i++) {
    if (adj[n][i].second <= x) continue;
    if (color[adj[n][i].first] == 1) {
      f = false;
      return;
    }
    if (color[n] != 2) dfs(adj[n][i].first, x, color);
  }
  color[n] = 2;
}
bool check(int x) {
  f = true;
  vector<long long int> color(LIM, 0);
  for (int i = 1; i <= n; i++) {
    if (color[i] == 0) dfs(i, x, color);
  }
  return f;
}
long long int ans = 0;
vector<long long int> stk(1);
vector<long long int> pos(LIM, -1);
void topo(int n, vector<long long int>& visited) {
  for (int i = 0; i < adj[n].size(); i++) {
    if (adj[n][i].second <= ans) continue;
    if (visited[adj[n][i].first] == -1) {
      visited[adj[n][i].first] = 1;
      topo(adj[n][i].first, visited);
      pos[adj[n][i].first] = stk.size();
      stk.push_back(adj[n][i].first);
    }
  }
}
int main() {
  int m;
  cin >> n >> m;
  vector<pair<int, pair<long long int, long long int> > > edges(m + 1);
  for (int i = 1; i <= m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    adj[a].push_back(pair<long long int, long long int>(b, c));
    inde[a][b] = i;
    edges[i] = pair<int, pair<long long int, long long int> >(
        c, pair<long long int, long long int>(a, b));
  }
  int l = 0, r = 1e9 + 10;
  while (l != r) {
    int mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  ans = l;
  vector<long long int> visited(n + 1, -1);
  for (int i = 1; i <= n; i++) {
    if (visited[i] == -1) {
      visited[i] = 1;
      topo(i, visited);
      pos[i] = stk.size();
      stk.push_back(i);
    }
  }
  cout << ans << " ";
  vector<long long int> roads;
  for (int i = 1; i <= m; i++) {
    if (edges[i].first <= ans &&
        pos[edges[i].second.second] > pos[edges[i].second.first])
      roads.push_back(i);
  }
  cout << roads.size() << endl;
  for (int i = 0; i < roads.size(); i++) cout << roads[i] << " ";
  return 0;
}
