#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int u, v, l;
  Edge(){};
  Edge(int u, int v, int l) {
    this->u = u;
    this->v = v;
    this->l = l;
  };
};
const long long Inf = 1e9;
const int N = 1111;
vector<Edge> all[1000011];
vector<Edge> g[N];
int n, m;
long long p[N];
bool mark[N];
set<pair<long long, long long> > s;
long long dijkstra() {
  fill(p, p + N, Inf);
  fill(mark, mark + N, false);
  s.clear();
  int node = 0;
  p[node] = 0;
  for (int i = 0; i < n; i++) {
    mark[node] = true;
    for (int j = 0; j < g[node].size(); j++) {
      int v = g[node][j].v;
      int w = max(1LL * g[node][j].l, p[node]);
      if (!mark[v] && p[v] > w) {
        s.erase(make_pair(p[v], v));
        p[v] = w;
        s.insert(make_pair(w, v));
      }
    }
    if (s.empty()) break;
    node = s.begin()->second;
    p[node] = s.begin()->first;
    s.erase(s.begin());
  }
  return p[n - 1];
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, l, r;
    scanf("%d %d %d %d", &a, &b, &l, &r);
    all[r].push_back(Edge(--a, --b, l));
  }
  long long ans = 0;
  for (int i = 1000000; i > 0; i--)
    for (int j = 0; j < all[i].size(); j++) {
      g[all[i][j].u].push_back(all[i][j]);
      Edge temp = all[i][j];
      swap(temp.u, temp.v);
      g[temp.u].push_back(temp);
      ans = max(1LL * i - dijkstra() + 1, ans);
    }
  if (ans <= 0) return cout << "Nice work, Dima!" << endl, 0;
  cout << ans << endl;
}
