#include <bits/stdc++.h>
using namespace std;
struct Node {
  int x, y, l, r;
} node[3000];
bool cmp(Node x, Node y) { return x.r > y.r; }
int pr[3001];
int f1(int x) {
  if (pr[x] == -1 || pr[x] == x) return x;
  return pr[x] = f1(pr[x]);
}
int main() {
  int n, m, ans = 0;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++)
    scanf("%d %d %d %d", &node[i].x, &node[i].y, &node[i].l, &node[i].r);
  sort(node, node + m, cmp);
  for (int i = 0; i < m; i++) {
    memset(pr, -1, sizeof(pr));
    for (int j = 0; j < m; j++) {
      if (node[j].r < node[i].l)
        break;
      else if (node[j].l > node[i].l)
        continue;
      else
        pr[f1(node[j].x)] = f1(node[j].y);
      if (f1(1) == f1(n)) {
        ans = max(ans, node[j].r - node[i].l + 1);
        break;
      }
    }
  }
  if (ans)
    printf("%d\n", ans);
  else
    printf("Nice work, Dima!\n");
  return 0;
}
