#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const double PI = 4 * atan(1);
long long int pow(long long int b, long long int p) {
  return !p ? 1
            : pow(b * b % (long long int)(1e9 + 9), p / 2) * (p & 1 ? b : 1) %
                  (long long int)(1e9 + 9);
}
long long int inv(long long int b) {
  return pow(b, (long long int)(1e9 + 9) - 2);
}
const long long int MAXN = 1e3 + 1;
long long int parent[MAXN], rank1[MAXN];
long long int find_set(long long int v) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v]);
}
void make_sets(long long int n) {
  for (long long int v = 0; v < n + 1; v++) {
    parent[v] = v;
    rank1[v] = 0;
  }
}
void union_sets(long long int a, long long int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (rank1[a] < rank1[b]) swap(a, b);
    parent[b] = a;
    if (rank1[a] == rank1[b]) rank1[a]++;
  }
}
struct node {
  long long int a, b, l, r;
  bool friend operator<(node x, node y) { return x.r > y.r; }
};
void solve() {
  long long int n, m, ans = 0;
  cin >> n >> m;
  if (m == 0) {
    cout << "Nice work, Dima!" << endl;
    return;
  }
  struct node q[m + 1];
  for (long long int i = 1; i <= m; ++i) {
    cin >> q[i].a >> q[i].b >> q[i].l >> q[i].r;
  }
  sort(q + 1, q + m + 1);
  for (long long int i = 1; i <= m; i++) {
    long long int l = q[i].l, r = q[i].r;
    make_sets(n);
    for (long long int j = 1; j <= m; j++) {
      if (q[i].l > q[j].r or q[j].l > q[i].r or q[j].l > l) continue;
      union_sets(q[j].a, q[j].b);
      if (find_set(1) == find_set(n)) ans = max(ans, q[j].r - q[i].l + 1);
    }
  }
  if (ans)
    cout << ans << endl;
  else
    cout << "Nice work, Dima!" << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  for (long long int i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
