#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int maxn = 3e3 + 5;
long long int maxnn = 1e18;
double pie = 3.1415926535;
long long int ans = 0, parent[maxn], m, n;
pair<pair<long long int, long long int>, pair<long long int, long long int> >
    edge[maxn];
long long int find(long long int node) {
  if (parent[node] == node) return node;
  return parent[node] = find(parent[node]);
}
void join(long long int u, long long int v) { parent[find(v)] = find(u); }
void solve(long long int r) {
  long long int i;
  for (i = 1; i <= n; i++) parent[i] = i;
  for (i = 1; i <= m; i++) {
    if (edge[i].first.second >= r) {
      join(edge[i].second.first, edge[i].second.second);
      if (find(1) == find(n)) {
        ans = max(ans, r - edge[i].first.first + 1);
        break;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int i, u, v, l, r;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> u >> v >> l >> r;
    edge[i] = {{l, r}, {u, v}};
  }
  sort(edge + 1, edge + m + 1);
  for (i = 1; i <= m; i++) {
    solve(edge[i].first.second);
  }
  if (ans)
    cout << ans;
  else
    cout << "Nice work, Dima!";
}
