#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:33554432")
int N, M, L[3008], R[3008], D[1004], ans;
vector<int> con[1004], V;
void proc(int mn) {
  int i, j, k;
  memset(D, 0, sizeof(D));
  priority_queue<pair<int, int> > que;
  D[1] = 1e9;
  que.push(make_pair(1e9, 1));
  while (!que.empty()) {
    int d = que.top().first;
    int q = que.top().second;
    que.pop();
    if (D[q] != d) continue;
    for (i = 0; i < ((int)(con[q]).size()); i += 2) {
      int k = con[q][i], m = con[q][i + 1];
      if (L[m] <= mn & mn <= R[m] && L[m] <= D[q]) {
        int nxt = min(D[q], R[m]);
        if (D[k] < nxt) D[k] = nxt, que.push(make_pair(D[k], k));
      }
    }
  }
  ans = max(ans, D[N] - mn + 1);
}
int main() {
  int i, j, k;
  scanf("%d%d", &N, &M);
  for (i = 1; i <= M; i++) {
    scanf("%d%d%d%d", &j, &k, L + i, R + i);
    con[j].push_back(k);
    con[j].push_back(i);
    con[k].push_back(j);
    con[k].push_back(i);
    V.push_back(L[i]), V.push_back(R[i]);
  }
  sort(V.begin(), V.end());
  for (i = 0; i < ((int)(V).size()); i++) {
    proc(V[i]);
  }
  if (ans)
    printf("%d\n", ans);
  else
    puts("Nice work, Dima!");
}
