#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000 + 20;
vector<int> adj[MAX_N], L, R;
vector<pair<int, int> > rng[MAX_N];
int mark[MAX_N];
int n, m, ans;
void dfs(int v, int l, int r) {
  mark[v] = 1;
  for (int i(0); i < int(adj[v].size()); i++) {
    int u = adj[v][i];
    if (rng[v][i].first <= l && r <= rng[v][i].second && !mark[u]) dfs(u, l, r);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i(0); i < int(m); i++) {
    int v, u, l, r;
    cin >> v >> u >> l >> r;
    --v, u--;
    adj[v].push_back(u);
    adj[u].push_back(v);
    rng[v].push_back(make_pair(l, r));
    rng[u].push_back(make_pair(l, r));
    L.push_back(l);
    R.push_back(r);
  }
  sort(L.begin(), L.end());
  sort(R.begin(), R.end());
  for (int i(0); i < int(L.size()); i++) {
    int l = L[i], r = L[i] - 1;
    int st = lower_bound(R.begin(), R.end(), L[i]) - R.begin(),
        en = R.size() - 1;
    while (en - st > 1) {
      int mid = (st + en) >> 1;
      fill(mark, mark + n, 0);
      dfs(0, l, R[mid]);
      if (mark[n - 1])
        st = mid;
      else
        en = mid;
    }
    for (int j(st); j < int(en + 1); j++) {
      fill(mark, mark + n, 0);
      dfs(0, l, R[j]);
      if (mark[n - 1]) r = R[j];
    }
    ans = max(ans, r - l + 1);
  }
  if (ans == 0)
    cout << "Nice work, Dima!";
  else
    cout << ans;
  cout << endl;
  return 0;
}
