#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
template <typename T>
void trace(T *a, int s, int n) {
  for (int i = s; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
const long long mod = 1e9 + 7;
const int maxn = 1e6 + 5;
int n, m;
struct edge {
  int a, b, l, r;
};
vector<edge> edges;
int par[maxn];
int siz[maxn];
int parent(int x) { return x == par[x] ? x : par[x] = parent(par[x]); }
void join(int x, int y) {
  x = parent(x);
  y = parent(y);
  if (x == y) return;
  if (siz[x] < siz[y]) {
    swap(x, y);
  }
  par[y] = x;
  siz[x] += siz[y];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, l, r;
    cin >> a >> b >> l >> r;
    edges.push_back({a, b, l, r});
  }
  auto cmp = [](edge e1, edge e2) { return e1.r > e2.r; };
  sort(edges.begin(), edges.end(), cmp);
  int ans = 0;
  for (auto ed : edges) {
    for (int i = 1; i <= n; i++) {
      par[i] = i;
      siz[i] = 1;
    }
    int lo = ed.l;
    int hi = ed.r;
    for (auto e : edges) {
      int l = e.l;
      int r = e.r;
      if (l > lo || r < lo) continue;
      join(e.a, e.b);
      if (parent(1) == parent(n)) {
        ans = max(ans, min(r, hi) - lo + 1);
      }
    }
  }
  if (!ans) out("Nice work, Dima!");
  out(ans);
  return 0;
}
