#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to, min, max, next;
} edge[10000];
int n, m, num_edge;
bool vis[10000];
int first1[10000], ans;
int l1[10000], r1[10000];
bool dfs(int u, int l, int r) {
  if (l > r) return false;
  if (u == n) return true;
  vis[u] = true;
  for (int k = first1[u]; k != 0; k = edge[k].next) {
    if (edge[k].min <= l && edge[k].max >= r && !vis[edge[k].to]) {
      if (dfs(edge[k].to, l, r)) return true;
    }
  }
  return false;
}
int main() {
  int i, a, b, l, r, mid;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &a, &b, &l, &r);
    edge[++num_edge].to = b;
    edge[num_edge].next = first1[a];
    first1[a] = num_edge;
    edge[num_edge].min = l;
    edge[num_edge].max = r;
    edge[++num_edge].to = a;
    edge[num_edge].next = first1[b];
    first1[b] = num_edge;
    edge[num_edge].min = l;
    edge[num_edge].max = r;
    l1[i] = l;
    r1[i] = r;
  }
  sort(l1 + 1, l1 + m + 1);
  sort(r1 + 1, r1 + m + 1);
  for (i = 1; i <= m; i++) {
    l = 1;
    r = m;
    while (l <= r) {
      memset(vis, 0, sizeof(vis));
      mid = (l + r) / 2;
      if (dfs(1, l1[i], r1[mid])) {
        ans = max(ans, r1[mid] - l1[i] + 1);
        l = mid + 1;
      } else
        r = mid - 1;
    }
  }
  if (ans != 0)
    printf("%d", ans);
  else
    printf("Nice work, Dima!");
}
