#include <bits/stdc++.h>
using namespace std;
typedef struct node {
  int idx, up, cost;
  node(){};
  node(int a, int b, int c) { idx = a, up = b, cost = c; }
  bool operator<(const node& x) const {
    if (cost != x.cost) return cost < x.cost;
    if (idx != x.idx) return idx < x.idx;
    if (up != x.up) return up < x.up;
  }
} node;
int maxiRightIdx;
int vis[1005][3 * 1005];
pair<int, int> edges[3 * 1005];
vector<pair<int, int> > adj[1005];
int n, m, a, b, c, d;
int dijkstra() {
  int ret = -1e9;
  memset(vis, 63, sizeof vis);
  set<node> pq;
  pq.insert(node(1, maxiRightIdx, 0));
  while (!pq.empty()) {
    node cur = *pq.begin();
    pq.erase(pq.begin());
    if (cur.idx == n) {
      ret = max(ret, edges[cur.up].second - cur.cost + 1);
      continue;
    }
    for (int i = 0; i < adj[cur.idx].size(); i++) {
      int to = adj[cur.idx][i].first;
      int e = adj[cur.idx][i].second;
      if (edges[cur.up].second < edges[e].first || cur.cost > edges[e].second)
        continue;
      node next(to, edges[cur.up].second < edges[e].second ? cur.up : e,
                max(cur.cost, edges[e].first));
      if (vis[next.idx][next.up] > next.cost) {
        set<node>::iterator it =
            pq.find(node(next.idx, next.up, vis[next.idx][next.up]));
        if (it != pq.end()) pq.erase(it);
        pq.insert(next);
        vis[next.idx][next.up] = next.cost;
      }
    }
  }
  return ret;
}
int main() {
  int besti = 0;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d %d", &a, &b, &c, &d);
    edges[i].first = c;
    edges[i].second = d;
    adj[a].push_back(pair<int, int>(b, i));
    adj[b].push_back(pair<int, int>(a, i));
    if (d >= besti) {
      besti = d;
      maxiRightIdx = i;
    }
  }
  int ans = dijkstra();
  if (ans > 0) {
    cout << ans << endl;
  } else {
    cout << "Nice work, Dima!" << endl;
  }
  return 0;
}
