#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
int n, m;
vector<pair<int, pair<int, int>>> adj[N];
int L[N], R[N];
int lm, rm;
bool vis[N];
void dfs(int node) {
  vis[node] = true;
  for (auto i : adj[node]) {
    int to = i.first, l = i.second.first, r = i.second.second;
    if (vis[to]) continue;
    if (l <= lm && rm <= r) dfs(to);
  }
}
int main() {
  int i = 0, j = 0, cs = 0, in;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v >> L[i] >> R[i];
    adj[u].push_back({v, {L[i], R[i]}});
    adj[v].push_back({u, {L[i], R[i]}});
  }
  int lo = 0, hi = 1e7;
  int ans = 0;
  while (lo <= hi) {
    int mid = lo + hi >> 1;
    bool f = 0;
    for (i = 0; i < m; i++) {
      lm = L[i], rm = L[i] + mid - 1;
      memset(vis, 0, sizeof(vis));
      dfs(1);
      if (vis[n]) f = 1, ans = mid;
    }
    if (f)
      lo = mid + 1;
    else
      hi = mid - 1;
  }
  if (ans <= 0)
    cout << "Nice work, Dima!"
         << "\n";
  else
    cout << ans << "\n";
  return 0;
}
