#include <bits/stdc++.h>
using namespace std;
int n, m;
struct edge {
  int a, b, l, r;
  void input() { scanf("%d %d %d %d", &a, &b, &l, &r); }
};
vector<edge> e;
vector<edge> v[1010];
set<int> l;
set<int> r;
vector<int> vl;
vector<int> vr;
bool isSearch[1010];
bool dfs(int now, int l, int r) {
  isSearch[now] = 1;
  for (int i = 0; i < v[now].size(); ++i) {
    int nxt = v[now][i].a;
    if (nxt == now) nxt = v[now][i].b;
    if (!isSearch[nxt]) {
      if (v[now][i].l <= l && v[now][i].r >= r) dfs(nxt, l, r);
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  int ans = -1;
  for (int i = 0; i < m; ++i) {
    edge t;
    t.input();
    if (t.a != t.b) {
      l.insert(t.l);
      r.insert(t.r);
      e.push_back(t);
      v[t.a].push_back(t);
      v[t.b].push_back(t);
    }
  }
  vl = vector<int>(l.begin(), l.end());
  vr = vector<int>(r.begin(), r.end());
  for (int i = 0; i < vl.size(); ++i) {
    int st = 0, ed = vr.size();
    while (st <= ed) {
      int mid = (st + ed) >> 1;
      if (vr[mid] < vl[i] || vr[mid] - vl[i] + 1 <= ans) {
        st = mid + 1;
        continue;
      }
      memset(isSearch, 0, sizeof(isSearch));
      dfs(1, vl[i], vr[mid]);
      if (isSearch[n]) {
        st = mid + 1;
        ans = max(ans, vr[mid] - vl[i] + 1);
      } else
        ed = mid - 1;
    }
  }
  if (ans == -1) {
    printf("Nice work, Dima!\n");
  } else
    printf("%d\n", ans);
}
