#include <bits/stdc++.h>
using namespace std;
int n;
int m;
struct st {
  int go;
  int l;
  int r;
  st(int go_, int l_, int r_) {
    go = go_;
    l = l_;
    r = r_;
  }
};
vector<st> v[1002];
int dist[1002];
vector<int> vv;
int dik(int bb) {
  memset(dist, -1, sizeof(dist));
  queue<int> q;
  q.push(0);
  dist[0] = INT_MAX;
  while (!q.empty()) {
    int b = q.front();
    for (int i = 0; i < v[b].size(); i++) {
      if (v[b][i].l <= bb && bb <= v[b][i].r) {
        if (dist[v[b][i].go] < min(dist[b], v[b][i].r)) {
          dist[v[b][i].go] = min(dist[b], v[b][i].r);
          q.push(v[b][i].go);
        }
      }
    }
    q.pop();
  }
  return dist[n - 1];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    int l, r;
    scanf("%d%d", &l, &r);
    v[a].push_back(st(b, l, r));
    v[b].push_back(st(a, l, r));
    vv.push_back(l);
    vv.push_back(r);
  }
  sort(vv.begin(), vv.end());
  vv.erase(unique(vv.begin(), vv.end()), vv.end());
  int ans = 0;
  for (int i = 0; i < vv.size(); i++) {
    ans = max(ans, dik(vv[i]) - vv[i] + 1);
  }
  if (ans == 0) {
    puts("Nice work, Dima!");
  } else {
    printf("%d\n", ans);
  }
  return 0;
}
