#include <bits/stdc++.h>
using namespace std;
class dsu {
  vector<long long> p, rank;
  vector<long long> set_count;

 public:
  dsu(long long n) {
    p.assign(n, 0);
    rank.assign(n, 0);
    set_count.assign(n, 1);
    for (long long i = 0; i < n; i++) p[i] = i;
  }
  long long findSet(long long first) {
    return (p[first] == first) ? first : (p[first] = findSet(p[first]));
  }
  bool isSame(long long i, long long j) { return (findSet(i) == findSet(j)); }
  void unionSet(long long i, long long j) {
    if (!isSame(i, j)) {
      long long first = findSet(i), second = findSet(j);
      if (rank[first] > rank[second]) {
        p[second] = first;
        set_count[first] += set_count[second];
      } else {
        p[first] = second;
        set_count[second] += set_count[first];
        if (rank[first] == rank[second]) rank[second]++;
      }
    }
  }
  long long count(long long first) { return set_count[findSet(first)]; }
};
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<pair<pair<long long, long long>, pair<long long, long long>>> edges;
  for (long long i = 0; i < m; i++) {
    long long a, b, l, r;
    cin >> a >> b >> l >> r;
    edges.push_back({{l, r}, {a, b}});
  }
  sort((edges).begin(), (edges).end());
  long long mx = 0;
  for (long long i = 0; i < m; i++) {
    long long lo = 1, hi = 1000000;
    long long ans = 0;
    while (lo <= hi) {
      dsu d(n + 1);
      long long mid = (lo + hi) / 2;
      for (long long j = i; j >= 0; j--) {
        if (edges[j].first.second >= mid) {
          d.unionSet(edges[j].second.first, edges[j].second.second);
        }
      }
      if (d.isSame(1, n)) {
        lo = mid + 1;
        ans = mid;
      } else
        hi = mid - 1;
    }
    mx = max(mx, ans - edges[i].first.first + 1);
  }
  if (mx == 0)
    cout << "Nice work, Dima!";
  else
    cout << mx;
}
