#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int INF = 100000005;
int DP[1005][3005], L[3005], R[3005];
int N, M;
priority_queue<pair<int, pair<int, int>>> Q;
vector<pair<int, int>> E[1005];
int main() {
  cin >> N >> M;
  for (int i = (1); i <= (M); i++) {
    int a, b;
    cin >> a >> b >> L[i] >> R[i];
    E[a].push_back({b, i});
    E[b].push_back({a, i});
  }
  DP[1][0] = INF;
  Q.push({INF, {1, 0}});
  while (!Q.empty()) {
    pair<int, pair<int, int>> p = Q.top();
    Q.pop();
    int r = p.first;
    int n = p.second.first;
    int l = p.second.second;
    for (pair<int, int> pr : E[n]) {
      int nl = L[pr.second] > L[l] ? pr.second : l;
      int nr = min(r, R[pr.second]);
      int v = pr.first;
      if (DP[v][nl] < nr) {
        DP[v][nl] = nr;
        Q.push({nr, {v, nl}});
      }
    }
  }
  int ans = 0;
  for (int i = (1); i <= (M); i++) ans = max(ans, DP[N][i] - L[i] + 1);
  if (ans)
    cout << ans;
  else
    cout << "Nice work, Dima!";
}
