#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
vector<int> mp[maxn];
vector<int> R[maxn];
vector<int> L[maxn];
int ans = 0;
bool vis[maxn];
int n, m;
struct node {
  int last_L;
  int last_R;
} last[maxn];
void dfs(int now, int l, int r) {
  if (now == n) {
    ans = max(ans, r - l + 1);
    return;
  }
  for (int i = 0; i < mp[now].size(); i++) {
    if (vis[mp[now][i]]) continue;
    int nl = max(l, L[now][i]);
    int nr = min(r, R[now][i]);
    vis[mp[now][i]] = 1;
    if (nl <= nr && nr - nl + 1 > ans &&
        !(last[mp[now][i]].last_L <= nl && last[mp[now][i]].last_R >= nr))
      last[mp[now][i]].last_L = nl, last[mp[now][i]].last_R = nr,
      dfs(mp[now][i], nl, nr);
    vis[mp[now][i]] = 0;
  }
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b, l, r;
    cin >> a >> b >> l >> r;
    mp[a].push_back(b);
    mp[b].push_back(a);
    L[a].push_back(l);
    L[b].push_back(l);
    R[a].push_back(r);
    R[b].push_back(r);
  }
  vis[1] = 1;
  last[1].last_L = 1;
  last[1].last_R = INT_MAX;
  dfs(1, 1, INT_MAX);
  if (!ans)
    cout << "Nice work, Dima!" << endl;
  else
    cout << ans << endl;
  return 0;
}
