#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000;
vector<int> g[maxn], leftt;
int a[maxn], b[maxn], used[maxn], l[maxn], r[maxn], ans = -1, n, m, clr;
bool dfs(int v, int x1, int x2, int color) {
  if (v == n) return true;
  used[v] = color;
  int id, to;
  for (int i = 0; i < (int)g[v].size(); i++) {
    id = g[v][i];
    to = b[id];
    if (l[id] <= x1 && r[id] >= x2 && used[to] != color &&
        dfs(to, x1, x2, color))
      return true;
  }
  return false;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i + i] >> b[i + i] >> l[i + i] >> r[i + i];
    leftt.push_back(l[i + i]);
    a[i + i + 1] = b[i + i];
    b[i + i + 1] = a[i + i];
    l[i + i + 1] = l[i + i];
    r[i + i + 1] = r[i + i];
    g[a[i + i]].push_back(i + i);
    g[b[i + i]].push_back(i + i + 1);
  }
  int ll, rr, mid;
  for (int i = 0; i < (int)leftt.size(); i++) {
    ll = leftt[i], rr = 1000001;
    while (rr - ll > 1) {
      mid = (ll + rr) / 2;
      if (dfs(1, leftt[i], mid, ++clr))
        ll = mid;
      else
        rr = mid;
    }
    if (dfs(1, leftt[i], ll, ++clr)) ans = max(ans, ll - leftt[i] + 1);
  }
  if (ans == -1)
    cout << "Nice work, Dima!";
  else
    cout << ans;
  return 0;
}
