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 = 50010;
const long long E = 1e7;
const long long INF = 1e18;
long long n, m, ct;
long long u[N], v[N], a[N], b[N], c[N], d[N];
long long hd[N], nxt[N], to[N], cp[N];
long long dst[N], que[N], cur[N];
long long head, tail;
void link(int u, int v, long long c) {
  to[++ct] = v;
  cp[ct] = c;
  nxt[ct] = hd[u];
  hd[u] = ct;
}
bool bfs() {
  for (int i = 0; i <= (n + 1); i++) dst[i] = 0;
  dst[0] = 1;
  head = 0, tail = 1;
  que[++head] = 0;
  while (head <= tail) {
    int u = que[head++];
    for (int i = hd[u]; i; i = nxt[i]) {
      int v = to[i];
      if (!dst[v] && cp[i] > 0) {
        dst[v] = dst[u] + 1;
        que[++tail] = v;
        if (v == (n + 1)) break;
      }
    }
  }
  return dst[(n + 1)];
}
long long dfs(long long u, long long f) {
  if (u == (n + 1) || f == 0) return f;
  long long vf = 0;
  for (long long &i = cur[u]; i; i = nxt[i]) {
    if (cp[i] > 0 && dst[to[i]] == dst[u] + 1) {
      long long fl = dfs(to[i], min(f, cp[i]));
      if (fl) {
        cp[i] -= fl;
        cp[i ^ 1] += fl;
        f -= fl;
        vf += fl;
        if (!f) break;
      }
    }
  }
  return vf;
}
long long dinic() {
  long long ret = 0;
  while (bfs()) {
    for (int i = 0; i <= (n + 1); i++) cur[i] = hd[i];
    while (long long f = dfs(0, INF)) ret += f;
  }
  return ret;
}
long long flow(long long x) {
  long long ret = 0;
  ct = 1;
  for (int i = 0; i <= (n + 1); i++) hd[i] = 0;
  for (int i = 1; i <= m; i++) {
    long long lb = a[i] * x + b[i], ub = c[i] * x + d[i];
    ret += lb;
    link(0, v[i], lb);
    link(v[i], 0, 0);
    link(u[i], (n + 1), lb);
    link((n + 1), u[i], 0);
    link(u[i], v[i], ub - lb);
    link(v[i], u[i], 0);
  }
  return ret - dinic();
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> u[i] >> v[i] >> a[i] >> b[i] >> c[i] >> d[i];
    b[i] *= E;
    d[i] *= E;
  }
  int l = 0, r = E;
  while (r - l >= 3) {
    int df = (r - l) / 3;
    if (flow(l + df) < flow(r - df))
      r -= df;
    else
      l += df;
  }
  long long mf = flow(l);
  for (int i = l + 1; i <= r; i++) {
    if (long long f = flow(i) < mf) {
      mf = f;
      l = i;
    }
  }
  if (mf > 0) return puts("0"), 0;
  int lp = 0, rp = l - 1;
  while (lp <= rp) {
    int m = (lp + rp) / 2;
    if (flow(m) > 0)
      lp = m + 1;
    else
      rp = m - 1;
  }
  long long ans = -lp;
  lp = l + 1, rp = E;
  while (lp <= rp) {
    int m = (lp + rp) / 2;
    if (flow(m) > 0)
      rp = m - 1;
    else
      lp = m + 1;
  }
  ans += rp;
  cout << fixed << setprecision(10) << (double)ans / E << endl;
  return 0;
}
