#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dx2[] = {1, -1, -1, 1, 0, 0, -1, 1};
int dy2[] = {1, -1, 1, -1, 1, -1, 0, 0};
int nmx[] = {-1, -1, 1, 1, 2, -2, 2, -2};
int nmy[] = {2, -2, 2, -2, -1, -1, 1, 1};
int read() {
  int x;
  scanf("%d", &x);
  return x;
}
const int N = 3e3;
struct edge {
  int x, y;
  int l, r;
};
bool cmp(edge a, edge b) { return a.r > b.r; }
edge a[N];
int n, m;
int p[N], ans;
int find(int i) { return i == p[i] ? i : p[i] = find(p[i]); }
void merge(int x, int y) {
  x = find(x);
  y = find(y);
  p[x] = y;
}
void init() {
  for (int i = 0; i < n; i++) {
    p[i] = i;
  }
}
void solve(int x) {
  init();
  for (int i = 0; i < m; i++) {
    if (x < a[i].l) continue;
    merge(a[i].x, a[i].y);
    if (find(0) == find(n - 1)) ans = max(ans, a[i].r - x + 1);
  }
}
int main() {
  n = read();
  m = read();
  for (int i = 0; i < m; i++) {
    a[i].x = read() - 1;
    a[i].y = read() - 1;
    a[i].l = read();
    a[i].r = read();
  }
  sort(a, a + m, cmp);
  for (int i = 0; i < m; i++) {
    solve(a[i].l);
  }
  if (ans == 0)
    printf("Nice work, Dima!\n");
  else
    printf("%d\n", ans);
  return 0;
}
