#include <bits/stdc++.h>
using namespace std;
int num, head[1005];
int n, m;
int vis[1005];
struct edge {
  int u, v, l, r, next;
} e[6005];
void addedge(int u, int v, int l, int r) {
  e[num].u = u;
  e[num].v = v;
  e[num].l = l;
  e[num].r = r;
  e[num].next = head[u];
  head[u] = num++;
}
void dfs(int u, int L, int R) {
  int i, v;
  vis[u] = 1;
  for (i = head[u]; i != -1; i = e[i].next) {
    v = e[i].v;
    if (!vis[v] && e[i].l <= L && e[i].r >= R) dfs(v, L, R);
  }
}
int check(int L, int R) {
  memset(vis, 0, sizeof(vis));
  dfs(1, L, R);
  return vis[n];
}
void work(int lmin, int rmax) {
  int i, j, d = 0, l, r, m;
  for (i = lmin; i <= rmax; i++) {
    l = i + d;
    r = rmax;
    while (l <= r) {
      m = (l + r) >> 1;
      if (check(i, m))
        l = m + 1;
      else
        r = m - 1;
    }
    d = max(d, r - i + 1);
  }
  if (d == 0)
    printf("Nice work, Dima!\n");
  else
    printf("%d\n", d);
}
void init() {
  num = 0;
  memset(head, -1, sizeof(head));
}
int main() {
  int i, u, v, l, r, lmin, rmax;
  while (scanf("%d%d", &n, &m) != EOF) {
    lmin = 1 << 30, rmax = -1;
    init();
    for (i = 1; i <= m; i++) {
      scanf("%d%d%d%d", &u, &v, &l, &r);
      addedge(u, v, l, r);
      addedge(v, u, l, r);
      lmin = min(lmin, l);
      rmax = max(rmax, r);
    }
    work(lmin, rmax);
  }
  return 0;
}
