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 long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const double EPS = 1e-9;
const double inf = 1e20;
inline int sign(double a) { return a < -EPS ? -1 : a > EPS; }
inline int cmp(double a, double b) { return sign(a - b); }
const int N = 101000;
int ts, u[N], v[N], a[N], b[N], c[N], d[N], n, m;
namespace flow {
const int M = 100000, N = 1000;
int y[M], nxt[M], gap[N], fst[N], c[N], pre[N], q[N], dis[N];
int slope[M];
double f[M];
int S, T, tot, Tn;
void init(int s, int t, int tn) {
  tot = 1;
  memset(fst, 0, sizeof(fst));
  S = s;
  T = t;
  Tn = tn;
}
void add(int u, int v, int c, double c1, double c2 = 0) {
  tot++;
  y[tot] = v;
  f[tot] = c1;
  nxt[tot] = fst[u];
  fst[u] = tot;
  slope[tot] = c;
  tot++;
  y[tot] = u;
  f[tot] = c2;
  nxt[tot] = fst[v];
  fst[v] = tot;
  slope[tot] = 0;
}
double sap() {
  int u = S, t = 1;
  double flow = 0;
  for (int i = 0; i < Tn; i++) c[i] = fst[i], dis[i] = Tn, gap[i] = 0;
  q[0] = T;
  dis[T] = 0;
  pre[S] = 0;
  for (int i = 0; i < t; i++) {
    int u = q[i];
    for (int j = fst[u]; j; j = nxt[j])
      if (dis[y[j]] > dis[u] + 1 && fabs(f[j ^ 1]) > EPS)
        q[t++] = y[j], dis[y[j]] = dis[u] + 1;
  }
  for (int i = 0; i < Tn; i++) gap[dis[i]]++;
  while (dis[S] <= Tn) {
    while (c[u] && (fabs(f[c[u]]) < EPS || dis[y[c[u]]] + 1 != dis[u]))
      c[u] = nxt[c[u]];
    if (c[u]) {
      pre[y[c[u]]] = c[u] ^ 1;
      u = y[c[u]];
      if (u == T) {
        double minf = inf;
        for (int p = pre[T]; p; p = pre[y[p]]) minf = min(minf, f[p ^ 1]);
        for (int p = pre[T]; p; p = pre[y[p]]) f[p ^ 1] -= minf, f[p] += minf;
        flow += minf;
        u = S;
      }
    } else {
      if (!(--gap[dis[u]])) break;
      int mind = Tn;
      c[u] = fst[u];
      for (int j = fst[u]; j; j = nxt[j])
        if (fabs(f[j]) > EPS && dis[y[j]] < mind) mind = dis[y[j]], c[u] = j;
      dis[u] = mind + 1;
      gap[dis[u]]++;
      if (u != S) u = y[pre[u]];
    }
  }
  q[0] = S;
  t = 1;
  for (int i = 0; i < Tn; i++) dis[i] = Tn;
  for (int i = 0; i < t; i++) {
    int u = q[i];
    for (int j = fst[u]; j; j = nxt[j])
      if (dis[y[j]] > dis[u] + 1 && fabs(f[j]) > EPS) {
        dis[y[j]] = dis[u] + 1;
        q[t++] = y[j];
      }
  }
  ts = 0;
  for (int i = 0; i < Tn; i++)
    for (int j = fst[i]; j; j = nxt[j])
      if (dis[i] < Tn && dis[y[j]] >= Tn) {
        ts += slope[j];
      }
  return flow;
}
};  // namespace flow
double bel[N];
int sl[N];
int check(double t) {
  for (int i = 1; i < n + 1; i++) bel[i] = 0, sl[i] = 0;
  flow::init(0, n + 1, n + 2);
  for (int i = 0; i < m; i++) {
    double l = a[i] * t + b[i], r = c[i] * t + d[i];
    flow::add(u[i], v[i], c[i] - a[i], r - l);
    bel[u[i]] += l;
    bel[v[i]] -= l;
    sl[u[i]] += a[i];
    sl[v[i]] -= a[i];
  }
  double sf = 0;
  int ss = 0;
  for (int i = 1; i < n + 1; i++)
    if (bel[i] > 0) {
      sf += bel[i];
      flow::add(i, n + 1, sl[i], bel[i]);
      ss += sl[i];
    } else
      flow::add(0, i, -sl[i], -bel[i]);
  double r = flow::sap();
  if (ts == ss) {
    if (cmp(r, sf) == -1)
      return 2;
    else
      return 1;
  } else if (ts > ss)
    return 0;
  else
    return 2;
}
double gao(int ty) {
  double l = 0, r = 1;
  for (int it = 0; it < 60; it++) {
    double md = (l + r) * 0.5;
    if (check(md) >= ty)
      r = md;
    else
      l = md;
  }
  return 0.5 * (l + r);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++)
    scanf("%d%d%d%d%d%d", u + i, v + i, a + i, b + i, c + i, d + i);
  double l = gao(1), r = gao(2);
  printf("%.10f\n", r - l);
}
