#include <bits/stdc++.h>
using namespace std;
const int Max = 3e3 + 3;
int n, m, l[Max], r[Max], mx, mn = 1e6;
vector<pair<int, int>> G[Max];
bool vis[Max];
bool DFS(int u, int i, int j) {
  if (u == n) return 1;
  vis[u] = 1;
  for (auto v : G[u])
    if (!vis[v.first]) {
      int ii = l[v.second];
      int jj = r[v.second];
      if (ii <= i && j <= jj && DFS(v.first, i, j)) return 1;
    }
  return 0;
}
bool check(int x) {
  for (int i = mn; i + x - 1 <= mx; i++) {
    memset(vis, 0, sizeof(vis));
    if (DFS(1, i, i + x - 1)) return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, x, y;
    cin >> a >> b >> x >> y;
    G[a].push_back({b, i});
    G[b].push_back({a, i});
    l[i] = x;
    r[i] = y;
    mx = max(mx, y);
    mn = min(mn, x);
  }
  int l = 1, r = mx - mn + 1, mid, ans = -1;
  while (l <= r) {
    mid = l + r >> 1;
    if (check(mid))
      l = mid + 1, ans = mid;
    else
      r = mid - 1;
  }
  if (ans == -1)
    cout << "Nice work, Dima!" << endl;
  else
    cout << ans << endl;
  return 0;
}
