#include <bits/stdc++.h>
using namespace std;
inline int min(int _a, int _b) { return _a < _b ? _a : _b; }
inline int max(int _a, int _b) { return _a > _b ? _a : _b; }
template <class _T>
inline void rd(_T &_a) {
  int _f = 0, _ch = getchar();
  _a = 0;
  while (_ch < '0' || _ch > '9') {
    if (_ch == '-') _f = 1;
    _ch = getchar();
  }
  while (_ch >= '0' && _ch <= '9') _a = _a * 10 + _ch - '0', _ch = getchar();
  if (_f) _a = -_a;
}
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int N = 1e3 + 5;
struct node {
  int u, v, l, r;
  bool operator<(const node &b) const { return l < b.l; }
} e[N << 2];
int p[N];
int gtf(int i) { return p[i] < 0 ? i : p[i] = gtf(p[i]); }
void mg(int u, int v) {
  u = gtf(u);
  v = gtf(v);
  if (u == v) return;
  if (p[u] > p[v]) swap(u, v);
  p[u] += p[v];
  p[v] = u;
}
int main() {
  int n, m, ans = 0;
  rd(n);
  rd(m);
  for (int i = 0; i < m; i++) rd(e[i].u), rd(e[i].v), rd(e[i].l), rd(e[i].r);
  sort(e, e + m);
  for (int i = 0; i < m; i++) {
    memset(p, -1, sizeof p);
    for (int j = 0; j < m; j++) {
      if (e[j].l > e[i].r) break;
      if (e[j].r < e[i].r) continue;
      mg(e[j].u, e[j].v);
      if (gtf(1) == gtf(n)) {
        ans = max(ans, e[i].r - e[j].l + 1);
      }
    }
  }
  if (!ans)
    puts("Nice work, Dima!");
  else
    printf("%d\n", ans);
  return 0;
}
