#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010, max_range = 1000001;
int edge[maxn][3 * maxn], reached[maxn], start[3 * maxn], len[3 * maxn],
    vert[3 * maxn][2], n, m, res;
FILE *in;
int nb(int v, int e) {
  if (vert[e][0] == v)
    return vert[e][1];
  else
    return vert[e][0];
}
int dfs(int sz, int x, int v) {
  reached[v] = 1;
  if (v == n) return 1;
  int e, u;
  for (int i = 1; i <= edge[v][0]; i++) {
    e = edge[v][i];
    u = nb(v, e);
    if (reached[u] == 0 && x >= start[e] && x - start[e] <= len[e] - sz) {
      if (dfs(sz, x, u) == 1) return 1;
    }
  }
  return 0;
}
bool check(int sz) {
  int res = 0;
  for (int i = 1; i <= m; i++)
    if (len[i] >= sz) {
      memset(reached, 0, sizeof(reached));
      res = dfs(sz, start[i], 1);
      if (res == 1) break;
    }
  return res == 1;
}
void init() {
  int x, y, l, r;
  fscanf(in, "%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    fscanf(in, "%d %d %d %d", &x, &y, &l, &r);
    edge[x][0]++;
    edge[x][edge[x][0]] = i;
    edge[y][0]++;
    edge[y][edge[y][0]] = i;
    start[i] = l;
    len[i] = r - l + 1;
    vert[i][0] = x;
    vert[i][1] = y;
  }
}
int solve() {
  int l = 0, r = max_range, s = (l + r) / 2;
  while (r - l > 1) {
    if (check(s))
      l = s;
    else
      r = s;
    s = (l + r) / 2;
  }
  return s;
}
int main() {
  in = stdin;
  init();
  res = solve();
  if (res == 0)
    printf("Nice work, Dima!\n");
  else
    printf("%d", res);
  return 0;
}
