#include <bits/stdc++.h>
using namespace std;
struct path {
  int pointat, prev, l, r;
};
priority_queue<pair<int, int> > pq;
vector<int> st;
int edge, h[11111], d[11111], n, m;
path e[11111];
bool pass[11111];
void setlink(int u, int v, int l, int r) {
  edge++;
  e[edge].pointat = v;
  e[edge].prev = h[u];
  h[u] = edge;
  e[edge].l = l;
  e[edge].r = r;
}
int dij(int s) {
  for (int i = 1; i <= n; i++) d[i] = 1000000000;
  for (int i = 1; i <= n; i++) pass[i] = true;
  d[1] = 0;
  while (!pq.empty()) pq.pop();
  pq.push(make_pair(-d[1], 1));
  int u, v, we, value;
  while (!pq.empty()) {
    u = pq.top().second;
    pq.pop();
    if (u == n) return s - d[u] + 1;
    if (pass[u]) {
      we = h[u];
      pass[u] = false;
      while (we) {
        v = e[we].pointat;
        if (e[we].r >= s) {
          value = max(d[u], e[we].l);
          if (d[v] > value) {
            d[v] = value;
            pq.push(make_pair(-d[v], v));
          }
        }
        we = e[we].prev;
      }
    }
  }
  return 0;
}
int main() {
  cin >> n >> m;
  edge = 0;
  memset(h, 0, sizeof(h));
  int u, v, l, r;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &u, &v, &l, &r);
    setlink(u, v, l, r);
    setlink(v, u, l, r);
    st.push_back(r);
  }
  sort(st.begin(), st.end());
  int ans = 0;
  for (int i = 0; i <= int(st.size()) - 1; i++) ans = max(ans, dij(st[i]));
  if (ans)
    cout << ans;
  else
    cout << "Nice work, Dima!";
  return 0;
}
