#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9;
const int N = (int)1e3 + 7;
const double eps = 1e-6;
bool eq(const double &a, const double &b) { return fabs(a - b) < eps; }
bool ls(const double &a, const double &b) { return a + eps < b; }
bool le(const double &a, const double &b) { return eq(a, b) || ls(a, b); }
char read_char() {
  char c;
  for (;;) {
    c = getchar();
    if (c >= 'A' && c <= 'Z') return c;
  }
}
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= MOD;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int add(int a, int b) {
  if ((a += b) >= MOD) a -= MOD;
  return a;
}
int mul(int a, int b) { return 1ll * a * b % MOD; }
int n, m, vis[N];
vector<int> lpos, rpos;
vector<pair<int, pair<int, int> > > e[N];
void Init() {
  lpos.clear();
  rpos.clear();
  rpos.push_back(0);
  for (int i = (0); i < (m); ++i) {
    int u, v, l, r;
    scanf("%d%d%d%d", &u, &v, &l, &r);
    e[u].push_back({v, {l, r}});
    e[v].push_back({u, {l, r}});
    lpos.push_back(l);
    rpos.push_back(r);
  }
  sort((lpos).begin(), (lpos).end());
  sort((rpos).begin(), (rpos).end());
}
bool check(int x, int l, int r) {
  if (x == n) return true;
  for (int i = (0); i < ((int)(e[x]).size()); ++i) {
    auto t = e[x][i];
    if (!vis[t.first] && t.second.first <= l && t.second.second >= r) {
      vis[t.first] = 1;
      if (check(t.first, l, r)) return true;
    }
  }
  return false;
}
int Solve() {
  int maxr = (int)(rpos).size() - 1, ans = 0;
  for (int i = (0); i < ((int)(lpos).size()); ++i) {
    int down = lpos[i];
    int L = 0, R = maxr, ok = 0;
    while (L < R) {
      int M = L + ((R - L + 1) >> 1);
      int up = rpos[M];
      memset(vis, 0, sizeof(vis));
      if (down <= up && check(1, down, up))
        L = M, ok = 1;
      else
        R = M - 1;
    }
    if (ok) ans = max(ans, rpos[L] - down + 1);
  }
  if (!ans)
    return !puts("Nice work, Dima!");
  else
    return !printf("%d\n", ans);
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    Init();
    Solve();
  }
  return 0;
}
