#include <bits/stdc++.h>
using namespace std;
const int MAXINT = 1 << 31 - 1;
const int MAXN = 1e3 + 5;
class Edge {
 public:
  int id, to, lo, hi;
  Edge(int i, int t, int l, int h) {
    id = i;
    to = t;
    lo = l;
    hi = h;
  }
};
vector<Edge> graph[MAXN];
bool vis[MAXN];
int n, m;
bool dfs(int cur, int target, int le, int ri) {
  if (ri - le + 1 < target) {
    return false;
  }
  if (cur == n) {
    return true;
  }
  vis[cur] = true;
  for (int i = (0); i < (graph[cur].size()); i += 1) {
    int next = graph[cur][i].to;
    if (vis[next]) {
      continue;
    }
    int nextLe = max(le, graph[cur][i].lo);
    int nextRi = min(ri, graph[cur][i].hi);
    bool res = dfs(next, target, nextLe, nextRi);
    if (res) {
      return true;
    }
  }
  vis[cur] = false;
  return false;
}
bool judge(int wide) {
  memset(vis, false, sizeof(vis));
  bool res = dfs(1, wide, 0, MAXINT);
  return res;
}
int main() {
  while (cin >> n >> m) {
    for (int i = (1); i < (n + 1); i += 1) {
      graph[i].clear();
    }
    int wide = 0;
    for (int i = (0); i < (m); i += 1) {
      int a, b, l, r;
      scanf("%d %d %d %d", &a, &b, &l, &r);
      graph[a].push_back(Edge(i + 1, b, l, r));
      graph[b].push_back(Edge(i + 1, a, l, r));
      wide = max(wide, r - l + 1);
    }
    int low = 0, up = wide + 1;
    while (low + 1 < up) {
      int mid = (low + up) / 2;
      bool res = judge(mid);
      if (res) {
        low = mid;
      } else {
        up = mid;
      }
    }
    if (judge(low + 1)) {
      low++;
    }
    if (low <= 0) {
      puts("Nice work, Dima!");
    } else {
      cout << low << endl;
    }
  }
  return 0;
}
