#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<int> R[1000005];
vector<pair<int, int>> E[1000005];
vector<pair<int, int>> adjList[1005];
int main(int argc, const char* argv[]) {
  cin >> N >> M;
  for (int i = 0, a, b, l, r; i < M; i++) {
    cin >> a >> b >> l >> r;
    R[l].push_back(r);
    E[l].push_back(make_pair(a, b));
  }
  int ANS = 0;
  for (int i = 1; i <= 1000000; i++)
    if (R[i].size() > 0) {
      for (int j = 0; j < R[i].size(); j++) {
        adjList[E[i][j].first].push_back(make_pair(E[i][j].second, R[i][j]));
        adjList[E[i][j].second].push_back(make_pair(E[i][j].first, R[i][j]));
      }
      vector<int> dist(N + 1, 0);
      dist[1] = INT_MAX;
      priority_queue<pair<int, int>, vector<pair<int, int>>> pq;
      pq.push(pair<int, int>(INT_MAX, 1));
      while (!pq.empty()) {
        pair<int, int> front = pq.top();
        pq.pop();
        int d = front.first;
        int u = front.second;
        if (d > dist[u]) continue;
        for (auto p : adjList[u]) {
          if (min(d, p.second) > dist[p.first]) {
            dist[p.first] = min(d, p.second);
            pq.push(pair<int, int>(dist[p.first], p.first));
          }
        }
      }
      if (dist[N] > 0) ANS = max(ANS, dist[N] - i + 1);
    }
  if (ANS > 0)
    cout << ANS << endl;
  else {
    cout << "Nice work, Dima!" << endl;
  }
  return 0;
}
