#include <bits/stdc++.h>
using namespace std;
inline int max(int a, int b) { return a > b ? a : b; }
inline int min(int a, int b) { return a < b ? a : b; }
const int maxn = 1005;
struct ed {
  int to, next, l, r;
} e[6005];
int head[maxn], cnt, n, m, ans, mx[maxn], mi[maxn];
void ad(int x, int y, int l, int r) {
  e[cnt] = (ed){y, head[x], l, r};
  head[x] = cnt++;
  e[cnt] = (ed){x, head[y], l, r};
  head[y] = cnt++;
}
void dfs(int u, int l, int r) {
  if ((l >= mi[u] && r <= mx[u]) || l > r || r - l + 1 <= ans) return;
  mi[u] = l;
  mx[u] = r;
  if (u == n) {
    ans = max(ans, mx[u] - mi[u] + 1);
    return;
  }
  for (int k = head[u]; k != -1; k = e[k].next) {
    int v = e[k].to;
    dfs(v, max(mi[u], e[k].l), min(mx[u], e[k].r));
  }
}
int main() {
  int a, b, l, r;
  memset(head, -1, sizeof(head));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &a, &b, &l, &r);
    ad(a, b, l, r);
  }
  memset(mi, 0x3f3f3f3f, sizeof(mx));
  dfs(1, 1, 1000000);
  if (ans)
    printf("%d", ans);
  else
    printf("Nice work, Dima!");
  return 0;
}
