#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000404;
const long long MOD = 1000000007ll;
const long double PI = acos(-1.0);
const long long INF = 2000000000000000000ll;
const long double EPS = 1e-9;
template <typename T>
inline T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
inline T lcm(T a, T b) {
  return a * (b / gcd(a, b));
}
template <typename T>
inline T sqr(T a) {
  return a * a;
}
inline bool pal(string &x) {
  int n = (int)x.length();
  for (int i = 0; i < n / 2; i++) {
    if (x[i] != x[n - i - 1]) return 0;
  }
  return 1;
}
int month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int dx8[] = {1, 1, 1, 0, 0, -1, -1, -1};
int dy8[] = {-1, 0, 1, 1, -1, -1, 0, 1};
int SQ = 400;
struct node {
  int l, r, u, v;
  bool operator<(const node &other) const { return (r > other.r); }
};
node edge[4111];
int p[4111];
void initial(int n) {
  for (int i = 0; i < n + 1; i++) p[i] = i;
}
int findset(int x) { return x == p[x] ? x : p[x] = findset(p[x]); }
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    node &x = edge[i];
    cin >> x.u >> x.v >> x.l >> x.r;
  }
  sort(edge, edge + m);
  int answer = 0;
  for (int i = 0; i < m; i++) {
    initial(n);
    for (int j = 0; j < m; j++) {
      node &x = edge[j];
      if (x.l <= edge[i].l) {
        if (findset(x.u) != findset(x.v)) {
          p[findset(x.u)] = findset(x.v);
          if (findset(1) == findset(n)) {
            answer = max(answer, x.r - edge[i].l + 1);
            break;
          }
        }
      }
    }
  }
  if (answer)
    cout << answer << endl;
  else
    cout << "Nice work, Dima!";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  };
  getchar();
  getchar();
  return 0;
}
