#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
const int maxm = 3e3 + 5;
struct DSU {
  int lab[maxn];
  void Init(void) { memset(lab, -1, sizeof lab); }
  int finds(int u) {
    if (lab[u] < 0) return u;
    return lab[u] = finds(lab[u]);
  }
  bool same(int u, int v) { return finds(u) == finds(v); }
  void merges(int u, int v) {
    u = finds(u);
    v = finds(v);
    if (u == v) return;
    if (lab[v] < lab[u]) swap(u, v);
    lab[u] += lab[v];
    lab[v] = u;
  }
} dsu;
int N, M;
struct edge_list {
  int u, v, L, R;
} edge[maxm];
bool check(int Left, int Right) {
  dsu.Init();
  for (int i = 1; i <= M; ++i)
    if (edge[i].L <= Left && edge[i].R >= Right)
      dsu.merges(edge[i].u, edge[i].v);
  return dsu.same(1, N);
}
signed main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  set<int> canLeft;
  cin >> N >> M;
  for (int i = 1; i <= M; ++i)
    cin >> edge[i].u >> edge[i].v >> edge[i].L >> edge[i].R,
        canLeft.insert(edge[i].L);
  int res = 0;
  for (auto it : canLeft) {
    int Left = it;
    int l = Left, r = 1e6, mid;
    while (l <= r) {
      mid = (l + r) / 2;
      if (check(Left, mid))
        l = mid + 1;
      else
        r = mid - 1;
    }
    res = max(res, r - Left + 1);
  }
  if (res)
    cout << res << '\n';
  else
    cout << "Nice work, Dima!\n";
}
