#include <bits/stdc++.h>
using namespace std;
int getSet(vector<int> &parents, int x) {
  if (parents[x] == x) return x;
  parents[x] = getSet(parents, parents[x]);
  return parents[x];
}
void join(vector<int> &parents, int a, int b) {
  int aa = getSet(parents, a);
  int bb = getSet(parents, b);
  if (rand() & 1) {
    parents[aa] = bb;
  } else {
    parents[bb] = aa;
  }
}
bool checkPath(int n, vector<pair<int, int> > &edges,
               vector<pair<int, int> > &range, int left, int right) {
  if (right < left) return false;
  vector<int> parents(n);
  for (int i = 0; i < n; i++) {
    parents[i] = i;
  }
  for (int i = 0; i < edges.size(); i++) {
    if (range[i].first <= left && right <= range[i].second) {
      join(parents, edges[i].first, edges[i].second);
    }
  }
  return (getSet(parents, 0) == getSet(parents, n - 1));
}
int main() {
  vector<pair<int, int> > edges;
  vector<pair<int, int> > range;
  int n, m;
  cin >> n >> m;
  edges.resize(m);
  range.resize(m);
  vector<int> right(m), left(m);
  for (int i = 0; i < m; i++) {
    cin >> edges[i].first >> edges[i].second;
    cin >> range[i].first >> range[i].second;
    edges[i].first--;
    edges[i].second--;
    right[i] = range[i].second;
    left[i] = range[i].first;
  }
  sort(right.begin(), right.end());
  sort(left.begin(), left.end());
  int sr = 1;
  int sl = 1;
  for (int i = 1; i < right.size(); i++) {
    if (right[i] != right[sr - 1]) {
      right[sr] = right[i];
      sr++;
    }
  }
  for (int i = 1; i < left.size(); i++) {
    if (left[i] != left[sl - 1]) {
      left[sl] = left[i];
      sl++;
    }
  }
  right.resize(sr);
  left.resize(sl);
  int best = -1;
  for (int i = 0; i < left.size(); i++) {
    int curl = left[i];
    int ll = 0, rr = right.size();
    while (rr > ll + 1) {
      int mid = (rr + ll) / 2;
      if (checkPath(n, edges, range, curl, right[mid])) {
        ll = mid;
      } else {
        rr = mid;
      }
    }
    if (checkPath(n, edges, range, curl, right[ll])) {
      if (right[ll] - curl + 1 > best) {
        best = right[ll] - curl + 1;
      }
    }
  }
  if (best != -1) {
    cout << best << endl;
  } else {
    cout << "Nice work, Dima!\n";
  }
  return 0;
}
