3 5
2 1 608591421 720962564
3 2 608591421 641991574
3 2 718110706 353409763
2 3 482786015 858341723
3 2 825397574 357507279
 2 1
2 1 317425595 636156322
 50000 1
20845 28516 904146168 997637433

Yes
641991574 1
2 
 Yes
0 0

 Yes
0 0


#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  write(a);
  puts("");
}
inline void wri(long long a) {
  write(a);
  putchar(' ');
}
inline unsigned long long rnd() {
  return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4;
}
const int N = 50005, NN = 10 * N, MM = 25 * N, inf = 1e9;
vector<int> jb[N], e[NN];
int n, m, qlt, ti, ne, top, u[N], v[N], c[N], t[N];
int dfn[NN], rd[NN], low[NN], to[NN], ans[NN], zhan[NN], zh[NN], son[NN];
int ed[MM], nxt[MM];
inline int yi(int x) { return (x & 1) ? x + 1 : x - 1; }
bool cmp(int x, int y) { return c[x] < c[y]; }
void ae(int a, int b) {
  nxt[++ne] = son[a];
  son[a] = ne;
  ed[ne] = b;
}
void ins(int a, int b) {
  ae(a, b);
  ae(yi(b), yi(a));
}
void dfs(int p) {
  dfn[p] = low[p] = ++ti;
  zhan[++top] = p;
  zh[p] = 1;
  for (int i = son[p]; i; i = nxt[i])
    if (!dfn[ed[i]]) {
      dfs(ed[i]);
      low[p] = min(low[p], low[ed[i]]);
    } else if (zh[ed[i]])
      low[p] = min(low[p], dfn[ed[i]]);
  if (dfn[p] == low[p]) {
    qlt++;
    while (1) {
      to[zhan[top]] = qlt;
      zh[zhan[top]] = 0;
      if (zhan[top--] == p) break;
    }
  }
}
int dq;
bool check(int x) {
  memset(son, 0, sizeof(son));
  memset(dfn, 0, sizeof(dfn));
  ti = ne = qlt = 0;
  dq = 2 * m;
  for (int i = (int)(1); i <= (int)(n); i++)
    if (jb[i].size()) {
      int len = jb[i].size();
      dq += 2;
      ins(dq, 2 * jb[i][0]);
      for (int j = (int)(1); j <= (int)(len - 1); j++) {
        dq += 2;
        ins(dq, dq - 2);
        ins(2 * jb[i][j] - 1, dq - 2);
        ins(dq, 2 * jb[i][j]);
      }
    }
  for (int i = (int)(1); i <= (int)(n); i++)
    if (jb[i].size()) {
      int len = jb[i].size();
      for (int j = 0, dd; j < len;) {
        dd = j + 1;
        while (dd < len && c[jb[i][dd]] == c[jb[i][j]]) dd++;
        dq += 2;
        ins(dq, 2 * jb[i][j] - 1);
        j++;
        while (j < dd) {
          dq += 2;
          ins(dq, dq - 2);
          ins(2 * jb[i][j], dq - 2);
          ins(dq, 2 * jb[i][j] - 1);
          j++;
        }
      }
    }
  for (int i = (int)(1); i <= (int)(m); i++)
    if (t[i] > x) ae(2 * i - 1, 2 * i);
  for (int i = (int)(1); i <= (int)(dq); i++)
    if (!dfn[i]) dfs(i);
  for (int i = 1; i <= dq; i += 2)
    if (to[i] == to[i + 1]) return 0;
  return 1;
}
void solve(int x) {
  check(x);
  queue<int> q;
  for (int i = (int)(1); i <= (int)(dq); i++)
    for (int j = son[i]; j; j = nxt[j])
      if (to[i] != to[ed[j]]) {
        e[to[i]].push_back(to[ed[j]]);
        rd[to[ed[j]]]++;
      }
  for (int i = (int)(1); i <= (int)(qlt); i++)
    if (!rd[i]) q.push(i);
  int zyk = 0;
  while (q.size()) {
    int t = q.front();
    q.pop();
    ans[t] = ++zyk;
    for (auto i : e[t])
      if (--rd[i] == 0) q.push(i);
  }
  vector<int> vvv;
  for (int i = (int)(1); i <= (int)(m); i++)
    if (ans[to[i * 2 - 1]] > ans[to[i * 2]]) vvv.push_back(i);
  writeln(vvv.size());
  for (auto i : vvv) wri(i);
}
int main() {
  n = read(), m = read();
  for (int i = (int)(1); i <= (int)(m); i++) {
    u[i] = read();
    v[i] = read();
    c[i] = read();
    t[i] = read();
    jb[u[i]].push_back(i);
    jb[v[i]].push_back(i);
  }
  for (int i = (int)(1); i <= (int)(n); i++)
    sort(jb[i].begin(), jb[i].end(), cmp);
  int l = 0, r = inf + 1;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  if (l > inf)
    puts("No");
  else {
    puts("Yes");
    wri(l);
    solve(l);
  }
}
