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 NMAX = 1005;
const int MMAX = 2005;
const double EPS = 1e-7;
template <class CapacityType>
class MaxFlow {
 private:
  static constexpr int NIL = -1;
  static constexpr double EPS = 1e-7;
  static constexpr int INF = std::numeric_limits<int>::max() / 2;
  template <class type>
  int cmp(type x) {
    if (-EPS < x and x < EPS) return 0;
    return x < 0 ? -1 : 1;
  }
  struct Edge {
    int nod, nxt;
    CapacityType cap;
    Edge() : nod(0), nxt(0), cap(0){};
    Edge(int _nod, int _nxt, CapacityType _cap)
        : nod(_nod), nxt(_nxt), cap(_cap){};
  };
  std::vector<Edge> lst;
  std::vector<bool> oki;
  int ptr = 0;
  std::vector<int> beg, que, adj, dis;
  bool bfs(const int src, const int dst) {
    std::fill(dis.begin(), dis.end(), (CapacityType)INF);
    dis[src] = 0;
    que[0] = src;
    for (int qbg = 0, qen = 0; qbg <= qen; ++qbg) {
      const int x = que[qbg];
      for (int it = beg[x]; it != NIL; it = lst[it].nxt) {
        const int y = lst[it].nod;
        if (cmp(lst[it].cap) > 0 and dis[y] == INF)
          dis[y] = dis[x] + 1, que[++qen] = y;
      }
    }
    return dis[dst] != INF;
  }
  CapacityType dfs(const int x, const int dst, const CapacityType cap) {
    if (!cmp(cap) or x == dst) return cap;
    for (; adj[x] != NIL; adj[x] = lst[adj[x]].nxt) {
      const int y = lst[adj[x]].nod;
      if (cmp(lst[adj[x]].cap) > 0 and dis[y] == dis[x] + 1) {
        const CapacityType aux = dfs(y, dst, std::min(cap, lst[adj[x]].cap));
        if (cmp(aux)) {
          lst[adj[x]].cap -= aux;
          lst[adj[x] ^ 1].cap += aux;
          return aux;
        }
      }
    }
    return 0;
  }
  void fill(const int x) {
    oki[x] = true;
    for (int it = beg[x]; it != NIL; it = lst[it].nxt) {
      const int y = lst[it].nod;
      if (cmp(lst[it].cap) > 0 and !oki[y]) fill(y);
    }
  }

 public:
  MaxFlow(int szn, int szm) {
    dis.resize(szn);
    beg.resize(szn);
    que.resize(szn);
    adj.resize(szn);
    oki.resize(szn);
    lst.resize(szm);
    std::fill(beg.begin(), beg.end(), (int)NIL);
  }
  inline void addDirectedEdge(const int x, const int y,
                              const CapacityType cap) {
    lst[ptr] = Edge(y, beg[x], cap);
    beg[x] = ptr++;
    lst[ptr] = Edge(x, beg[y], 0);
    beg[y] = ptr++;
  }
  inline void addUndirectedEdge(const int x, const int y,
                                const CapacityType cap) {
    lst[ptr] = Edge(y, beg[x], cap);
    beg[x] = ptr++;
    lst[ptr] = Edge(x, beg[y], cap);
    beg[y] = ptr++;
  }
  CapacityType getMaxFlow(const int src, const int dst) {
    CapacityType aux, ans = 0;
    while (bfs(src, dst)) {
      copy(beg.begin(), beg.end(), adj.begin());
      do {
        aux = dfs(src, dst, INF);
        ans += aux;
      } while (cmp(aux));
    }
    return ans;
  }
  CapacityType getMinCut(const int src, const int dst, std::vector<int> &ans) {
    std::fill(oki.begin(), oki.end(), false);
    CapacityType sol = getMaxFlow(src, dst);
    fill(src);
    ans.clear();
    for (int i = 0; i < oki.size(); ++i)
      if (oki[i]) ans.push_back(i);
    return sol;
  }
};
struct edge {
  int x, y, a, b, c, d;
} edl[MMAX];
inline double sign(double x) {
  if (-EPS < x and x < +EPS) return 0;
  return x < 0 ? -1 : 1;
}
double check(double t, int n, int m) {
  int src = n + 1, dst = n + 2;
  double sum = 0;
  MaxFlow<double> myNetwork(n + 5, m * 6 + 5);
  for (int i = 1; i <= m; ++i) {
    int x = edl[i].x, y = edl[i].y;
    double le = t * edl[i].a + edl[i].b, ri = t * edl[i].c + edl[i].d;
    sum += le;
    myNetwork.addDirectedEdge(x, y, ri - le);
    myNetwork.addDirectedEdge(src, y, le);
    myNetwork.addDirectedEdge(x, dst, le);
  }
  return sum - myNetwork.getMaxFlow(src, dst);
}
double solve(double le, double ri, int n, int m) {
  double ans = 0;
  for (int i = 1; i <= 50; ++i) {
    double md = (le + ri) / 2.0;
    if (sign(check(md, n, m)) <= 0) {
      ans += fabs(md - le);
      le = md;
    } else
      ri = md;
  }
  return ans;
}
void debug(void) {
  MaxFlow<double> myNetwork(4, 6);
  myNetwork.addDirectedEdge(1, 2, 0.5);
  myNetwork.addDirectedEdge(2, 3, 0.3);
  cerr << myNetwork.getMaxFlow(1, 3);
  exit(0);
}
int main(void) {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> edl[i].x >> edl[i].y;
    cin >> edl[i].a >> edl[i].b >> edl[i].c >> edl[i].d;
  }
  double le = 0.0, ri = 1.0;
  for (int i = 1; i <= 50; ++i) {
    double md1 = le + (ri - le) / 3.0, md2 = ri - (ri - le) / 3.0;
    double ans1 = check(md1, n, m), ans2 = check(md2, n, m);
    if (sign(ans1) <= 0 and sign(ans2) <= 0) {
      cout << setprecision(10) << fixed;
      cout << solve((md1 + md2) / 2.0, 1.0, n, m) +
                  solve((md1 + md2) / 2.0, 0.0, n, m);
      exit(0);
    }
    if (ans1 < ans2)
      ri = md2;
    else
      le = md1;
  }
  cout << setprecision(10) << fixed << 0.0;
  return 0;
}
