#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const long long INF64 = 9e18;
const long double EPS = 1e-9;
const long double PI = 3.14159265358979310000;
const long long MD = 535355424;
const long long T = 34539;
const int N = 200001;
const int M = 101;
struct st {
  int l, r, first;
  st(int first, int l, int r) {
    this->first = first;
    this->l = l;
    this->r = r;
  }
};
int n, m, maxi = 0;
vector<st> g[N];
bool mark[N];
void dfs(int v, int first, int second) {
  mark[v] = 1;
  for (int i = 0; i < int(int((g[v]).size())); i++)
    if (!mark[g[v][i].first] && g[v][i].l <= first && g[v][i].r >= second)
      dfs(g[v][i].first, first, second);
}
bool get(int first, int second) {
  for (int i = 1; i <= n; i++) mark[i] = 0;
  dfs(1, first, second);
  return mark[n];
}
int check(int l, int r) {
  int m, first = l;
  while (r - l > 1) {
    m = (l + r) / 2;
    if (get(first, m))
      l = m;
    else
      r = m;
  }
  if (get(first, r)) return r - first + 1;
  if (get(first, l)) return l - first + 1;
  return 0;
}
int main() {
  cin >> n >> m;
  int first, second, l, r;
  for (int i = 0; i < int(m); i++) {
    cin >> first >> second >> l >> r;
    g[first].push_back(st(second, l, r));
    g[second].push_back(st(first, l, r));
  }
  for (int v = 1; v <= n; v++)
    for (int i = 0; i < int(int((g[v]).size())); i++)
      maxi = max(maxi, check(g[v][i].l, g[v][i].r));
  if (maxi == 0)
    cout << "Nice work, Dima!";
  else
    cout << maxi;
  return 0;
}
