#include <bits/stdc++.h>
using namespace std;
struct node {
  int u, l, r;
};
vector<node> a[1001];
int n, m, d[1001], lef, rig, ans = 0;
bool kt;
vector<int> trai, phai;
node mr(int q, int w, int e) {
  node t;
  t.u = q;
  t.l = w;
  t.r = e;
  return t;
}
void dfs(int u) {
  d[u] = 1;
  if (u == n) {
    kt = true;
    return;
  }
  for (auto v : a[u]) {
    int o = v.u;
    if (d[o] == 0 && lef >= v.l && rig <= v.r) dfs(o);
  }
}
bool check(int l, int r) {
  lef = l;
  rig = r;
  memset(d, 0, sizeof(d));
  kt = false;
  dfs(1);
  return kt;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v, l, r;
    cin >> u >> v >> l >> r;
    a[u].push_back(mr(v, l, r));
    a[v].push_back(mr(u, l, r));
    trai.push_back(l);
    phai.push_back(r);
  }
  sort(phai.begin(), phai.end());
  for (int i = 0; i < m; i++) {
    int l = 0, r = m - 1;
    int x = trai[i];
    while (l <= r) {
      int mid = (l + r) / 2;
      int y = phai[mid];
      if (check(x, y)) {
        ans = max(ans, y - x + 1);
        l = mid + 1;
      } else
        r = mid - 1;
    }
  }
  if (ans == 0)
    cout << "Nice work, Dima!";
  else
    cout << ans;
}
