#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long Mxn = 3e3 + 7;
long long n, m, parent[Mxn];
struct node {
  long long x, y, l, r;
} a[Mxn];
bool cmp(node u, node v) { return u.r > v.r; }
long long findroot(long long u) {
  if (parent[u] == u) return u;
  return parent[u] = findroot(parent[u]);
}
void Union(long long x, long long y) {
  long long u = findroot(x);
  long long v = findroot(y);
  if (u == v) return;
  parent[u] = v;
}
signed main() {
  ios::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    cin >> a[i].x >> a[i].y >> a[i].l >> a[i].r;
  }
  long long res = 0;
  sort(a + 1, a + 1 + m, cmp);
  for (long long i = 1; i <= m; i++) {
    for (long long j = 1; j <= n; j++) parent[j] = j;
    for (long long j = 1; j <= m; j++) {
      if (a[j].r < a[i].l || a[j].l > a[i].l) continue;
      Union(a[j].x, a[j].y);
      if (findroot(1) == findroot(n)) {
        res = max(res, a[j].r - a[i].l + 1);
        break;
      }
    }
  }
  if (res)
    cout << res;
  else
    cout << "Nice work, Dima!";
}
