#include <bits/stdc++.h>
using namespace std;
struct st {
  int u, v, l, r;
} ar[3005];
bool operator<(const st &a, const st &b) { return a.r > b.r; };
int pi[3005];
int find(int x) { return (x == pi[x]) ? x : pi[x] = find(pi[x]); }
void merge(int x, int y) {
  x = find(x);
  y = find(y);
  pi[x] = y;
}
int n, m;
void init() {
  for (int i = 1; i <= n; ++i) {
    pi[i] = i;
  }
}
int ans = 0;
void solve(int x) {
  init();
  for (int i = 0; i < m; ++i) {
    if (ar[i].l > x) continue;
    merge(ar[i].u, ar[i].v);
    if (find(1) == find(n)) {
      ans = max(ans, ar[i].r - x + 1);
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d %d %d", &ar[i].u, &ar[i].v, &ar[i].l, &ar[i].r);
  }
  sort(ar, ar + m);
  ans = 0;
  for (int i = 0; i < m; ++i) {
    solve(ar[i].l);
  }
  if (ans == 0) {
    cout << "Nice work, Dima!";
  } else {
    cout << ans;
  }
  cout << endl;
}
