At the entrance examination for the magistracy of the MSU Cyber-Mechanics Department Sasha got the question about Ford-Fulkerson algorithm. He knew the topic perfectly as he worked with it many times on programming competition. As the task for the question he was given a network with partially build flow that he had to use in order to demonstrate the workflow of the algorithm. He quickly finished to write the text and took a look at the problem only to understand that the given network is incorrect!

Suppose you are given a directed graph G(V, E) with two special nodes s and t called source and sink. We denote as n the number of nodes in the graph, i.e. n = |V| and m stands for the number of directed edges in the graph, i.e. m = |E|. For the purpose of this problem we always consider node 1 to be the source and node n to be the sink. In addition, for each edge of the graph e we define the capacity function c(e) and flow function f(e). Function f(e) represents the correct flow if the following conditions are satisfied:

  1. For each edge <image> the flow is non-negative and does not exceed capacity c(e), i.e. 0 ≤ f(e) ≤ c(e). 
  2. For each node <image>, that is not source or sink (v ≠ s and v ≠ t) the sum of flows of all edges going in v is equal to the sum of the flows among all edges going out from v. In other words, there is no flow stuck in v. 



It was clear that as the exam was prepared last night and there are plenty of mistakes in the tasks. Sasha asked one of the professors to fix the network or give the correct task, but the reply was that the magistrate student should be able to fix the network himself. As the professor doesn't want the task to become easier, he asks Sasha to fix the network in a such way that the total number of changes is minimum possible. Sasha is not allowed to remove edges, add new ones or reverse the direction of existing edges. The only thing he is able to do is to change capacity function c(e) and flow function f(e). Moreover, all the values should remain non-negative integers. There is no requirement on the flow to be maximum in any sense.

Find the minimum possible total change of the functions f(e) and c(e) that Sasha has to make in order to make the flow correct. The total change is defined as the sum of absolute differences, i.e. if new functions are f * (e) and c * (e), then the total change is <image>.

Input

The first line of the input contains two integers n and m (2 ≤ n ≤ 100, 0 ≤ m ≤ 100) — the number of nodes and edges in the graph respectively. Each of the following m lines contains the description of the edges, consisting of four integers ui, vi, ci and fi (1 ≤ ui, vi ≤ n, ui ≠ vi, 0 ≤ ci, fi ≤ 1 000 000) — index of the node the edges starts from, the index of the node the edge goes to, current capacity and flow value.

Node number 1 is the source, and node number n is the sink. It's guaranteed that no edge goes to the source, and no edges starts in the sink.

Given graph contains no self-loops but may contain multiple edges.

Output

Print one integer — the minimum total sum of changes that Sasha has to do in order to get the correct flow description.

Examples

Input

2 1
1 2 2 1


Output

0


Input

2 1
1 2 1 2


Output

1


Input

3 3
1 2 1 1
2 3 2 2
1 3 3 3


Output

1


Input

4 2
2 3 1 1
3 2 1 1


Output

0

Note

In the first sample, the flow is initially correct. Note, that the flow is not maximum, but this is not required.

In the second sample, the flow value of the only edge is greater than its capacity. There are two ways to fix this: either increase the capacity up to 2 or reduce the flow down to 1.

In the third sample, there is only 1 unit of flow coming to vertex 2, but there are 2 units going out of it. One of the possible solutions is to reduce the value of the flow on the second edge by 1.

