#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    heap;
struct edge {
 public:
  int l, r, v;
};
vector<edge> N[2000];
edge E[4000];
int n, m;
int dis[2000];
int di(int r, int v) {
  for (int i = 0; i < N[v].size(); i++) {
    if (N[v][i].r >= r && dis[N[v][i].v] == -1)
      heap.push(make_pair(max(N[v][i].l, dis[v]), N[v][i].v));
  }
  while (!heap.empty() && dis[heap.top().second] != -1) heap.pop();
  if (heap.empty()) {
    return r + 1;
  }
  pair<int, int> x = heap.top();
  dis[x.second] = x.first;
  heap.pop();
  if (x.second == n - 1) return dis[n - 1];
  return di(r, x.second);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, l, r;
    cin >> a >> b >> l >> r;
    a--;
    b--;
    edge x;
    x.v = b;
    x.l = l;
    x.r = r;
    N[a].push_back(x);
    x.v = a;
    N[b].push_back(x);
    E[i] = x;
  }
  int ans = 0;
  dis[0] = 0;
  for (int i = 0; i < m; i++) {
    fill(dis, dis + 1100, -1);
    dis[0] = -2;
    heap = priority_queue<pair<int, int>, vector<pair<int, int> >,
                          greater<pair<int, int> > >();
    ans = max(E[i].r - di(E[i].r, 0) + 1, ans);
  }
  if (ans <= 0) return cout << "Nice work, Dima!", 0;
  cout << ans << endl;
}
