2 2
1 2 1 4 2 4
1 2 3 4 4 4
 2 2
1 2 0 9998 0 9999
2 1 0 9999 0 10000
 3 3
1 2 0 3 -4 7
2 3 -2 5 1 6
3 1 0 4 0 4
 2 2
1 2 0 3 0 3
2 1 0 4 0 4
 2 2
1 2 0 0 0 0
2 1 0 0 0 0
 5 10
4 3 -19 49 -11 65
4 4 50 12 -2 65
1 5 56 8 -5 76
5 1 -28 33 -38 49
4 2 0 0 2 9
4 2 0 0 14 8
3 1 26 67 15 85
5 3 -51 98 -44 99
1 3 -33 65 -20 65
3 4 30 6 -30 70
 5 10
4 3 -8 16 -29 72
4 4 -62 65 33 65
1 5 -58 97 -17 97
5 1 -5 10 -68 88
4 2 0 0 -9 60
4 2 0 0 -23 39
3 1 3 28 13 87
5 3 -1 25 -15 90
1 3 -12 33 6 94
3 4 -71 86 -39 86
 5 10
4 3 -1 5 -6 98
4 4 12 14 -43 98
1 5 -4 6 8 88
5 1 0 0 -9 100
4 2 0 0 6 50
4 2 0 0 -39 77
3 1 1 4 -1 100
5 3 -7 13 9 88
1 3 2 0 -7 100
3 4 2 0 3 88
 2 2
1 1 0 4 0 5
2 2 4 0 5 0
 2 2
1 2 0 4 0 4
2 1 0 4 0 4
 2 2
1 2 0 3 0 5
2 1 0 4 0 6

0
 1.0000000000
 0.2500000000
 0
 1.0000000000
 0.2121212000
 0.6666666000
 1.0000000000
 1.0000000000
 1.0000000000
 1.0000000000

#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
struct edge {
  int to, next;
  long long f;
} e[N];
int head[N], tot, S, T;
int dis[N], q[N];
void add(int x, int y, long long v) {
  e[++tot] = (edge){y, head[x], v};
  head[x] = tot;
  e[++tot] = (edge){x, head[y], 0};
  head[y] = tot;
}
bool bfs() {
  for (int i = (int)(1); i <= (int)(T); i++) dis[i] = -1;
  int t = 1;
  dis[q[1] = S] = 0;
  for (int h = (int)(1); h <= (int)(t); h++)
    for (int i = head[q[h]]; i; i = e[i].next)
      if (dis[e[i].to] == -1 && e[i].f) {
        dis[e[i].to] = dis[q[h]] + 1;
        if (e[i].to == T) return 1;
        q[++t] = e[i].to;
      }
  return 0;
}
long long dfs(int x, long long flow) {
  if (x == T) return flow;
  long long k, rest = flow;
  for (int i = head[x]; i && rest; i = e[i].next)
    if (dis[e[i].to] == dis[x] + 1 && e[i].f) {
      k = dfs(e[i].to, min(rest, e[i].f));
      e[i].f -= k;
      e[i ^ 1].f += k;
      rest -= k;
    }
  if (rest) dis[x] = -1;
  return flow - rest;
}
int x[N], y[N], n, m;
int a[N], b[N], c[N], d[N];
long long deg[N], LIM = 100000000;
long long F(long long v) {
  for (int i = (int)(1); i <= (int)(n + 2); i++) head[i] = deg[i] = 0;
  S = n + 1;
  T = n + 2;
  tot = 1;
  for (int i = (int)(1); i <= (int)(m); i++) {
    long long L = a[i] * v + b[i] * LIM;
    long long R = c[i] * v + d[i] * LIM;
    add(x[i], y[i], R - L);
    deg[y[i]] += L;
    deg[x[i]] -= L;
  }
  long long ans = 0;
  for (int i = (int)(1); i <= (int)(n); i++)
    if (deg[i] > 0)
      add(S, i, deg[i]), ans += deg[i];
    else
      add(i, T, -deg[i]);
  for (; bfs(); ans -= dfs(S, 1ll << 60))
    ;
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (int)(1); i <= (int)(m); i++)
    scanf("%d%d%d%d%d%d", &x[i], &y[i], &a[i], &b[i], &c[i], &d[i]);
  int l = 0, r = LIM;
  for (; r - l >= 5;) {
    int m1 = l + (r - l) / 3, m2 = r - (r - l) / 3;
    if (F(m1) < F(m2))
      r = m2;
    else
      l = m1;
  }
  pair<long long, long long> mn(8e18, 8e18);
  for (int i = (int)(l); i <= (int)(r); i++)
    mn = min(mn, pair<long long, long long>(F(i), i));
  if (mn.first) return puts("0"), 0;
  l = mn.second + 1;
  r = LIM;
  int ansr = mn.second;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (!F(mid))
      ansr = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  l = 0;
  r = mn.second - 1;
  int ansl = mn.second;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (!F(mid))
      ansl = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%.10lf\n", 1.0 * (ansr - ansl) / LIM);
}
