#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9, mod = 1e9 + 7;
const int N = 1e6 + 5;
int i, j, k, n, m, x, y, l, r, h[1001], H[N];
vector<pair<int, pair<int, int> > > v[N];
bool ctr(int node, int l, int r) {
  if (node == n) return true;
  bool flag = false;
  h[node] = 1;
  for (__typeof(v[node].begin()) it = v[node].begin(); it != v[node].end();
       it++)
    if (!h[it->first] && it->second.first <= l && r <= it->second.second)
      flag = max(flag, ctr(it->first, l, r));
  return flag;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d %d", &x, &y, &l, &r);
    v[x].push_back(make_pair(y, make_pair(l, r)));
    v[y].push_back(make_pair(x, make_pair(l, r)));
    H[l] = 1;
  }
  int ans = -1;
  for (int i = 1; i <= 1000000; i++) {
    if (H[i]) {
      int bas = i, son = 1000000;
      while (bas < son) {
        int orta = bas + son >> 1;
        if (orta == bas) orta++;
        memset(h, 0, sizeof h);
        if (ctr(1, i, orta))
          bas = orta;
        else
          son = orta - 1;
      }
      memset(h, 0, sizeof h);
      if (ctr(1, i, bas)) ans = max(ans, bas - i + 1);
    }
  }
  if (ans == -1)
    cout << "Nice work, Dima!" << '\n';
  else
    cout << ans << '\n';
  return 0;
}
