#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long b,
                 long long mod = (long long)(1e9 + 7)) {
  if (!b) return 1;
  a %= mod;
  return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mxn = 1e3, mxm = 3e3;
int n, m;
int bestDist[mxn];
vector<pair<int, pair<int, int>>> adj[mxn];
int check(int x) {
  for (int i = 0; i < n; i++) bestDist[i] = x + 1;
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      pq;
  bestDist[0] = 0;
  pq.push(pair<int, int>(0, 0));
  while (int((pq).size())) {
    pair<int, int> pp = pq.top();
    pq.pop();
    int v = pp.second;
    if (bestDist[v] < pp.first) continue;
    for (pair<int, pair<int, int>> &pp : adj[v]) {
      int w = pp.first, l = pp.second.first, r = pp.second.second;
      if ((l <= x && x <= r) && bestDist[w] > max(bestDist[v], l)) {
        bestDist[w] = max(bestDist[v], l);
        pq.push(pair<int, int>(bestDist[w], w));
      }
    }
  }
  return x - bestDist[n - 1] + 1;
}
void solve() {
  vector<int> pos;
  for (int i = 0; i < n; i++) adj[i].clear();
  for (int i = 0; i < m; i++) {
    int v, w, l, r;
    cin >> v >> w >> l >> r;
    adj[--v].push_back(pair<int, pair<int, int>>(--w, pair<int, int>(l, r)));
    adj[w].push_back(pair<int, pair<int, int>>(v, pair<int, int>(l, r)));
    pos.push_back(r);
  }
  sort(pos.begin(), pos.end(), greater<int>());
  int ans = 0;
  for (int d : pos) (ans) = max((ans), (check(d)));
  if (!ans)
    cout << "Nice work, Dima!" << endl;
  else
    cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  while (cin >> n >> m) solve();
  return 0;
}
