#include <bits/stdc++.h>
using namespace std;
int N, M;
int F[1005];
int nxt[6 * 1005], e[1005 * 6], pre[1005 * 6], l[1005 * 6], r[1005 * 6], sum;
int c[1005 * 3];
void add(int x, int y, int L, int R) {
  nxt[++sum] = pre[x];
  e[sum] = y;
  l[sum] = L, r[sum] = R;
  pre[x] = sum;
}
int dfs(int k, int dn, int up) {
  if (k == N) return 1;
  int x = pre[k];
  while (x) {
    if (F[e[x]] == 0 && l[x] <= dn && up <= r[x]) {
      F[e[x]] = k;
      if (dfs(e[x], dn, up)) return 1;
    }
    x = nxt[x];
  }
  return 0;
}
int check(int limitdn, int limitup) {
  memset(F, 0, sizeof(F));
  F[1] = 1;
  return (dfs(1, limitdn, limitup) == 1);
}
int main() {
  scanf("%d%d", &N, &M);
  sum = 0;
  memset(pre, 0, sizeof(pre));
  for (int i = 1; i <= M; i++) {
    int a, b, L, R;
    scanf("%d%d%d%d", &a, &b, &L, &R);
    c[i] = R;
    add(a, b, L, R);
    add(b, a, L, R);
  }
  sort(c + 1, c + 1 + M);
  int ans = 0;
  for (int i = 1; i <= M; i++) {
    int L = 1, R = M;
    while (L <= R) {
      if (c[R] - l[i * 2] + 1 <= ans) break;
      int m = (L + R) >> 1;
      if (c[m] < l[i * 2])
        L = m + 1;
      else {
        if (check(l[i * 2], c[m]))
          ans = max(ans, c[m] - l[i * 2] + 1), L = m + 1;
        else
          R = m - 1;
      }
    }
  }
  if (ans)
    printf("%d\n", ans);
  else
    printf("Nice work, Dima!\n");
  return 0;
}
