#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void umax(T &x, T y) {
  if (y > x) x = y;
}
template <class T>
inline void umin(T &x, T y) {
  if (y < x) x = y;
}
const int N = 2e5 + 5, B = 0x7fffffff;
struct edge {
  int u, v, l, r;
} a[N];
vector<pair<int, pair<int, int>>> g[N];
int n, m;
int ans;
bool bfs(int x, int ql, int qr) {
  bool vis[N];
  memset(vis, 0, sizeof vis);
  queue<int> Q;
  Q.push(x);
  vis[x] = 1;
  while (!Q.empty()) {
    int fr = Q.front();
    Q.pop();
    for (pair<int, pair<int, int>> ss : g[fr]) {
      if (vis[ss.first] != 1 && ss.second.first <= ql &&
          qr <= ss.second.second) {
        vis[ss.first] = 1;
        Q.push(ss.first);
      }
    }
  }
  return vis[n];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &a[i].u, &a[i].v, &a[i].l, &a[i].r);
    int x = a[i].u;
    int y = a[i].v;
    int l = a[i].l;
    int r = a[i].r;
    g[x].push_back({y, {l, r}});
    g[y].push_back({x, {l, r}});
  }
  for (int i = 1; i <= m; i++) {
    int l = 1, r = 1e9, ann = -1;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (bfs(1, a[i].l, mid))
        l = mid + 1, ann = mid;
      else
        r = mid - 1;
    }
    if (ann != -1) umax(ans, (ann - a[i].l) + 1);
  }
  if (ans == 0)
    puts("Nice work, Dima!");
  else
    printf("%d", ans);
  return !!0;
}
