#include <bits/stdc++.h>
using namespace std;
struct _ {
  _() { ios_base::sync_with_stdio(0); }
} _;
template <class A, class B>
ostream &operator<<(ostream &o, pair<A, B> t) {
  o << "(" << t.first << ", " << t.second << ")";
  return o;
}
template <class T>
string tostring(T first, int len = 0, char c = '0') {
  stringstream ss;
  ss << first;
  string r = ss.str();
  if (r.length() < len) r = string(len - r.length(), c) + r;
  return r;
}
template <class T>
void PV(T a, T b, int n = 0, int w = 0, string s = " ") {
  int c = 0;
  while (a != b) {
    cout << tostring(*a++, w, ' ');
    if (a != b && (n == 0 || ++c % n))
      cout << s;
    else
      cout << endl;
  }
}
template <class T>
inline bool chmin(T &a, T b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
inline bool chmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
const long long linf = 0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int mod = int(1e9) + 7;
const int N = 3333;
struct BCJ {
  int par[N], rk[N];
  BCJ(int n = N) { init(n); }
  void init(int n) {
    for (int i = 0; i <= n; i++) par[i] = i, rk[i] = 1;
  }
  int Find(int first) {
    if (par[first] != first) par[first] = Find(par[first]);
    return par[first];
  }
  bool Union(int first, int second) {
    first = Find(first), second = Find(second);
    if (first == second) return 0;
    if (rk[first] > rk[second]) {
      par[second] = first, rk[first] += rk[second];
    } else {
      par[first] = second, rk[second] += rk[first];
    }
    return 1;
  }
} dsu;
int n, m;
int a[N];
int b[N];
int l[N];
int r[N];
int check(int L, int R) {
  dsu.init(n);
  for (int i = 0; i < m; i++)
    if (l[i] <= L && R <= r[i]) dsu.Union(a[i], b[i]);
  return dsu.Find(0) == dsu.Find(n - 1);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> l[i] >> r[i];
    a[i]--;
    b[i]--;
  }
  int res = 0;
  for (int i = 0; i < m; i++) {
    int L = l[i];
    int R = 1000000;
    while (L < R) {
      int M = (L + R + 1) / 2;
      if (check(l[i], M)) {
        L = M;
      } else {
        R = M - 1;
      }
    }
    if (check(l[i], L)) chmax(res, R - l[i] + 1);
  }
  if (res > 0)
    cout << res << endl;
  else
    cout << "Nice work, Dima!" << endl;
  return 0;
}
