#include <bits/stdc++.h>
using namespace std;
int dijkstra(const vector<vector<pair<int, pair<int, int> > > >& g, int n,
             int s, int t) {
  vector<int> vist(n, 1e9);
  priority_queue<pair<pair<int, pair<int, int> >, int> > q;
  q.push(pair<pair<int, pair<int, int> >, int>(
      pair<int, pair<int, int> >(1e9, pair<int, int>(1, 1e9)), s));
  while (!q.empty()) {
    pair<pair<int, pair<int, int> >, int> act = q.top();
    q.pop();
    if (act.second == t) return act.first.first;
    vist[act.second] = act.first.first;
    int a = act.first.second.first;
    int b = act.first.second.second;
    for (int i = 0; i < g[act.second].size(); ++i) {
      int aa = max(a, g[act.second][i].second.first);
      int bb = min(b, g[act.second][i].second.second);
      if (bb - aa >= 0 and bb - aa < vist[g[act.second][i].first]) {
        q.push(pair<pair<int, pair<int, int> >, int>(
            pair<int, pair<int, int> >(bb - aa, pair<int, int>(aa, bb)),
            g[act.second][i].first));
      }
    }
  }
  return -1;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, pair<int, int> > > > g(n);
  for (int i = 0; i < m; ++i) {
    int a, b, l, r;
    cin >> a >> b >> l >> r;
    --a;
    --b;
    g[a].push_back(pair<int, pair<int, int> >(b, pair<int, int>(l, r)));
    g[b].push_back(pair<int, pair<int, int> >(a, pair<int, int>(l, r)));
  }
  int res = dijkstra(g, n, 0, n - 1);
  if (res < 0)
    cout << "Nice work, Dima!" << endl;
  else
    cout << res + 1 << endl;
}
