#include <bits/stdc++.h>
using namespace std;
int father[1001];
struct zk {
  int u, v, l, r;
} e[3001];
int find(int x) {
  if (father[x] == x) return father[x];
  return father[x] = find(father[x]);
}
int cmp(zk a, zk b) { return a.l < b.l; }
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) father[i] = i;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &e[i].u, &e[i].v, &e[i].l, &e[i].r);
  }
  sort(e + 1, e + 1 + m, cmp);
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) father[j] = j;
    for (int j = 1; j <= m; j++) {
      if (e[i].r > e[j].r) continue;
      if (e[i].r < e[j].l) continue;
      int fx = find(e[j].u);
      int fy = find(e[j].v);
      if (fx != fy) father[fx] = fy;
      if (find(1) == find(n)) {
        ans = max(ans, e[i].r - e[j].l + 1);
        break;
      }
    }
  }
  if (ans == 0)
    printf("Nice work, Dima!\n");
  else
    printf("%d\n", ans);
}
