#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long num = 0;
  int fix = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') fix = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    num = num * 10 + ch - '0';
    ch = getchar();
  }
  return num * fix;
}
const int MAXM = 3e3;
const int MAXN = 1e3;
int N, M;
int U[MAXM + 1], V[MAXM + 1], L[MAXM + 1], R[MAXM + 1];
int bel[MAXN + 1];
struct edge {
  int u, v, w;
} e[MAXM + 2];
int findset(int a) { return a == bel[a] ? a : bel[a] = findset(bel[a]); }
int comp(const edge& a, const edge& b) { return a.w > b.w; }
int kruskal(int x) {
  int ecnt = 0;
  for (int i = 1; i <= M; i++)
    if (L[i] <= x) {
      e[++ecnt] = (edge){U[i], V[i], R[i]};
    }
  sort(e + 1, e + ecnt + 1, comp);
  for (int i = 1; i <= N; i++) {
    bel[i] = i;
  }
  for (int i = 1; i <= ecnt; i++) {
    int u = e[i].u, v = e[i].v, w = e[i].w;
    if (findset(u) == findset(v)) continue;
    bel[findset(u)] = findset(v);
    if (findset(1) == findset(N)) return w;
  }
  return -1;
}
void solve() {
  int ans = 0;
  for (int i = 1; i <= M; i++) {
    int MST = kruskal(L[i]);
    if (MST == -1) continue;
    ans = max(ans, MST - L[i] + 1);
  }
  if (ans == 0)
    puts("Nice work, Dima!");
  else
    printf("%d\n", ans);
}
int main() {
  N = read();
  M = read();
  for (int i = 1; i <= M; i++) {
    U[i] = read();
    V[i] = read();
    L[i] = read();
    R[i] = read();
  }
  solve();
  return 0;
}
