#include <bits/stdc++.h>
using namespace std;
struct range_t {
  int rmin, rmax;
  range_t() {}
  range_t(int rmin, int rmax) : rmin(rmin), rmax(rmax) {}
  int size() { return rmax - rmin + 1; }
};
struct edge_t {
  int from, to;
  range_t range;
  edge_t() {}
  edge_t(int from, int to, range_t range) : from(from), to(to), range(range) {}
};
const int MAXN = 1005;
int N;
int M;
vector<edge_t> adj[MAXN];
vector<int> S;
bool seen[1000005];
int ub[MAXN];
range_t path(int lb) {
  priority_queue<pair<int, int> > Q;
  fill(ub, ub + MAXN, 0);
  ub[1] = 1000000;
  Q.push(pair<int, int>(ub[1], 1));
  while (!Q.empty()) {
    int v = Q.top().second;
    if (Q.top().first != ub[v]) {
      Q.pop();
      continue;
    } else
      Q.pop();
    for (vector<edge_t>::const_iterator e = adj[v].begin(); e != adj[v].end();
         ++e) {
      int u = e->to;
      int w = (e->range).rmax;
      if ((e->range).rmin > lb || w < lb) continue;
      if (min(ub[v], w) > ub[u]) {
        ub[u] = min(ub[v], w);
        Q.push(pair<int, int>(ub[u], u));
      }
    }
  }
  if (ub[N] < lb)
    return range_t(0, 0);
  else
    return range_t(lb, ub[N]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    int from, to, rmin, rmax;
    cin >> from >> to >> rmin >> rmax;
    adj[from].push_back(edge_t(from, to, range_t(rmin, rmax)));
    adj[to].push_back(edge_t(to, from, range_t(rmin, rmax)));
    S.push_back(rmin);
  }
  range_t best(0, 0);
  for (vector<int>::const_iterator it = S.begin(); it != S.end(); ++it) {
    if (seen[*it]) continue;
    seen[*it] = true;
    range_t res = path(*it);
    if (res.size() >= best.size()) best = res;
  }
  if (best.rmax != 0)
    cout << best.size() << endl;
  else
    cout << "Nice work, Dima!" << endl;
  return 0;
}
