#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, pair<int, int> > > adjList[1003];
int gl, gr;
bool reachable[1003];
void dfs(int v, int p) {
  if (reachable[v]) return;
  reachable[v] = true;
  for (int i = 0; i < adjList[v].size(); i++) {
    if (adjList[v][i].first != p && gl >= adjList[v][i].second.first &&
        gr <= adjList[v][i].second.second)
      dfs(adjList[v][i].first, v);
  }
}
int main() {
  cin >> n >> m;
  vector<int> l1;
  vector<int> r1;
  for (int i = 0; i < m; i++) {
    int a, b, l, r;
    cin >> a >> b >> l >> r;
    a--;
    b--;
    adjList[a].push_back(make_pair(b, make_pair(l, r)));
    adjList[b].push_back(make_pair(a, make_pair(l, r)));
    l1.push_back(l);
    r1.push_back(r);
  }
  sort((l1).begin(), (l1).end());
  sort((r1).begin(), (r1).end());
  int maxval = 0;
  for (int i = 0; i < l1.size(); i++) {
    for (int j = r1.size() - 1; j >= 0; j--) {
      if (l1[i] <= r1[j] && maxval < r1[j] - l1[i] + 1) {
        gl = l1[i];
        gr = r1[j];
        memset(reachable, false, sizeof reachable);
        dfs(0, -1);
        if (reachable[n - 1]) maxval = max(maxval, gr - gl + 1);
      }
    }
  }
  if (maxval == 0)
    cout << "Nice work, Dima!" << endl;
  else
    cout << maxval << endl;
}
