#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
double EPS = 1e-7;
int INF = 1000000000;
int MOD = 1000000007;
int MAXINT = 2147483647;
long long INFLL = 1000000000000000000LL;
long long MAXLL = 9223372036854775807LL;
int mx[8] = {-1, 1, 0, 0, -1, -1, 1, 1};
int my[8] = {0, 0, -1, 1, -1, 1, -1, 1};
vector<pair<int, pair<int, int> > > adj[1005];
vector<int> range;
int vs[1005];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int(a) = (1); (a) <= (m); (a)++) {
    int u, v, l, r;
    scanf("%d%d%d%d", &u, &v, &l, &r);
    adj[u].push_back(make_pair(v, make_pair(l, r)));
    adj[v].push_back(make_pair(u, make_pair(l, r)));
    range.push_back(r);
  }
  int maks = 0;
  for (int(a) = (0); (a) <= ((int)range.size() - 1); (a)++) {
    for (int(b) = (1); (b) <= (n); (b)++) vs[b] = INF;
    int check = range[a];
    priority_queue<pair<int, int>, vector<pair<int, int> >,
                   greater<pair<int, int> > >
        q;
    q.push(make_pair(-INF, 1));
    vs[1] = -INF;
    while (!q.empty()) {
      int val = q.top().first;
      int cur = q.top().second;
      q.pop();
      if (vs[cur] == val) {
        for (int(b) = (0); (b) <= ((int)adj[cur].size() - 1); (b)++) {
          if (adj[cur][b].second.first <= check &&
              check <= adj[cur][b].second.second) {
            if (vs[adj[cur][b].first] > max(val, adj[cur][b].second.first)) {
              vs[adj[cur][b].first] = max(val, adj[cur][b].second.first);
              q.push(make_pair(max(val, adj[cur][b].second.first),
                               adj[cur][b].first));
            }
          }
        }
      }
    }
    if (vs[n] != INF) {
      (maks) = max((maks), (check - vs[n] + 1));
    }
  }
  if (maks == 0)
    puts("Nice work, Dima!");
  else
    printf("%d\n", maks);
}
