#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 5;
const int maxe = 6000 + 5;
struct NodeEdge {
  int to, next;
  int l, r;
} Edge[maxe];
int head[maxn], PosLeft[maxe], vis[maxn];
int cnt, numEdge, n, m;
bool isOk;
void addEdges(int u, int v, int l, int r) {
  numEdge++;
  Edge[numEdge].to = v;
  Edge[numEdge].l = l;
  Edge[numEdge].r = r;
  Edge[numEdge].next = head[u];
  head[u] = numEdge;
}
void dfs(int u, int l, int r) {
  if (u == n) {
    isOk = true;
    return;
  }
  for (int k = head[u]; k != -1; k = Edge[k].next) {
    int v = Edge[k].to;
    if (!vis[v] && l >= Edge[k].l && r <= Edge[k].r) {
      vis[v] = 1;
      dfs(v, l, r);
    }
  }
}
void solve() {
  int ans = 0, le, ri, mid;
  for (int i = 1; i <= cnt; i++) {
    le = PosLeft[i], ri = 1000000 + 1;
    while (le < ri) {
      mid = (le + ri) / 2;
      isOk = false;
      memset(vis, 0, sizeof(vis));
      vis[1] = 1;
      dfs(1, PosLeft[i], mid);
      if (isOk)
        le = mid + 1;
      else
        ri = mid;
    }
    ans = max(ans, le - PosLeft[i]);
  }
  if (ans == 0)
    printf("Nice work, Dima!\n");
  else
    printf("%d\n", ans);
}
int main() {
  int a, b, l, r;
  while (scanf("%d%d", &n, &m) == 2) {
    memset(head, -1, sizeof(head));
    cnt = numEdge = 0;
    for (int i = 1; i <= m; i++) {
      scanf("%d%d%d%d", &a, &b, &l, &r);
      addEdges(a, b, l, r);
      addEdges(b, a, l, r);
      PosLeft[++cnt] = l;
      PosLeft[++cnt] = r;
    }
    solve();
  }
  return 0;
}
