#include <bits/stdc++.h>
using namespace std;
struct dwell {
  int node, lx, rx;
};
vector<dwell> edge[1010];
bool used[1010];
int a[3010];
int n, m, x, y, z1, z2;
void Search(int where, int l, int r) {
  if (used[where]) return;
  used[where] = true;
  for (int i = 0; i < edge[where].size(); i++) {
    int xx = edge[where][i].node, yy = edge[where][i].lx,
        zz = edge[where][i].rx;
    if ((yy <= l) && (r <= zz)) Search(xx, l, r);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &x, &y, &z1, &z2);
    dwell p0;
    p0.node = y, p0.lx = z1, p0.rx = z2, edge[x].push_back(p0);
    p0.node = x, edge[y].push_back(p0);
    a[i] = z1;
  }
  sort(a, a + m + 1);
  int ans = 0;
  for (int i = 1; i <= m; i++)
    if (a[i] != a[i - 1]) {
      int l = a[i], r = 1000000;
      while (l <= r) {
        if (r - a[i] + 1 < ans) break;
        int mid = (l + r) / 2;
        memset(used, false, sizeof(used));
        Search(1, a[i], mid);
        if (used[n]) {
          ans = max(ans, mid - a[i] + 1);
          l = mid + 1;
        } else
          r = mid - 1;
      }
    }
  if (!ans)
    printf("Nice work, Dima!\n");
  else
    printf("%d\n", ans);
  return 0;
}
