#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int maxn = 10000 + 10;
const int maxm = 1000;
struct E {
  int to, next;
  int l, r;
} e[maxn];
int head[maxn], vis[maxn], cnt;
bool ok;
int n, m, tot;
int point[maxn];
inline void addedge(int u, int v, int l, int r) {
  e[cnt].to = v;
  e[cnt].next = head[u];
  e[cnt].l = l;
  e[cnt].r = r;
  head[u] = cnt++;
}
inline void add(int u, int v, int l, int r) {
  addedge(u, v, l, r);
  addedge(v, u, l, r);
}
inline 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);
    }
  }
}
inline void solve() {
  int ans = 0;
  for (int i = (1); i <= (tot); i++) {
    int l = point[i];
    int r = 1000005;
    while (l < r) {
      int mid = (l + r) >> 1;
      ok = 0;
      memset((vis), (0), sizeof(vis));
      vis[1] = 1;
      dfs(1, point[i], mid);
      if (ok)
        l = mid + 1;
      else
        r = mid;
    }
    ans = max(ans, l - point[i]);
  }
  if (ans == 0)
    cout << "Nice work, Dima!" << endl;
  else
    cout << ans << endl;
}
int main() {
  cin >> n >> m;
  memset((head), (-1), sizeof(head)), cnt = 0, tot = 0;
  int u, v, l, r;
  for (int i = (1); i <= (m); i++) {
    cin >> u >> v >> l >> r;
    point[++tot] = l;
    point[++tot] = r;
    add(u, v, l, r);
  }
  solve();
  return 0;
}
