#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
int father[N];
int ans = 0;
int n, m;
struct ST {
  int a, b, l, r;
} st[N];
bool cmp(ST x, ST y) { return x.l < y.l; }
int root(int x) {
  if (x == father[x]) return x;
  return root(father[x]);
}
void u(int x, int y) {
  father[root(x)] = root(y);
  return;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++)
    scanf("%d %d %d %d", &st[i].a, &st[i].b, &st[i].l, &st[i].r);
  ans = 0;
  sort(st + 1, st + 1 + m, cmp);
  for (int i = 1; i <= m; i++) {
    for (int ii = 1; ii <= N; ii++) father[ii] = ii;
    for (int j = 1; j <= m; j++) {
      if (st[i].r < st[j].l) break;
      if (st[i].r > st[j].r) continue;
      u(st[j].a, st[j].b);
      if (root(1) == root(n)) {
        ans = max(ans, st[i].r - st[j].l + 1);
        break;
      }
    }
  }
  if (ans == 0)
    printf("Nice work, Dima!");
  else
    printf("%d\n", ans);
  return 0;
}
