#include <bits/stdc++.h>
using namespace std;
const int N = 1009;
int n, m;
struct edge {
  int to, l, r;
  edge(int a, int b, int c) { tie(to, l, r) = make_tuple(a, b, c); }
};
vector<edge> graph[N];
vector<bool> used;
void dfs(int v, int lf, int rg) {
  used[v] = true;
  for (edge go : graph[v]) {
    if (!used[go.to] && go.l <= lf && go.r >= rg) dfs(go.to, lf, rg);
  }
}
bool check(int lf, int rg) {
  used.assign(n + 1, false);
  dfs(1, lf, rg);
  return used[n];
}
int main() {
  cin >> n >> m;
  int a, b, l, r;
  vector<int> left_borders;
  for (int i = 1; i <= m; ++i) {
    cin >> a >> b >> l >> r;
    left_borders.push_back(l);
    graph[a].push_back(edge(b, l, r));
    graph[b].push_back(edge(a, l, r));
  }
  int ans = 0;
  for (int lf : left_borders) {
    int l = lf - 1, r = N * N;
    while (r - l > 1) {
      int m = (r + l) / 2;
      if (check(lf, m))
        l = m;
      else
        r = m;
    }
    int rg = l;
    ans = max(ans, rg - lf + 1);
  }
  if (ans == 0)
    cout << "Nice work, Dima!";
  else
    cout << ans;
  return 0;
}
