#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > st[1010];
int n;
map<int, int> v[1010];
vector<pair<int, pair<int, int> > > p[1010];
int dik() {
  priority_queue<pair<pair<int, int>, pair<int, int> > > q;
  q.push(make_pair(make_pair(1000000, 1), make_pair(1, 1000000)));
  pair<pair<int, int>, pair<int, int> > t;
  while (!q.empty()) {
    t = q.top();
    int u = t.first.second;
    int l = t.second.first;
    int r = t.second.second;
    int res = t.first.first;
    q.pop();
    if (v[u].count(l)) continue;
    v[u][l] = r;
    if (u == n) return res;
    for (int i = 0; i < p[u].size(); i++) {
      int vv = p[u][i].first;
      int l1 = p[u][i].second.first;
      int r1 = p[u][i].second.second;
      if (r1 < l || l1 > r) continue;
      int l2 = max(l1, l);
      int r2 = min(r1, r);
      if (v[vv].count(l2) == 0 || r2 > v[vv][l2])
        q.push(make_pair(make_pair(r2 - l2 + 1, vv), make_pair(l2, r2)));
    }
  }
  int maxx = 0;
  for (int i = 1; i <= 1000000; i++) {
    if (v[n].count(i)) maxx = max(maxx, v[n][i] - i + 1);
  }
  return maxx;
}
int main() {
  cin >> n;
  int m, a, b, x, y;
  cin >> m;
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d%d", &a, &b, &x, &y);
    p[a].push_back(make_pair(b, make_pair(x, y)));
    p[b].push_back(make_pair(a, make_pair(x, y)));
  }
  int res = dik();
  if (!res) {
    cout << "Nice work, Dima!";
  } else {
    cout << res;
  }
  return 0;
}
