#include <bits/stdc++.h>
using namespace std;
const int maxm = 34005;
struct edge {
  int to, next;
  int l, r;
} e[maxm];
const int maxn = 2344;
int head[maxn], cnt;
bool vis[maxn];
int n, m, tot;
void add(int u, int v, int l, int r) {
  e[cnt] = (edge){v, head[u], l, r};
  e[cnt].to = v;
  e[cnt].next = head[u];
  e[cnt].l = l, e[cnt].r = r;
  head[u] = cnt++;
}
bool ok = 0;
void dfs(int u, int l, int r) {
  if (ok) return;
  if (u == n) {
    ok = 1;
    return;
  }
  for (int i = head[u]; ~i; i = e[i].next) {
    int v = e[i].to;
    if (!vis[v] && e[i].l <= l && e[i].r >= r) {
      vis[v] = 1;
      dfs(v, l, r);
    }
  }
}
int p[maxm << 3];
void solve() {
  int ans = 0;
  for (int i = 0; i < tot; i++) {
    int l = p[i];
    int r = 1e6 + 9;
    while (l < r) {
      int mid = (l + r) / 2;
      ok = 0;
      memset(vis, 0, sizeof vis);
      vis[1] = 1;
      dfs(1, p[i], mid);
      if (ok)
        l = mid + 1;
      else
        r = mid;
    }
    ans = max(ans, l - p[i]);
  }
  if (ans == 0)
    printf("Nice work, Dima!\n");
  else
    printf("%d\n", ans);
}
int main() {
  cin >> n >> m;
  memset(head, -1, sizeof head);
  cnt = tot = 0;
  while (m--) {
    int u, v, l, r;
    cin >> u >> v >> l >> r;
    p[tot++] = l;
    p[tot++] = r;
    add(u, v, l, r);
    add(v, u, l, r);
  }
  solve();
}
