#include <bits/stdc++.h>
using namespace std;
const int N = 3333;
int n, m, a[N], b[N], l[N], r[N], p[N];
int getp(int x) { return x == p[x] ? x : (p[x] = getp(p[x])); }
bool ck(int lb, int ub) {
  for (int i = 0; i < n; ++i) p[i] = i;
  for (int i = 0; i < m; ++i)
    if (l[i] <= lb && ub <= r[i] && a[i] != b[i]) p[getp(a[i])] = getp(b[i]);
  return getp(0) == getp(n - 1);
}
int sol(int lb) {
  int L = 0, R = 1e6;
  while (R - L > 1) {
    int M = (L + R) / 2;
    if (ck(lb, lb + M)) {
      L = M;
    } else {
      R = M;
    }
  }
  return ck(lb, lb + R) ? R + 1 : (ck(lb, lb + L) ? L + 1 : 0);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> a[i] >> b[i] >> l[i] >> r[i];
    --a[i];
    --b[i];
  }
  int ans = 0;
  for (int i = 0; i < m; ++i) ans = max(ans, sol(l[i]));
  if (!ans)
    cout << "Nice work, Dima!" << endl;
  else
    cout << ans << endl;
  return 0;
}
