#include <bits/stdc++.h>
using namespace std;
struct node {
  int to;
  int l, r;
  node() {}
  node(int to, int l, int r) : to(to), l(l), r(r) {}
};
struct node1 {
  int l, r;
  node1() {}
  node1(int l, int r) : l(l), r(r) {}
};
vector<node> G[1010];
vector<node1> Q[1010];
int n, m, ans = 0;
bool book[1010], came[1010];
void init() {
  for (int i = 1; i <= n; i++) {
    G[i].clear();
    Q[i].clear();
  }
}
void add(int u, int v, int l, int r) {
  G[u].push_back(node(v, l, r));
  G[v].push_back(node(u, l, r));
}
void dfs(int cur, int le, int ri) {
  if (book[cur]) return;
  if (cur == n) {
    ans = max(ans, ri - le + 1);
    return;
  }
  if (ans >= ri - le + 1) return;
  book[cur] = 1;
  for (int i = 0; i < G[cur].size(); i++) {
    node tmp = G[cur][i];
    int newl = max(le, G[cur][i].l);
    int newr = min(ri, G[cur][i].r);
    if (newl > newr) continue;
    int flag = 1;
    for (int j = 0; j < Q[tmp.to].size(); j++) {
      if (Q[tmp.to][j].l <= newl && Q[tmp.to][j].r >= newr) {
        flag = 0;
        break;
      }
    }
    if (flag) {
      Q[tmp.to].push_back(node1(newl, newr));
      dfs(tmp.to, newl, newr);
    }
  }
  book[cur] = 0;
}
int main() {
  scanf("%d%d", &n, &m);
  init();
  for (int i = 1; i <= m; i++) {
    int u, v, l, r;
    scanf("%d%d%d%d", &u, &v, &l, &r);
    add(u, v, l, r);
  }
  ans = 0;
  memset(book, 0, sizeof(book));
  memset(came, 0, sizeof(came));
  dfs(1, 0, 1000000 + 10);
  if (ans)
    printf("%d\n", ans);
  else
    printf("Nice work, Dima!\n");
}
