#include <bits/stdc++.h>
using namespace std;
template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return a.second < b.second;
}
struct c_h {
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    x ^= FIXED_RANDOM;
    return x ^ (x >> 16);
  }
};
template <typename T>
T calcpow(T x, T y) {
  T temp;
  if (y == 0) return 1;
  temp = calcpow(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else {
    if (y > 0)
      return x * temp * temp;
    else
      return (temp * temp) / x;
  }
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long egcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long x1;
  long long y1;
  long long g = egcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return g;
}
bool isprime(long long a) {
  bool flag = 1;
  for (long long i = 2; i * i <= a; i++) {
    if (a % i == 0) {
      flag = 0;
      break;
    }
  }
  return flag;
}
long long dx[4] = {1, -1, 0, 0};
long long dy[4] = {0, 0, 1, -1};
long long N = 1e3 + 3;
vector<long long> al(3 * N);
vector<vector<array<long long, 2> > > vec(N);
vector<long long> vis(N);
void dfs(long long e) {
  vis[e] = 1;
  for (auto x : vec[e]) {
    if (!vis[x[0]]) {
      if (al[x[1]]) dfs(x[0]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  vector<long long> lb, ub;
  vector<array<long long, 2> > ranges;
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    long long l, r;
    cin >> l >> r;
    a--;
    b--;
    ranges.push_back({l, r});
    vec[a].push_back({b, i});
    vec[b].push_back({a, i});
    lb.push_back(l);
    ub.push_back(r);
  }
  sort(ub.begin(), ub.end());
  long long ans = 0;
  long long n2 = ub.size();
  for (auto x : lb) {
    long long l = 0;
    long long r = n2 - 1;
    while (l <= r) {
      long long mid = (l + r) / 2;
      for (long long i = 0; i < n; i++) vis[i] = 0;
      for (long long i = 0; i < m; i++) {
        al[i] = 0;
        if (ranges[i][0] <= x && ranges[i][1] >= ub[mid]) al[i] = 1;
      }
      dfs(0);
      if (vis[n - 1]) {
        ans = max(ans, ub[mid] - x + 1);
        l = mid + 1;
      } else
        r = mid - 1;
    }
  }
  if (ans == 0)
    cout << "Nice work, Dima!\n";
  else
    cout << ans << endl;
  return 0;
}
