#include <bits/stdc++.h>
using namespace std;
int n, res;
set<pair<int, int> > pass[3010], tmp;
set<pair<int, int> >::iterator it;
int adj[3010][3010], deg[3010];
pair<int, int> range[3010][3010];
void go(int u, int l, int r) {
  if (r - l + 1 <= res) return;
  if (u == n - 1) {
    res = max(res, r - l + 1);
    return;
  }
  int i, v, ll, rr;
  for (i = 0; i < deg[u]; i++) {
    v = adj[u][i];
    ll = max(l, range[u][i].first);
    rr = min(r, range[u][i].second);
    if (pass[v].empty()) {
      pass[v].insert(pair<int, int>(ll, rr));
      go(v, ll, rr);
    } else {
      tmp.clear();
      for (it = pass[v].begin(); it != pass[v].end(); it++) {
        if ((*it).first <= ll && (*it).second >= rr) break;
        if ((*it).first >= ll && (*it).second <= rr) tmp.insert(*it);
      }
      if (it != pass[v].end()) continue;
      for (it = tmp.begin(); it != tmp.end(); it++) pass[v].erase(*it);
      pass[v].insert(pair<int, int>(ll, rr));
      go(v, ll, rr);
    }
  }
}
int main() {
  int u, v, l, r, i, m;
  scanf("%d %d ", &n, &m);
  memset(deg, 0, sizeof(deg));
  for (i = 0; i < m; i++) {
    scanf("%d %d %d %d ", &u, &v, &l, &r);
    u--;
    v--;
    range[u][deg[u]] = pair<int, int>(l, r);
    range[v][deg[v]] = pair<int, int>(l, r);
    adj[u][deg[u]++] = v;
    adj[v][deg[v]++] = u;
  }
  res = 0;
  for (i = 0; i < n; i++) pass[i].clear();
  go(0, -0x3f3f3f3f, 0x3f3f3f3f);
  if (res)
    printf("%d\n", res);
  else
    puts("Nice work, Dima!");
  return 0;
}
