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;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long double d[1001 + 5], in[1001 + 5];
int n, m, q[1001 + 5], head[1001 + 5], cnt, top, c[1001 + 5];
struct Edge {
  int u, v, a, b, c, d;
} s[2000 + 5];
struct edge {
  int to, next;
  long double cap;
} e[100005];
inline void ins(int f, int t, long double w) {
  e[++cnt] = (edge){t, head[f], w};
  head[f] = cnt;
  e[++cnt] = (edge){f, head[t], 0};
  head[t] = cnt;
}
bool bfs() {
  for (int i = 1; i <= 1001; ++i) d[i] = 1e9;
  int i, j;
  for (d[q[top = i = 1] = 0] = 0; i <= top; ++i)
    for (j = c[q[i]] = head[q[i]]; j; j = e[j].next)
      if (e[j].cap > 1e-9 && d[q[i]] + 1 < d[e[j].to])
        d[q[++top] = e[j].to] = d[q[i]] + 1;
  return d[1001] < 1e8;
}
long double dfs(int x, long double f) {
  if (x == 1001) return f;
  long double used = 0;
  for (int& i = c[x]; i; i = e[i].next)
    if (e[i].cap > 1e-9 && d[e[i].to] == d[x] + 1) {
      long double w = dfs(e[i].to, min(f - used, e[i].cap));
      used += w;
      e[i].cap -= w;
      e[i ^ 1].cap += w;
      if (f - used < 1e-9) return f;
    }
  return used;
}
long double Solve(long double t) {
  cnt = 1;
  memset(head, 0, sizeof(head));
  memset(in, 0, sizeof(in));
  for (int i = 1; i <= m; ++i) {
    long double l = t * s[i].a + s[i].b, r = t * s[i].c + s[i].d;
    ins(s[i].u, s[i].v, r - l);
    in[s[i].u] -= l;
    in[s[i].v] += l;
  }
  long double res = 0;
  for (int i = 1; i <= n; ++i)
    if (in[i] > 0)
      res += in[i], ins(0, i, in[i]);
    else
      ins(i, 1001, -in[i]);
  while (bfs()) res -= dfs(0, 1e9);
  return res;
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; ++i)
    s[i].u = read(), s[i].v = read(), s[i].a = read(), s[i].b = read(),
    s[i].c = read(), s[i].d = read();
  long double l = 0, r = 1, ok = -1;
  while (r - l > 1e-9) {
    long double m1 = l + (r - l) / 3, m2 = m1 + (r - l) / 3;
    long double r1 = Solve(m1), r2 = Solve(m2);
    if (r1 < 1e-9) {
      ok = m1;
      break;
    }
    if (r2 < 1e-9) {
      ok = m2;
      break;
    }
    if (r1 < r2)
      r = m2;
    else
      l = m1;
  }
  if (ok < 0) return 0 * puts("0");
  l = 0, r = ok;
  long double L = ok, R = ok;
  while (r - l > 1e-9) {
    long double mid = (l + r) * 0.5;
    if (Solve(mid) < 1e-9)
      L = mid, r = mid;
    else
      l = mid;
  }
  l = ok;
  r = 1;
  while (r - l > 1e-9) {
    long double mid = (l + r) * 0.5;
    if (Solve(mid) < 1e-9)
      R = mid, l = mid;
    else
      r = mid;
  }
  printf("%.10lf\n", (double)(R - L));
  return 0;
}
