#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
vector<pair<int, pair<int, int>>> g[N];
priority_queue<pair<pair<int, int>, pair<int, int>>> q;
map<int, int> visL[N], visR[N];
int n, m, a, b, l, r, ans;
void bfs() {
  q.emplace(pair<int, int>(1e7, 1), pair<int, int>(0, 1e7));
  while (q.size()) {
    auto node = q.top();
    q.pop();
    int u = node.first.second;
    int size = node.first.first;
    int L = node.second.first;
    int R = node.second.second;
    if (visL[u][L] || visR[u][R] || size < ans) continue;
    visL[u][L] = 1, visR[u][R] = 1;
    if (u == n) {
      ans = max(ans, size);
      continue;
    }
    for (auto &i : g[u]) {
      int v = i.first;
      int l = i.second.first;
      int r = i.second.second;
      l = max(l, L);
      r = min(r, R);
      if (r >= l) q.emplace(pair<int, int>(r - l + 1, v), pair<int, int>(l, r));
    }
  }
}
int main() {
  cin >> n >> m;
  while (m--) {
    cin >> a >> b >> l >> r;
    g[a].emplace_back(b, pair<int, int>(l, r));
    g[b].emplace_back(a, pair<int, int>(l, r));
  }
  bfs();
  if (ans)
    cout << ans;
  else
    cout << "Nice work, Dima!";
  return 0;
}
