#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > e[1000][1000];
vector<int> ea[1000];
set<int> c;
set<int> d;
int lc[3000], rc[3000];
int nl, nr;
bool vis[1000], done[1000][1000];
int n;
bool dfs(int i, int lx, int rx) {
  vis[i] = 1;
  if (i == n - 1) return 1;
  bool ret = 0;
  int sz = ea[i].size();
  for (int j = 0; j < sz; j++) {
    int to = ea[i][j];
    int szt = e[i][to].size();
    for (int k = 0; k < szt; k++)
      if (!vis[to] && lx >= e[i][to][k].first && rx <= e[i][to][k].second) {
        ret |= dfs(to, lx, rx);
        if (ret) break;
      }
    if (ret) break;
  }
  return ret;
}
int main() {
  int m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b, l, r;
    scanf(" %d%d%d%d", &a, &b, &l, &r);
    a--, b--;
    if (!done[a][b]) {
      ea[a].push_back(b);
      ea[b].push_back(a);
      done[a][b] = done[b][a] = 1;
    }
    e[a][b].push_back(make_pair(l, r));
    e[b][a].push_back(make_pair(l, r));
    c.insert(l);
    d.insert(r);
  }
  for (set<int>::iterator it = c.begin(); it != c.end(); ++it) lc[nl++] = *it;
  for (set<int>::iterator it = d.begin(); it != d.end(); ++it) rc[nr++] = *it;
  c.clear();
  d.clear();
  int count = -1;
  for (int i = 0; i < nl; i++) {
    int lo = 0, hi = nr - 1, s = -1;
    while (lo <= hi) {
      int mid = (lo + hi) / 2;
      if (rc[mid] < lc[i])
        lo = mid + 1;
      else {
        s = mid;
        hi = mid - 1;
      }
    }
    if (s == -1) break;
    lo = s, hi = nr - 1;
    while (lo <= hi) {
      int mid = (lo + hi) / 2;
      memset(vis, 0, sizeof(vis));
      if (dfs(0, lc[i], rc[mid])) {
        count = max(count, rc[mid] - lc[i] + 1);
        lo = mid + 1;
      } else
        hi = mid - 1;
    }
  }
  if (count < 0)
    printf("Nice work, Dima!\n");
  else
    printf("%d\n", count);
  return 0;
}
