#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000 + 10;
const int MAX_M = 3000 + 10;
pair<pair<int, int>, pair<int, int> > e[MAX_M];
int par[MAX_N];
int get_par(int u) { return ~par[u] ? (par[u] = get_par(par[u])) : u; }
void merge(int u, int v) {
  u = get_par(u), v = get_par(v);
  par[u] = (u == v ? -1 : v);
}
int main() {
  ios_base ::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> x;
  for (int i = 0; i < m; i++) {
    int u, v, l, r;
    cin >> u >> v >> l >> r;
    x.push_back(r);
    u--, v--;
    e[i].first.first = l, e[i].first.second = r;
    e[i].second.first = u, e[i].second.second = v;
  }
  int ans = 0;
  sort(e, e + m);
  sort(x.begin(), x.end());
  x.erase(unique(x.begin(), x.end()), x.end());
  for (auto r : x) {
    memset(par, -1, sizeof par);
    for (int i = 0; i < m; i++) {
      if (e[i].first.second < r) continue;
      merge(e[i].second.first, e[i].second.second);
      if (get_par(0) == get_par(n - 1))
        ans = max(ans, r - e[i].first.first + 1);
    }
  }
  if (ans)
    cout << ans << endl;
  else
    cout << "Nice work, Dima!\n";
  return 0;
}
