#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1e3 + 5;
struct Node {
  int b, l, r;
} tmp;
vector<Node> edge[N];
set<pair<int, int> > len[N];
int n, m, ans = 0;
void Add_edge(int a, int b, int l, int r) {
  tmp.b = b;
  tmp.l = l, tmp.r = r;
  edge[a].push_back(tmp);
}
void solve() {
  queue<Node> q;
  tmp.b = 1, tmp.l = 0, tmp.r = INF;
  q.push(tmp);
  set<pair<int, int> >::iterator it;
  while (!q.empty()) {
    tmp = q.front();
    q.pop();
    int id = tmp.b;
    int l = tmp.l, r = tmp.r;
    if (id == n) {
      ans = max(ans, r - l + 1);
      continue;
    }
    if (r - l + 1 <= ans) continue;
    for (int i = 0; i < edge[id].size(); i++) {
      int ll = max(l, edge[id][i].l);
      int rr = min(r, edge[id][i].r);
      int t = edge[id][i].b;
      if (ll > rr) continue;
      bool flag = 0;
      for (it = len[t].begin(); it != len[t].end(); it++) {
        if ((*it).first <= ll && (*it).second >= rr) {
          flag = 1;
          break;
        }
      }
      if (flag) continue;
      len[t].insert(pair<int, int>(ll, rr));
      tmp.b = t;
      tmp.l = ll;
      tmp.r = rr;
      q.push(tmp);
    }
  }
}
int main() {
  int a, b, l, r;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b >> l >> r;
    Add_edge(a, b, l, r);
    Add_edge(b, a, l, r);
  }
  solve();
  if (ans == 0)
    cout << "Nice work, Dima!\n";
  else
    cout << ans << endl;
  return 0;
}
