#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e3;
struct Edge {
  int to, left, right;
};
int n, m, maximumLoyalty;
vector<Edge> g[1 + nmax];
vector<int> lefts;
void citire() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    Edge foo;
    int from;
    scanf("%d%d%d%d", &from, &foo.to, &foo.left, &foo.right);
    g[from].push_back(foo);
    lefts.push_back(foo.left);
    swap(from, foo.to);
    g[from].push_back(foo);
  }
}
bool viz[1 + nmax];
void dfs(int from, int left, int right) {
  viz[from] = 1;
  for (auto& foo : g[from]) {
    if (viz[foo.to] == false) {
      if (foo.left <= left && right <= foo.right) {
        dfs(foo.to, left, right);
      }
    }
  }
}
bool ok(int left, int right) {
  memset(viz, 0, sizeof(viz));
  dfs(1, left, right);
  return viz[n];
}
void binarySearch(int left) {
  int l = left, r = 1e6;
  while (l <= r) {
    int med = (l + r) / 2;
    if (ok(left, med)) {
      l = med + 1;
      maximumLoyalty = max(maximumLoyalty, med - left + 1);
    } else {
      r = med - 1;
    }
  }
}
void solve() {
  for (auto& left : lefts) {
    binarySearch(left);
  }
  if (maximumLoyalty == 0) {
    printf("Nice work, Dima!\n");
  } else {
    printf("%d\n", maximumLoyalty);
  }
}
int main() {
  citire();
  solve();
  return 0;
}
