#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)(1e3) + 100;
const int INF = (1 << 30);
const double PI = acos(-1.0);
const double EPS = (1e-6);
vector<pair<int, pair<int, int> > > g[MAXN];
bool used[MAXN];
int n, m, ans = -INF;
set<int> second;
void dfs(int v, int L, int R) {
  used[v] = 1;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i].first;
    int l = g[v][i].second.first, r = g[v][i].second.second;
    if (l <= L && R <= r && !used[to]) dfs(to, L, R);
  }
}
bool check(int l, int r) {
  memset(used, 0, sizeof(used));
  dfs(1, l, r);
  return used[n];
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b, l, r;
    cin >> 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)));
    second.insert(l);
  }
  for (set<int>::iterator it = second.begin(); it != second.end(); it++) {
    int L = *it, R = -1;
    int l = L, r = (1 << 30);
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (check(L, mid)) {
        l = mid + 1;
        R = mid;
      } else {
        r = mid - 1;
      }
    }
    if (R != -1) ans = max(ans, R - L + 1);
  }
  if (ans == -INF)
    cout << "Nice work, Dima!";
  else
    cout << ans;
  return 0;
}
