#include <bits/stdc++.h>
using namespace std;
int n;
const int size = 1000;
int x[size * 3 + 10], y[size * 3 + 10], L[size * 3 + 10], R[size * 3 + 10];
vector<pair<int, pair<int, int>>> ve[size + 10];
bool vis[size + 10];
bool bSearch(int pos, int x, int y) {
  vis[pos] = true;
  if (pos == n) {
    return true;
  }
  for (auto it : ve[pos]) {
    if (!vis[it.first]) {
      if (it.second.first <= x && it.second.second >= y) {
        if (bSearch(it.first, x, y)) {
          return true;
        }
      }
    }
  }
  return false;
}
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int m;
  while (cin >> n >> m) {
    for (int i = 1; i <= m; ++i) {
      cin >> x[i] >> y[i] >> L[i] >> R[i];
      ve[x[i]].emplace_back(y[i], make_pair(L[i], R[i]));
      ve[y[i]].emplace_back(x[i], make_pair(L[i], R[i]));
    }
    int res = -1;
    for (int i = 1; i <= m; ++i) {
      int le = L[i];
      int ri = R[i];
      int temp = -1;
      while (le <= ri) {
        int mi = le + ri >> 1;
        memset(vis, false, sizeof(vis));
        if (bSearch(1, L[i], mi)) {
          temp = mi - L[i] + 1;
          le = mi + 1;
        } else {
          ri = mi - 1;
        }
      }
      res = max(res, temp);
    }
    if (res == -1) {
      cout << "Nice work, Dima!" << '\n';
    } else {
      cout << res << '\n';
    }
    cout.flush();
  }
  return 0;
}
