#include <bits/stdc++.h>
using namespace std;
const int INF = numeric_limits<int>::max();
const long long LLINF = numeric_limits<long long>::max();
const unsigned long long ULLINF = numeric_limits<unsigned long long>::max();
const double PI = acos(-1.0);
struct edge {
  int to, l, r;
};
int n, m;
vector<vector<edge>> g;
set<int> ls;
vector<int> check;
int curL, curR;
bool used[1010];
void dfs(int v) {
  used[v] = 1;
  for (auto k : g[v]) {
    int to = k.to, l = k.l, r = k.r;
    if (l > curL || r < curR) continue;
    if (!used[to]) dfs(to);
  }
}
bool pos(int val) {
  for (int i : check) {
    memset(used, 0, sizeof(used));
    curL = i, curR = i + val - 1;
    dfs(0);
    if (used[n - 1]) return 1;
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  g.resize(n);
  for (int i = 0; i < m; i++) {
    int a, b, l, r;
    cin >> a >> b >> l >> r;
    a--, b--;
    g[a].push_back({b, l, r});
    g[b].push_back({a, l, r});
    ls.insert(l);
  }
  for (auto k : ls) check.push_back(k);
  int l = 1, r = 1000000, res = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (pos(mid))
      res = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  if (!res)
    cout << "Nice work, Dima!";
  else
    cout << res;
  return 0;
}
