#include <bits/stdc++.h>
using namespace std;
struct Tedge {
  int a, b, l, r;
};
const int N = 1000 + 123;
const int M = 3000 + 123;
Tedge edges[M];
int n, m;
bool cmp(const Tedge& a, const Tedge& b) { return (a.r < b.r); }
int fa[N];
int getfather(int a) { return fa[a] = (a == fa[a]) ? a : getfather(fa[a]); }
void initfa(int n) {
  for (int i = 1; i <= n; ++i) fa[i] = i;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i)
    scanf("%d%d%d%d", &edges[i].a, &edges[i].b, &edges[i].l, &edges[i].r);
  sort(edges, edges + m, cmp);
  int ans = 0;
  for (int i = 0; i < m; ++i) {
    int tl = edges[i].l;
    int l = 0, r = m;
    while (l <= r) {
      int mid = (l + r) >> 1;
      initfa(n);
      int tr = edges[mid].r;
      for (int j = 0; j < m; ++j)
        if (edges[j].l <= tl && edges[j].r >= tr) {
          fa[getfather(edges[j].a)] = getfather(edges[j].b);
        }
      if (getfather(1) == getfather(n)) {
        if (tr - tl + 1 > ans) ans = tr - tl + 1;
        l = mid + 1;
      } else
        r = mid - 1;
    }
  }
  if (ans == 0)
    puts("Nice work, Dima!");
  else
    printf("%d\n", ans);
  return 0;
}
