#include <bits/stdc++.h>
using namespace std;
const long double PI = atan(1.0) * 4;
const int64_t INF = 3e18;
const int32_t LOG = 21;
const long long int MOD = 1e9 + 7;
vector<pair<long long int, pair<long long int, long long int>>> v[2005];
long long int vis[2005];
bool g = false;
long long int n, m;
long long int sol = 0;
void dfs(long long int i, pair<long long int, long long int> range) {
  vis[i] = true;
  if (i == n) g = true;
  for (auto it : v[i]) {
    if (!vis[it.first] && it.second.first <= range.first &&
        it.second.second >= range.second)
      dfs(it.first, range);
  }
}
void solve(long long int bound) {
  long long int l = 1, r = bound;
  long long int ans = bound + 1;
  while (l <= r) {
    long long int mid = (l + r) >> 1;
    g = false;
    fill(vis, vis + n + 1, false);
    dfs(1, {mid, bound});
    if (g) {
      ans = min(ans, mid);
      r = mid - 1;
    } else
      l = mid + 1;
  }
  sol = max(sol, bound + 1 - ans);
}
vector<pair<long long int, long long int>> edges;
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int tests = 1;
  for (long long int ii = 0; ii < tests; ii++) {
    cin >> n >> m;
    for (long long int i = 0; i < m; i++) {
      long long int x, y, l, r;
      cin >> x >> y >> l >> r;
      if (x == y) continue;
      v[x].push_back({y, {l, r}});
      v[y].push_back({x, {l, r}});
      edges.push_back({l, r});
    }
    for (auto it : edges) solve(it.second);
    string second = "Nice work, Dima!";
    if (sol > 0)
      cout << sol << '\n';
    else
      cout << second << '\n';
  }
  return 0;
}
