#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
const int oo = 0x3f3f3f3f;
typedef vector<pair<pair<int, int>, pair<int, int> > > Graph[MAXN];
const inline int min(const int &a, const int &b) {
  if (a > b) return b;
  return a;
}
const inline int max(const int &a, const int &b) {
  if (a < b) return b;
  return a;
}
const inline void Get_min(int &a, const int b) {
  if (a > b) a = b;
}
const inline void Get_max(int &a, const int b) {
  if (a < b) a = b;
}
struct edge {
  int x, y, l, r;
  edge() {
    x = 0;
    y = 0;
    l = 0;
    r = 0;
  }
  edge(int _x, int _y, int _l, int _r) {
    x = _x;
    y = _y;
    l = _l;
    r = _r;
  }
};
struct classComp {
  inline bool operator()(const edge &a, const edge &b) const {
    return a.r > b.r;
  }
};
vector<edge> v;
int N, M, Father[MAXN], Ans;
int Find(int X) {
  if (Father[X] != X) Father[X] = Find(Father[X]);
  return Father[X];
}
inline void Unite(int X, int Y) { Father[X] = Y; }
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    int x, y, l, r;
    cin >> x >> y >> l >> r;
    v.push_back(edge(x, y, l, r));
  }
  sort(v.begin(), v.end(), classComp());
  for (int i = 0; i < M; ++i) {
    for (int j = 1; j <= N; ++j) Father[j] = j;
    for (int j = 0; j < M; ++j)
      if (v[j].l <= v[i].l) {
        int Tx = Find(v[j].x);
        int Ty = Find(v[j].y);
        if (Tx != Ty) {
          Unite(Tx, Ty);
          if (Find(1) == Find(N)) {
            Ans = max(Ans, 1 + v[j].r - v[i].l);
            break;
          }
        }
      }
  }
  if (!Ans)
    cout << "Nice work, Dima!\n";
  else
    cout << Ans << '\n';
  return 0;
}
