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 = 1e3 + 10, M = 2e3 + 10, D = N, E = 1e5 + 10;
int n, m, S, T;
struct QAQ {
  int x, y, a, b, c, d;
} q[M];
struct Edge {
  int to, nxt;
  long double cap;
} e[E];
int cnt, lnk[D], mn[D], level[D];
long double sum[D];
bool bfs() {
  queue<int> q;
  memset(level, 0x3f, sizeof(level));
  q.push(S);
  level[S] = 1;
  while (q.size()) {
    int x = q.front();
    q.pop();
    for (int i = lnk[x]; i; i = e[i].nxt) {
      int y = e[i].to;
      if (e[i].cap > 1e-9 && level[y] > level[x] + 1) {
        level[y] = level[x] + 1;
        q.push(y);
      }
    }
  }
  return level[T] < 1e9;
}
long double dinic(int x, long double flow) {
  if (x == T) return flow;
  long double rest = flow, k;
  for (int i = lnk[x]; i && rest > 1e-9; i = e[i].nxt) {
    int y = e[i].to;
    if (e[i].cap > 1e-9 && level[y] == level[x] + 1) {
      k = dinic(y, min(rest, e[i].cap));
      if (k < 1e-9) level[y] = 0;
      rest -= k, e[i].cap -= k, e[i ^ 1].cap += k;
    }
  }
  return flow - rest;
}
void adde(int x, int y, long double c) {
  e[++cnt] = (Edge){y, lnk[x], c}, lnk[x] = cnt;
  e[++cnt] = (Edge){x, lnk[y], 0}, lnk[y] = cnt;
}
long double chk(long double t) {
  cnt = 1;
  memset(lnk, 0, sizeof(lnk));
  memset(sum, 0, sizeof(sum));
  for (int i = 1; i <= m; i++) {
    long double l = q[i].a * t + q[i].b, r = q[i].c * t + q[i].d;
    adde(q[i].x, q[i].y, r - l);
    sum[q[i].x] -= l, sum[q[i].y] += l;
  }
  long double tot = 0;
  for (int i = 1; i <= n; i++) {
    if (sum[i] > 0)
      adde(S, i, sum[i]), tot += sum[i];
    else
      adde(i, T, -sum[i]);
  }
  while (bfs()) tot -= dinic(S, 1e9);
  return tot;
}
int main() {
  cin >> n >> m;
  S = 0, T = 1001;
  for (int i = 1; i <= m; i++) {
    int x, y, a, b, c, d;
    scanf("%d%d%d%d%d%d", &x, &y, &a, &b, &c, &d);
    q[i] = (QAQ){x, y, a, b, c, d};
  }
  long double top = -1, l = 0, r = 1;
  for (int i = 1; i <= 50; i++) {
    long double lmid = l + (r - l) / 3, rmid = lmid + (r - l) / 3;
    long double lans = chk(lmid), rans = chk(rmid);
    if (lans < 1e-9) {
      top = lmid;
      break;
    }
    if (rans < 1e-9) {
      top = rmid;
      break;
    }
    if (lans < rans)
      r = rmid;
    else
      l = lmid;
  }
  if (top < 0) return puts("0"), 0;
  long double L = top, R = top;
  l = 0, r = top;
  for (int i = 1; i <= 50; i++) {
    long double mid = (l + r) * 0.5;
    if (chk(mid) < 1e-9)
      L = mid, r = mid;
    else
      l = mid;
  }
  l = top, r = 1;
  for (int i = 1; i <= 50; i++) {
    long double mid = (l + r) * 0.5;
    if (chk(mid) < 1e-9)
      R = mid, l = mid;
    else
      r = mid;
  }
  printf("%.10lf\n", (double)(R - L));
  return 0;
}
