#include <bits/stdc++.h>
using namespace std;
struct st {
  int x, y;
  int lo, up;
} ar[3001];
bool operator<(const st &a, const st &b) { return a.up > b.up; };
vector<int> v[3001];
int id[3001];
void merge(int x, int y) {
  x = id[x], y = id[y];
  if (x == y) return;
  if (v[x].size() < v[y].size()) swap(x, y);
  int omar = v[y].size();
  for (int i = 0; i < omar; ++i) {
    id[v[y][i]] = x;
    v[x].push_back(v[y][i]);
  }
  v[y].clear();
}
int n, m, best = 0;
void nk7(int x) {
  for (int i = 1; i <= n; ++i) id[i] = i, v[i].clear(), v[i].push_back(i);
  for (int i = 1; i <= m; ++i) {
    if (ar[i].lo > x) continue;
    merge(ar[i].x, ar[i].y);
    if (id[1] == id[n]) {
      best = max(best, ar[i].up - x + 1);
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i)
    scanf("%d%d%d%d", &ar[i].x, &ar[i].y, &ar[i].lo, &ar[i].up);
  sort(ar + 1, ar + 1 + m);
  for (int i = 1; i <= m; ++i) nk7(ar[i].lo);
  if (best == 0)
    puts("Nice work, Dima!");
  else
    cout << best << endl;
}
