#include <bits/stdc++.h>
using namespace std;
const int maxl = 1000 + 1;
const int maxm = 3 * 1000 + 1;
int n, m;
vector<pair<int, int> > v[maxl];
bool marked[maxl];
pair<int, int> e[maxm];
int a[maxm];
int b[maxm];
int front, back;
bool valid(int node, int edge) {
  return (!marked[node] && (e[edge].first <= front) &&
          (e[edge].second >= back));
}
bool dfs(int index) {
  marked[index] = true;
  if (index == (n - 1)) return true;
  for (int i = 0; i < v[index].size(); i++) {
    int node = v[index][i].first, edge = v[index][i].second;
    if (valid(node, edge))
      if (dfs(node)) return true;
  }
  return false;
}
bool init_dfs() {
  for (int i = 0; i < n; i++) marked[i] = false;
  return dfs(0);
}
int check(int i) {
  front = a[i];
  int first = -1, last = m;
  for (int j = 0; j < m; j++)
    if (b[j] >= a[i]) {
      first = j;
      break;
    }
  if (first == -1) return 0;
  while ((last - first) > 1) {
    int mid = (first + last) / 2;
    back = b[mid];
    if (init_dfs())
      first = mid;
    else
      last = mid;
  }
  back = b[first];
  if (init_dfs())
    return (back - front + 1);
  else
    return 0;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int p, q, l, r;
    cin >> p >> q >> l >> r;
    p--;
    q--;
    v[p].push_back(make_pair(q, i));
    v[q].push_back(make_pair(p, i));
    e[i].first = l;
    e[i].second = r;
    a[i] = l;
    b[i] = r;
  }
  sort(a, a + m);
  sort(b, b + m);
  int ans = 0;
  for (int i = 0; i < m; i++) {
    ans = max(check(i), ans);
  }
  if (ans == 0)
    cout << "Nice work, Dima!";
  else
    cout << ans;
  cout << endl;
}
