#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 3123;
int n, m;
vector<tuple<int, int, int>> g[N];
vector<int> lpos, rpos;
bool vis[N];
bool dfs(int u, int l, int r) {
  vis[u] = 1;
  if (u == n) return 1;
  bool ret = 0;
  for (auto t : g[u]) {
    int v, tl, tr;
    tie(v, tl, tr) = t;
    if (tl > l or tr < r or vis[v]) continue;
    ret |= dfs(v, l, r);
  }
  return ret;
}
bool has_path(int l, int r) {
  memset(vis, 0, sizeof vis);
  return dfs(1, l, r);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, l, r;
    cin >> a >> b >> l >> r;
    g[a].emplace_back(b, l, r);
    g[b].emplace_back(a, l, r);
    lpos.emplace_back(l);
    rpos.emplace_back(r);
  }
  sort(begin(lpos), end(lpos));
  sort(begin(rpos), end(rpos));
  lpos.resize(unique(begin(lpos), end(lpos)) - lpos.begin());
  rpos.resize(unique(begin(rpos), end(rpos)) - rpos.begin());
  int ans = 0;
  for (int l : lpos) {
    int lo = lower_bound(begin(rpos), end(rpos), l) - rpos.begin(),
        hi = rpos.size();
    while (lo < hi) {
      int mi = (lo + hi) / 2;
      if (has_path(l, rpos[mi]))
        lo = mi + 1;
      else
        hi = mi;
    }
    if (lo - 1 >= 0) ans = max(ans, rpos[lo - 1] - l + 1);
  }
  if (ans == 0) {
    cout << "Nice work, Dima!" << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}
