#include <bits/stdc++.h>
using namespace std;
struct data {
  int x, y, l, r;
  bool operator<(const data &p) const { return r > p.r; }
  data() {}
  data(int a, int b, int c, int d) {
    x = a;
    y = b;
    l = c;
    r = d;
  }
};
int n, m, par[100050];
vector<data> edge;
int Find(int at) {
  if (par[at] == at) return at;
  return par[at] = Find(par[at]);
}
void Union(int a, int b) {
  int x = Find(a);
  int y = Find(b);
  if (x != y) {
    par[x] = y;
  }
}
int solve(int low) {
  for (int i = 1; i <= n; i++) par[i] = i;
  for (int i = 0; i < m; i++) {
    if (edge[i].l > low) continue;
    Union(edge[i].x, edge[i].y);
    if (Find(1) == Find(n)) {
      return edge[i].r - low + 1;
    }
  }
  return 0;
}
int main() {
  int x, y, l, r;
  scanf("%d %d", &n, &m);
  for (int I = 0; I < m; I++) {
    scanf("%d %d %d %d", &x, &y, &l, &r);
    edge.push_back(data(x, y, l, r));
  }
  sort(edge.begin(), edge.end());
  int ret = 0;
  for (int i = 0; i < m; i++) {
    ret = max(ret, solve(edge[i].l));
  }
  if (ret == 0)
    printf("Nice work, Dima!\n");
  else
    printf("%d\n", ret);
  return 0;
}