In the fourth sample, there is isolated circulation of flow, but this description is correct by definition.
#include <bits/stdc++.h>
using namespace std;
namespace io {
const int SI = 1 << 21 | 1;
char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
int f, t;
inline void flush() { fwrite(OB, 1, OS - OB, stdout), OS = OB; }
inline void pc(char x) {
  *OS++ = x;
  if (OS == OT) flush();
}
template <class I>
inline void rd(I &x) {
  for (f = 1, c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                              IS == IT ? EOF : *IS++)
                            : *IS++);
       c < '0' || c > '9';
       c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                       IS == IT ? EOF : *IS++)
                     : *IS++))
    if (c == '-') f = -1;
  for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15),
      c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                      IS == IT ? EOF : *IS++)
                    : *IS++))
    ;
  x *= f;
}
template <class I>
inline void rda(I *a, int &n) {
  for (int i = 1; i <= n; i++) rd(a[i]);
}
inline void rds(char *s, int &x) {
  for (c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                       IS == IT ? EOF : *IS++)
                     : *IS++);
       c < 33 || c > 126;
       c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                       IS == IT ? EOF : *IS++)
                     : *IS++))
    ;
  for (x = 0; c >= 33 && c <= 126;
       s[++x] = c, c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                                   IS == IT ? EOF : *IS++)
                                 : *IS++))
    ;
  s[x + 1] = '\0';
}
template <class I>
inline void print(I x, char k = '\n') {
  if (!x) pc('0');
  if (x < 0) pc('-'), x = -x;
  while (x) ch[++t] = x % 10 + '0', x /= 10;
  while (t) pc(ch[t--]);
  pc(k);
}
inline void prints(string s) {
  int x = s.length();
  while (t < x) pc(s[t++]);
  pc('\n'), t = 0;
}
struct Flush {
  ~Flush() { flush(); }
} flusher;
}  // namespace io
using io::print;
using io::prints;
using io::rd;
using io::rda;
using io::rds;
namespace EK {
const int N = 1e4 + 7, M = 1e5 + 7;
const long long inf = 1e18;
int n, S, T, h[N], e[M], t[M], tot, pre[N], v[N];
long long mxf, ans, f[M], c[M], d[N], now[N];
inline void add(int x, int y, long long z, long long w, int o = 1) {
  e[++tot] = y, f[tot] = z, c[tot] = w, t[tot] = h[x], h[x] = tot;
  if (o) add(y, x, 0, -w, 0);
}
inline bool spfa() {
  for (int i = 1; i <= n; i++) v[i] = 0, d[i] = inf;
  queue<int> q;
  q.push(S), v[S] = 1, d[S] = 0, now[S] = inf;
  while (q.size()) {
    int x = q.front();
    q.pop(), v[x] = 0;
    for (int i = h[x]; i; i = t[i]) {
      int y = e[i];
      long long z = f[i], w = c[i];
      if (!z || d[y] <= d[x] + w) continue;
      d[y] = d[x] + w, now[y] = min(now[x], z), pre[y] = i;
      if (!v[y]) q.push(y), v[y] = 1;
    }
  }
  return d[T] != inf;
}
inline void upd() {
  mxf += now[T], ans += d[T] * now[T];
  int x = T;
  while (x != S)
    f[pre[x]] -= now[T], f[pre[x] ^ 1] += now[T], x = e[pre[x] ^ 1];
}
inline void main() {
  while (spfa()) upd();
}
inline void init(int _n, int _S, int _T) {
  n = _n, S = _S, T = _T, tot = 1, mxf = ans = 0;
  for (int i = 1; i <= n; i++) h[i] = 0;
}
}  // namespace EK
namespace no_min_cost_flow {
const int N = 1e5 + 7;
int n, S, T;
long long d[N], s;
inline void add(int x, int y, long long l, long long r, long long w) {
  EK::add(x, y, r - l, w), d[y] += l, d[x] -= l;
}
inline bool main() {
  for (int i = 1; i <= n; i++)
    if (d[i] > 0)
      EK::add(S, i, d[i], 0), s += d[i];
    else if (d[i] < 0)
      EK::add(i, T, -d[i], 0);
  EK::main();
  return EK::mxf == s;
}
inline void init(int _n) {
  n = _n, s = 0, S = n + 1, T = n + 2;
  EK::init(n + 2, S, T);
  for (int i = 1; i <= n; i++) d[i] = 0;
}
}  // namespace no_min_cost_flow
const long long inf = 1e18;
long long ans;
int main() {
  int n, m, S, T;
  rd(n), rd(m), S = 1, T = n;
  no_min_cost_flow::init(n);
  no_min_cost_flow::add(T, S, 0, inf, 0);
  for (int i = 1, u, v, c, f; i <= m; i++) {
    rd(u), rd(v), rd(c), rd(f);
    no_min_cost_flow::add(u, v, f, f, 0);
    if (c >= f) {
      no_min_cost_flow::add(v, u, 0, f, 1);
      no_min_cost_flow::add(u, v, 0, c - f, 1);
      no_min_cost_flow::add(u, v, 0, inf, 2);
    } else {
      ans += f - c;
      no_min_cost_flow::add(v, u, 0, c, 1);
      no_min_cost_flow::add(v, u, 0, f - c, 0);
      no_min_cost_flow::add(u, v, 0, inf, 2);
    }
  }
  no_min_cost_flow::main();
  print(EK::ans + ans);
  return 0;
}
