#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, pair<int, int> > > edges[1001 + 1];
bool done[1001 + 1];
int BFS[2][1001 + 1];
bool possible(int left_pt, int right_pt) {
  for (int j = 0; j < n; j++) {
    done[j] = false;
  }
  BFS[0][0] = 0;
  int sz = 1;
  done[0] = true;
  for (int t = 1; sz > 0; t++) {
    int nsz = 0;
    for (int j = 0; j < sz; j++) {
      int u = BFS[(t - 1) & 1][j];
      for (int k = 0; k < edges[u].size(); k++) {
        int v = edges[u][k].first;
        pair<int, int> lu = edges[u][k].second;
        if (!done[v] && lu.first <= left_pt && lu.second >= right_pt) {
          if (v == n - 1) return true;
          done[v] = true;
          BFS[t & 1][nsz++] = v;
        }
      }
    }
    sz = nsz;
  }
  return false;
}
int main() {
  cin >> n >> m;
  vector<int> left_points;
  vector<int> right_points;
  for (int j = 0; j < m; j++) {
    int a, b, l, r;
    cin >> a >> b >> l >> r;
    a--;
    b--;
    edges[a].push_back(make_pair(b, make_pair(l, r)));
    edges[b].push_back(make_pair(a, make_pair(l, r)));
    left_points.push_back(l);
    right_points.push_back(r);
  }
  sort(left_points.begin(), left_points.end());
  sort(right_points.begin(), right_points.end());
  int answer = -1;
  for (int j = 0; j < left_points.size(); j++) {
    int low = 0;
    int high = right_points.size() - 1;
    while (low < high) {
      int mid = (low + high + 1) / 2;
      if (possible(left_points[j], right_points[mid])) {
        low = mid;
      } else {
        high = mid - 1;
      }
    }
    if (left_points[j] <= right_points[low] &&
        possible(left_points[j], right_points[low])) {
      answer = max(answer, right_points[low] - left_points[j] + 1);
    }
  }
  if (answer == -1) {
    cout << "Nice work, Dima!" << endl;
  } else {
    cout << answer << endl;
  }
}
