#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, pair<int, int> > > > graph;
int visited[1002];
void dfs(int x, int left, int right) {
  visited[x] = 1;
  for (vector<pair<int, pair<int, int> > >::iterator it = graph[x].begin();
       it != graph[x].end(); it++) {
    if (!visited[(*it).first] && ((*it).second.first <= left) &&
        ((*it).second.second >= right))
      dfs((*it).first, left, right);
  }
}
int main() {
  int n, m, a, b, c, d;
  cin >> n >> m;
  graph.resize(n + 2);
  vector<int> left, right;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c >> d;
    graph[a].push_back(pair<int, pair<int, int> >(b, pair<int, int>(c, d)));
    graph[b].push_back(pair<int, pair<int, int> >(a, pair<int, int>(c, d)));
    left.push_back(c);
    right.push_back(d);
  }
  sort(left.begin(), left.end());
  sort(right.begin(), right.end());
  int ans = -1;
  for (int i = 0; i < m; i++) {
    for (int j = m - 1; j >= 0; j--) {
      if (left[i] <= right[j] && ans < right[j] - left[i] + 1) {
        memset(visited, 0, sizeof(visited));
        dfs(1, left[i], right[j]);
        if (visited[n]) ans = right[j] - left[i] + 1;
      }
    }
  }
  if (ans == -1)
    cout << "Nice work, Dima!";
  else
    cout << ans;
  return 0;
}
