#include <bits/stdc++.h>
using namespace std;
int ans = 0;
int visit[1050] = {0};
vector<pair<int, pair<int, int> > > v[1050];
int l[10000];
int r[10000];
void dfs(int s, int lb, int ub) {
  visit[s] = 1;
  for (int i = 0; i < v[s].size(); i++) {
    if (visit[v[s][i].first] == -1 && v[s][i].second.first <= lb &&
        v[s][i].second.second >= ub) {
      dfs(v[s][i].first, lb, ub);
    }
  }
  return;
}
int main() {
  int n, m, a, b, c, d, i, ans = 0;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> a >> b >> c >> d;
    v[a].push_back(make_pair(b, make_pair(c, d)));
    v[b].push_back(make_pair(a, make_pair(c, d)));
    l[i - 1] = c;
    r[i - 1] = d;
  }
  sort(l, l + m);
  sort(r, r + m);
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      memset(visit, -1, sizeof(visit));
      if (ans < (r[j] - l[i] + 1)) dfs(1, l[i], r[j]);
      if (visit[n] == 1) {
        ans = max(ans, r[j] - l[i] + 1);
      }
    }
  }
  if (ans)
    cout << ans << endl;
  else
    cout << "Nice work, Dima!" << endl;
  return 0;
}
