#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, l[1000000], r[1000000], a[1000000], b[1000000], w[1000000],
    f[1000000], tmp, ans;
int max(int a, int b) {
  if (a > b) return a;
  return b;
}
int gf(int x) {
  int p, t;
  p = x;
  while (p != f[p]) p = f[p];
  while (x != p) {
    t = f[x];
    f[x] = p;
    x = t;
  }
  return p;
}
int ef(int ll, int rr) {
  int mm, z, i;
  z = rr;
  do {
    for (i = 1; i <= n; i++) f[i] = i;
    mm = (ll + rr) >> 1;
    for (i = 1; i <= m; i++)
      if ((l[i] <= mm) && (z <= r[i])) f[gf(a[i])] = gf(b[i]);
    if (gf(1) == gf(n))
      rr = mm - 1;
    else
      ll = mm + 1;
  } while (ll <= rr);
  return ll;
}
int main() {
  scanf("%d%d", &n, &m);
  tmp = -1;
  ans = -0x37373737;
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &a[i], &b[i], &w[2 * i - 1], &w[2 * i]);
    l[i] = w[2 * i - 1];
    r[i] = w[2 * i];
  }
  for (i = 1; i <= m; i++) {
    tmp = ef(1, r[i]);
    ans = max(ans, r[i] - tmp + 1);
  }
  if (ans > 0)
    printf("%d", ans);
  else
    printf("Nice work, Dima!");
}
