#include <bits/stdc++.h>
using namespace std;
const int maxm = 3000 + 12;
const int maxn = 1000 + 12;
int l[maxm], r[maxm], x[maxm], y[maxm];
vector<int> nei[maxn];
bool mark[maxn];
int n, m;
bool q = 0;
int other(int eid, int k) {
  if (x[eid] == k) return y[eid];
  return x[eid];
}
void dfs(int input, int kam, int bish) {
  if (input == n) {
    q = 1;
    return;
  }
  mark[input] = 1;
  for (int i = 0; i < nei[input].size(); i++) {
    int u = nei[input][i];
    if (l[u] <= kam && r[u] >= bish) {
      int rokoodom = other(u, input);
      if (!mark[rokoodom]) {
        dfs(rokoodom, kam, bish);
      }
    }
  }
}
int main() {
  cin >> n >> m;
  int minr = maxn * maxn;
  int maxr = 0;
  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i] >> l[i] >> r[i];
    minr = min(minr, r[i]);
    maxr = max(maxr, r[i]);
    nei[x[i]].push_back(i);
    nei[y[i]].push_back(i);
  }
  int javab = 0;
  for (int i = 0; i < m; i++) {
    int lo = max(minr, l[i]), hi = maxr + 1, mid;
    while (lo < hi - 1) {
      mid = (hi + lo) / 2;
      q = 0;
      fill(mark, mark + n + 10, 0);
      dfs(1, l[i], mid);
      if (q)
        lo = mid;
      else
        hi = mid;
    }
    q = 0;
    fill(mark, mark + n + 10, 0);
    dfs(1, l[i], lo);
    if (q) javab = max(javab, lo - l[i] + 1);
  }
  if (javab)
    cout << javab << endl;
  else
    cout << "Nice work, Dima!";
  return 0;
}
