#include <bits/stdc++.h>
using namespace std;
vector<int> cand;
pair<pair<int, int>, pair<int, int> > e[3005];
int par[1005];
int ran[1005];
void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    ran[i] = 0;
  }
}
int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (ran[x] < ran[y]) {
    par[x] = par[y];
  } else {
    par[y] = par[x];
    if (ran[x] == ran[y]) ran[x]++;
  }
}
bool same(int x, int y) { return find(x) == find(y); }
int main() {
  srand((unsigned int)time(NULL));
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x, y, l, r;
    scanf("%d %d %d %d", &x, &y, &l, &r);
    e[i] = make_pair(make_pair(--x, --y), make_pair(l, r));
    cand.push_back(l);
  }
  sort(cand.begin(), cand.end());
  cand.erase(unique(cand.begin(), cand.end()), cand.end());
  int lb = 0, ub = 1000005;
  while (ub - lb > 1) {
    int mid = (lb + ub) >> 1;
    for (int i = 0; i < cand.size(); i++) {
      int lb = cand[i];
      int ub = cand[i] + mid - 1;
      init(n);
      for (int i = 0; i < m; i++) {
        if (e[i].second.first <= lb && ub <= e[i].second.second) {
          unite(e[i].first.first, e[i].first.second);
        }
      }
      if (same(0, n - 1)) goto ok;
    }
    ub = mid;
    continue;
  ok:;
    lb = mid;
  }
  if (lb)
    printf("%d\n", lb);
  else
    puts("Nice work, Dima!");
}
