#include <bits/stdc++.h>
using namespace std;
const int NMAX = 3e3 + 7;
struct edge {
  int u, v, l, r;
  edge() {}
  edge(int _u, int _v, int _l, int _r) {
    u = _u;
    v = _v;
    l = _l;
    r = _r;
  }
} e[NMAX];
int p[NMAX];
int _find(int x) { return (x == p[x]) ? x : p[x] = _find(p[x]); }
void join(int x, int y) {
  x = _find(x);
  y = _find(y);
  if (x == y) return;
  p[x] = y;
}
int n, m;
int check(int x) {
  for (int i = 0; i < m; i++) {
    int flag = 0;
    for (int j = 0; j < n; j++) p[j] = j;
    for (int j = 0; j < m; j++) {
      if (i == j && (e[j].r - e[i].l + 1 < x)) {
        flag = 1;
        break;
      }
      if (e[i].l >= e[j].l && (e[j].r - e[i].l + 1 >= x)) join(e[j].u, e[j].v);
    }
    if (flag) continue;
    if (_find(0) == _find(n - 1)) return 1;
  }
  return 0;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y, z, t;
    cin >> x >> y >> z >> t;
    x--;
    y--;
    e[i] = edge(x, y, z, t);
  }
  int L = 0;
  int R = 1e8 + 846;
  while (R - L > 1) {
    int mid = (L + R) / 2;
    if (check(mid)) {
      L = mid;
    } else {
      R = mid;
    }
  }
  if (L == 0)
    cout << "Nice work, Dima!\n";
  else
    cout << L;
  return 0;
}
