#include <bits/stdc++.h>
using namespace std;
struct data {
  int r, l, x, y;
} s[3111];
int k[1111];
int n, m;
bool cmp(data a, data b) { return a.l < b.l; }
int find(int x) {
  if (x != k[x])
    return k[x] = find(k[x]);
  else
    return x;
}
int main() {
  scanf("%d%d", &n, &m);
  int ans = 0;
  int i, j;
  for (i = 0; i < m; i++) scanf("%d%d%d%d", &s[i].x, &s[i].y, &s[i].l, &s[i].r);
  sort(s, s + m, cmp);
  for (i = 0; i < m; i++) {
    for (j = 1; j <= n; j++) k[j] = j;
    for (j = 0; j < m; j++) {
      if (s[j].r < s[i].r) continue;
      if (s[j].l > s[i].r) continue;
      int s1 = find(s[j].x);
      int s2 = find(s[j].y);
      if (s1 != s2) k[s1] = s2;
      if (find(1) == find(n)) {
        ans = max(ans, s[i].r - s[j].l + 1);
        break;
      }
    }
  }
  if (ans == 0)
    printf("Nice work, Dima!\n");
  else
    printf("%d\n", ans);
}
