#include <bits/stdc++.h>
using namespace std;
class UFDS {
 public:
  vector<int> p, rank;
  int count = 0;
  UFDS(int n) {
    p.resize(n);
    rank.resize(n);
    for (int i = 0; i < n; i++) p[i] = i;
    count = n;
  }
  int getParent(int i) { return (p[i] == i) ? i : (p[i] = getParent(p[i])); }
  void join(int i, int j) {
    int a = getParent(i), b = getParent(j);
    if (a == b) return;
    count -= 1;
    if (rank[a] > rank[b]) {
      p[b] = a;
    } else {
      p[a] = b;
      if (rank[a] == rank[b]) rank[b] += 1;
    }
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  set<int> ls, rss;
  vector<int> rs;
  vector<vector<int> > edges(m, vector<int>(4));
  for (int i = 0; i < m; i++) {
    cin >> edges[i][2] >> edges[i][3] >> edges[i][0] >> edges[i][1];
    ls.insert(edges[i][0]);
    if (!rss.count(edges[i][1])) {
      rss.insert(edges[i][1]);
      rs.push_back(edges[i][1]);
    }
    edges[i][2] -= 1;
    edges[i][3] -= 1;
  }
  sort(rs.begin(), rs.end());
  sort(edges.begin(), edges.end());
  int out = 0, prev = 0;
  for (auto l : ls) {
    int lo = prev, hi = rss.size(), ans = -1;
    while (lo < hi) {
      int idx = (lo + hi) / 2;
      int mid = rs[idx];
      UFDS ufds(n);
      for (auto e : edges) {
        if (e[0] > l) break;
        if (e[1] >= mid) ufds.join(e[2], e[3]);
      }
      if (ufds.getParent(0) == ufds.getParent(n - 1)) {
        lo = idx + 1;
        ans = mid;
        prev = idx;
      } else {
        hi = idx;
      }
    }
    if (ans != -1) out = max(out, ans - l + 1);
  }
  if (out)
    cout << out;
  else
    cout << "Nice work, Dima!";
  cout << endl;
  return 0;
}
