#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int u, v, l, r;
  int getV(int u) { return this->u == u ? v : this->u; }
  int getW(int lo, int hi) {
    if (lo > r || l > lo) return -1;
    return min(r, hi) - lo + 1;
  }
};
int mX;
vector<vector<int> > adj;
Edge E[3010];
int D[1010];
int ITER[3010];
int ditra(int s, int t) {
  priority_queue<pair<int, int> > PQ;
  memset(D, -1, sizeof(D));
  PQ.push(pair<int, int>(2000000, s));
  D[s] = 2000000;
  while (PQ.size()) {
    pair<int, int> c = PQ.top();
    PQ.pop();
    int u = c.second, d = c.first;
    if (D[u] > d) continue;
    if (u == t) return d;
    for (int i = 0; i < adj[u].size(); ++i) {
      int e = adj[u][i];
      int v = E[e].getV(u);
      int nd = E[e].getW(mX, mX + d - 1);
      if (nd == -1) continue;
      if (D[v] == -1 || D[v] < nd) {
        D[v] = nd;
        PQ.push(pair<int, int>(nd, v));
      }
    }
  }
  return 0;
}
int main() {
  int N, M;
  cin >> N >> M;
  adj = vector<vector<int> >(N);
  for (int i = 0; i < M; ++i) {
    cin >> E[i].u >> E[i].v >> E[i].l >> E[i].r;
    E[i].u--;
    E[i].v--;
    adj[E[i].u].push_back(i);
    adj[E[i].v].push_back(i);
    ITER[i] = E[i].l;
  }
  int ma = 0;
  for (int i = 0; i < M; ++i) {
    mX = ITER[i];
    int d = ditra(0, N - 1);
    ma = max(ma, d);
  }
  if (ma == 0)
    cout << "Nice work, Dima!" << endl;
  else
    cout << ma << endl;
}
