#include <bits/stdc++.h>
using namespace std;
int dist[1006];
class cmp {
 public:
  cmp() {}
  bool operator()(const pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
  }
};
struct ss {
  int to, l, r;
  ss() {}
  ss(int tt, int ll, int rr) { to = tt, l = ll, r = rr; }
};
vector<vector<ss> > Edges(1006);
int dijkstra(int N, int st) {
  priority_queue<pair<int, int>, vector<pair<int, int> >, cmp> PQ;
  while (!PQ.empty()) PQ.pop();
  memset(dist, -1, sizeof(dist));
  PQ.push(make_pair(1, 10000000));
  dist[1] = 10000000;
  pair<int, int> now;
  int i, nd, n, d, m;
  ss nxt;
  while (!PQ.empty()) {
    now = PQ.top();
    PQ.pop();
    n = now.first, d = now.second;
    if (dist[n] > d) continue;
    if (n == N) return d;
    for (i = 0; i < Edges[n].size(); ++i) {
      nxt = Edges[n][i];
      nd = nxt.to;
      if (nxt.l > st || nxt.r < st) continue;
      m = ((d) < (nxt.r) ? (d) : (nxt.r));
      if (dist[nd] < m) {
        dist[nd] = m;
        PQ.push(make_pair(nd, m));
      }
    }
  }
  return -1;
}
vector<int> st;
int main() {
  int N, M, x, y, l, r, i, j, ans, temp;
  while (scanf("%d %d", &N, &M) != EOF) {
    for (i = 1; i <= N; ++i) Edges[i].clear();
    st.clear();
    while (M--) {
      scanf("%d %d %d %d", &x, &y, &l, &r);
      Edges[x].push_back(ss(y, l, r));
      Edges[y].push_back(ss(x, l, r));
      st.push_back(l);
    }
    ans = -1;
    for (i = 0; i < st.size(); ++i) {
      temp = dijkstra(N, st[i]);
      if (temp == -1) continue;
      temp = temp - st[i] + 1;
      if (temp > ans) ans = temp;
    }
    if (ans == -1)
      puts("Nice work, Dima!");
    else
      printf("%d\n", ans);
  }
  return 0;
}
