#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1e3 + 5;
vector<pair<int, int> > E[N];
bitset<N> seen;
int n, m;
int x[3 * N], y[3 * N];
bool dfs(int node, int L, int R) {
  if (node == n) return true;
  seen[node] = true;
  bool ok = false;
  for (const auto &p : E[node]) {
    if (seen[p.first]) continue;
    if (x[p.second] <= L && R <= y[p.second]) {
      ok |= dfs(p.first, L, R);
    }
  }
  return ok;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  for (int i = 1, a, b; i <= m; i++) {
    cin >> a >> b >> x[i] >> y[i];
    E[a].emplace_back(b, i);
    E[b].emplace_back(a, i);
  }
  int result = 0;
  for (int i = 1; i <= m; i++) {
    int L = x[i], l = x[i], r = y[i];
    while (l <= r) {
      int R = (l + r) / 2;
      seen.reset();
      if (dfs(1, L, R)) {
        result = max(result, R - L + 1);
        l = R + 1;
      } else {
        r = R - 1;
      }
    }
  }
  if (result == 0)
    cout << "Nice work, Dima!\n";
  else
    cout << result << "\n";
}
