#include <bits/stdc++.h>
using namespace std;
struct node {
  int v1, v2;
  int x, y;
} s[3 * 1005];
int father[3000];
int n, m;
int vist[1005], flg1, flg2, ans, xx, yy;
int cmp(const node a, const node b) {
  if (a.y > b.y)
    return 1;
  else
    return 0;
}
int find(int x) {
  int root, i = x;
  while (x != father[x]) x = father[x];
  root = x;
  x = i;
  while (x != father[x]) {
    i = father[x];
    father[x] = root;
    x = i;
  }
  return root;
}
int main() {
  while (scanf("%d%d", &n, &m) > 0) {
    for (int i = 0; i < m; i++) {
      scanf("%d%d%d%d", &s[i].v1, &s[i].v2, &s[i].x, &s[i].y);
    }
    sort(s, s + m, cmp);
    ans = 0;
    for (int i = 0; i < m; i++) {
      for (int j = 0; j <= n; j++) father[j] = j;
      for (int j = 0; j < m; j++) {
        if (s[i].x > s[j].y) continue;
        if (s[i].y < s[j].x) continue;
        if (s[j].x > s[i].x) continue;
        int s1 = find(s[j].v1);
        int s2 = find(s[j].v2);
        if (s1 != s2) {
          father[s1] = s2;
        }
        if (find(1) == find(n)) {
          if (ans < s[j].y - s[i].x + 1) ans = s[j].y - s[i].x + 1;
          break;
        }
      }
    }
    if (ans == 0)
      printf("Nice work, Dima!\n");
    else
      printf("%d\n", ans);
  }
  return 0;
}
