#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
int lcm(int x, int y) { return x * y / gcd(x, y); }
int n, m;
bool graph[1001][1001], visited[1001];
vector<int> l[1001][1001];
vector<int> r[1001][1001];
bool check(int node, int s, int e, int diff) {
  if (e - s + 1 < diff) return false;
  if (e < s) return false;
  if (node == n) return true;
  visited[node] = true;
  for (int to = 1; to < 1001; ++to) {
    if (node != to && graph[node][to] && !visited[to]) {
      for (int c = 0; c < l[node][to].size(); ++c) {
        int ll = l[node][to][c];
        int rr = r[node][to][c];
        if (check(to, max(s, ll), min(e, rr), diff)) return true;
      }
    }
  }
  visited[node] = false;
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  memset(graph, 0, sizeof(graph));
  for (int i = 0; i < m; ++i) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    graph[a][b] = graph[b][a] = true;
    l[a][b].push_back(c);
    l[b][a].push_back(c);
    r[a][b].push_back(d);
    r[b][a].push_back(d);
  }
  int left = 1, right = 1000000, mid, ret = -1;
  while (left <= right) {
    mid = (left + right) / 2;
    memset(visited, 0, sizeof(visited));
    if (check(1, 1, 1000000, mid)) {
      left = mid + 1;
      ret = mid;
    } else {
      right = mid - 1;
    }
  }
  if (ret <= 0)
    printf("Nice work, Dima!");
  else
    printf("%d\n", ret);
  return 0;
}
