#include <bits/stdc++.h>
using namespace std;
int fa[5000];
struct node {
  int from, to, low, high;
} pp[10000];
bool cmp(node a, node b) { return a.low < b.low; }
int find(int x) {
  if (fa[x] != x) fa[x] = find(fa[x]);
  return fa[x];
}
int main() {
  int i, j, k, m, n;
  while (cin >> n >> m) {
    for (i = 0; i < m; i++)
      cin >> pp[i].from >> pp[i].to >> pp[i].low >> pp[i].high;
    sort(pp, pp + m, cmp);
    int ans = 0;
    for (i = 0; i < m; i++) {
      for (j = 1; j <= n; j++) fa[j] = j;
      int L = 0;
      for (j = 0; j < m; j++)
        if (pp[j].high >= pp[i].high) {
          int fx = find(pp[j].from);
          int fy = find(pp[j].to);
          if (fx == fy) continue;
          fa[fx] = fy;
          if (find(1) == find(n)) ans = max(ans, pp[i].high - pp[j].low + 1);
        }
    }
    if (ans > 0)
      cout << ans << endl;
    else
      puts("Nice work, Dima!");
  }
  return 0;
}
