#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 5;
vector<int> zz[maxn], ld[maxn], ud[maxn];
map<pair<int, int>, int> sm;
set<pair<int, int> > se;
int n, m, ans;
queue<pair<int, int> > t;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, l, u;
    cin >> a >> b >> l >> u;
    zz[a].push_back(b);
    ld[a].push_back(l);
    ud[a].push_back(u);
    zz[b].push_back(a);
    ld[b].push_back(l);
    ud[b].push_back(u);
  }
  pair<int, int> tep(1, 1);
  sm[tep] = 1000000;
  t.push(tep);
  se.insert(tep);
  while (t.size()) {
    pair<int, int> y = t.front();
    t.pop();
    int high = sm[y];
    int low = y.second;
    set<pair<int, int> >::iterator point = se.find(y);
    se.erase(point);
    if (high - low + 1 <= ans) continue;
    for (int i = 0; i < zz[y.first].size(); i++) {
      int aim = zz[y.first][i];
      int newlow = max(ld[y.first][i], low);
      int newhigh = min(ud[y.first][i], high);
      if (newhigh < newlow) continue;
      pair<int, int> tem(aim, newlow);
      if (aim == n) {
        ans = max(ans, newhigh - newlow + 1);
      }
      if (sm.find(tem) == sm.end()) {
        sm[tem] = newhigh;
        se.insert(tem);
        t.push(tem);
      } else {
        if (newhigh > sm[tem]) {
          sm[tem] = newhigh;
          if (se.find(tem) == se.end()) {
            se.insert(tem);
            t.push(tem);
          }
        }
      }
    }
  }
  if (ans == 0)
    cout << "Nice work, Dima!" << endl;
  else
    cout << ans << endl;
  return 0;
}
