#include <bits/stdc++.h>
using namespace std;
typedef struct node {
  int pos, l, r;
} node;
int size;
int res[1000006];
int ans;
vector<node> graph[1005];
vector<int> leftarr, rightarr;
bool visited[1005];
bool comp(const node &n1, const node &n2) { return (n1.r <= n2.r); }
bool dfs(int v, int left, int right) {
  int i;
  visited[v] = true;
  if (v == size) return true;
  for (i = 0; i < graph[v].size(); i++) {
    node n = graph[v][i];
    if (!visited[n.pos]) {
      while (i < graph[v].size() && graph[v][i].pos == n.pos) {
        if (graph[v][i].l <= left && graph[v][i].r >= right) {
          visited[n.pos] = true;
          if (dfs(graph[v][i].pos, left, right)) return true;
        }
        i++;
      }
      i--;
    }
  }
  return false;
}
inline int findgr(int e) {
  int f = 0, l = rightarr.size() - 1, m;
  while ((l - f) > 1) {
    m = (f + l) / 2;
    if (rightarr[m] > e)
      l = m - 1;
    else if (rightarr[m] == e)
      f = m;
    else
      f = m + 1;
  }
  while (f < rightarr.size() && rightarr[f] <= e) f++;
  if (f == rightarr.size() && rightarr[f - 1] < e) return -1;
  if (f > 0 && rightarr[f - 1] == e) return f - 1;
  return f;
}
inline int find_size(int left) {
  int pos = findgr(left), f, l = rightarr.size() - 1, m;
  f = 0;
  if (f == -1) return 0;
  while ((l - f) > 1) {
    m = (f + l) / 2;
    memset(visited, 0, (size + 1));
    if (dfs(1, left, rightarr[m]))
      f = m;
    else
      l = m - 1;
  }
  memset(visited, 0, (size + 1));
  while (f < rightarr.size() && dfs(1, left, rightarr[f])) {
    f++;
    memset(visited, 0, (size + 1));
  }
  f--;
  if (f < 0) return 0;
  return (rightarr[f] - left + 1);
}
int solve() {
  int temp, j, i, max = 0;
  sort(rightarr.begin(), rightarr.end());
  sort(leftarr.begin(), leftarr.end());
  for (i = 0; i < leftarr.size(); i++) {
    temp = find_size(leftarr[i]);
    if (temp > max) max = temp;
    j = i;
    while (j < leftarr.size() && leftarr[j] == leftarr[i]) j++;
    i = j - 1;
  }
  return max;
}
int main() {
  int i, m, a1, a2, a3, a4;
  cin >> size >> m;
  ans = 0;
  for (i = 0; i < m; i++) {
    cin >> a1 >> a2 >> a3 >> a4;
    node n1, n2;
    n1.pos = a1;
    n1.l = a3;
    n1.r = a4;
    n2.pos = a2;
    n2.l = a3;
    n2.r = a4;
    graph[a1].push_back(n2);
    graph[a2].push_back(n1);
    leftarr.push_back(a3);
    rightarr.push_back(a4);
  }
  ans = solve();
  if (ans == 0)
    cout << "Nice work, Dima!\n";
  else
    cout << ans << endl;
  return 0;
}
