#include <bits/stdc++.h>
using namespace std;
struct EDGE {
  int x, y, l, h;
  EDGE(int _x = 0, int _y = 0, int _l = 0, int _h = 0)
      : x(_x), y(_y), l(_l), h(_h) {}
  bool operator<(const EDGE& b) const { return h > b.h; }
} e[3030];
int lv[3030], d[3030];
int find(int x) { return x != d[x] ? d[x] = find(d[x]) : x; }
void uu(int x, int y) {
  x = find(x);
  y = find(y);
  d[x] = y;
}
int go(int low, int n, int m) {
  for (int i = (1); i < (n + 1); ++i) d[i] = i;
  for (int i = 0; i < (m); ++i) {
    if (e[i].l <= low) uu(e[i].x, e[i].y);
    if (find(1) == find(n)) return e[i].h - low + 1;
  }
  return 0;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (m); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    int low, high;
    scanf("%d%d", &low, &high);
    e[i] = EDGE(x, y, low, high);
    lv[i] = low;
    d[i + 1] = i + 1;
  }
  sort(e, e + m);
  int ma = 0;
  for (int i = 0; i < (m); ++i) {
    ma = max(ma, go(lv[i], n, m));
  }
  if (ma == 0)
    puts("Nice work, Dima!");
  else
    printf("%d\n", ma);
  return 0;
}
