#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, m, a, b, l, r, cost[N];
set<int> st;
bool vis[N];
struct edge {
  int to, l, r;
  edge(int _to, int _l, int _r) {
    to = _to;
    l = _l;
    r = _r;
  }
};
vector<edge> g[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d%d", &a, &b, &l, &r);
    g[a].push_back(edge(b, l, r));
    g[b].push_back(edge(a, l, r));
    st.insert(l);
  }
  int best = 0;
  for (set<int>::iterator it = st.begin(); it != st.end(); it++) {
    int L = *it;
    int lo = 0, hi = 1000000;
    while (lo <= hi) {
      int mid = (lo + hi) / 2;
      memset(vis, 0, sizeof vis);
      queue<int> q;
      vis[1] = 1;
      q.push(1);
      while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int i = 0; i < g[u].size(); ++i) {
          edge e = g[u][i];
          if (!vis[e.to] && e.l <= L && e.r >= mid) {
            q.push(e.to);
            vis[e.to] = 1;
          }
        }
      }
      if (vis[n]) {
        best = max(best, mid - L + 1);
        lo = mid + 1;
      } else {
        hi = mid - 1;
      }
    }
  }
  if (best <= 0) {
    puts("Nice work, Dima!");
    return 0;
  }
  printf("%d\n", best);
  return 0;
}
