#include <bits/stdc++.h>
using namespace std;
const int M = 3005;
bool visit[M];
vector<pair<int, pair<int, int> > > g[M];
int low, high;
void dfs(int u) {
  visit[u] = true;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first;
    int l = g[u][i].second.first;
    int r = g[u][i].second.second;
    if (visit[v]) continue;
    if (l > low || r < high) continue;
    dfs(v);
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  set<int> left;
  for (int i = 0; i < m; i++) {
    int a, b, l, r;
    scanf("%d %d %d %d", &a, &b, &l, &r);
    g[a].push_back(make_pair(b, make_pair(l, r)));
    g[b].push_back(make_pair(a, make_pair(l, r)));
    left.insert(l);
  }
  int ans = -1;
  bool done = false;
  for (typeof(left.begin()) i = left.begin(); i != left.end(); i++) {
    low = *i;
    int l = low, r = 1e6, mid, it = 22;
    while (it--) {
      mid = (l + r) / 2;
      high = mid;
      memset(visit, 0, sizeof visit);
      dfs(1);
      if (visit[n])
        l = mid, done = true;
      else
        r = mid;
    }
    memset(visit, 0, sizeof visit);
    high++;
    dfs(1);
    if (!visit[n]) high--;
    ans = max(ans, high - low + 1);
  }
  if (!done) {
    cout << "Nice work, Dima!";
    return 0;
  }
  cout << ans;
  return 0;
}
