#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5;
struct data {
  long long v, l, r;
  data() {}
  data(long long v, long long l, long long r) : v(v), l(l), r(r) {}
};
long long n, m;
long long dist[N], vis[N];
set<long long> s;
vector<data> g[N];
long long work(long long x) {
  for (long long i = 1; i <= n; i++) dist[i] = 0, vis[i] = 0;
  dist[1] = 1e9;
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> > >
      pq;
  pq.push({dist[1], 1});
  while (!pq.empty()) {
    long long node = pq.top().second;
    long long curd = pq.top().first;
    pq.pop();
    if (vis[node]) continue;
    vis[node] = 1;
    for (auto &it : g[node]) {
      if (x >= it.l && x <= it.r && min(it.r, curd) > dist[it.v]) {
        dist[it.v] = min(it.r, curd);
        pq.push({dist[it.v], it.v});
      }
    }
  }
  return dist[n];
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    long long a, b, l, r;
    cin >> a >> b >> l >> r;
    g[a].push_back(data(b, l, r));
    g[b].push_back(data(a, l, r));
    s.insert(l);
    s.insert(r);
  }
  long long ans = 0;
  for (auto &it : s) ans = max(ans, work(it) - it + 1);
  if (ans)
    cout << ans;
  else
    cout << "Nice work, Dima!";
  return 0;
}
