#include <bits/stdc++.h>
using namespace std;
int n, m, f[1100], a[3100], b[3100], l[3100], r[3100];
void init() {
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (m); ++i)
    scanf("%d%d%d%d", &a[i], &b[i], &l[i], &r[i]);
}
int find(int t) {
  if (f[t] == t) return t;
  return f[t] = find(f[t]);
}
bool ok(int ll, int rr) {
  for (int i = (1); i <= (n); ++i) f[i] = i;
  for (int i = (1); i <= (m); ++i)
    if (l[i] <= ll && r[i] >= rr) f[find(a[i])] = find(b[i]);
  return find(1) == find(n);
}
void work() {
  int ll, rr, k, ans = 0;
  for (int i = (1); i <= (m); ++i) {
    ll = 0;
    rr = 1000000;
    while (ll < rr) {
      k = (ll + rr + 1) / 2;
      if (ok(l[i], l[i] + k))
        ll = k;
      else
        rr = k - 1;
    }
    if (ok(l[i], l[i] + ll)) ans = max(ans, ll + 1);
  }
  if (ans)
    printf("%d", ans);
  else
    puts("Nice work, Dima!");
}
int main() {
  init();
  work();
  return 0;
}
