#include <bits/stdc++.h>
using namespace std;
const int maxn = 20000 + 5;
const int INF = 0x3f3f3f3f;
int vis[maxn];
int dis[maxn], pre[maxn], last[maxn], flow[maxn], maxflow, mincost;
struct Edge {
  int to, next, flow, dis;
} edge[maxn * 2 + 1];
int head[maxn], num_edge;
void init() {
  memset(head, -1, sizeof(head));
  num_edge = -1;
  maxflow = 0;
  mincost = 0;
}
void add_edge(int from, int to, int flow, int dis) {
  edge[++num_edge].next = head[from];
  edge[num_edge].to = to;
  edge[num_edge].flow = flow;
  edge[num_edge].dis = dis;
  head[from] = num_edge;
  edge[++num_edge].next = head[to];
  edge[num_edge].to = from;
  edge[num_edge].flow = 0;
  edge[num_edge].dis = -dis;
  head[to] = num_edge;
}
bool spfa(int s, int t) {
  queue<int> q;
  memset(dis, 0x7f, sizeof(dis));
  memset(flow, 0x7f, sizeof(flow));
  memset(vis, 0, sizeof(vis));
  q.push(s);
  vis[s] = 1;
  dis[s] = 0;
  pre[t] = -1;
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    vis[now] = 0;
    for (int i = head[now]; i != -1; i = edge[i].next) {
      if (edge[i].flow > 0 && dis[edge[i].to] > dis[now] + edge[i].dis) {
        dis[edge[i].to] = dis[now] + edge[i].dis;
        pre[edge[i].to] = now;
        last[edge[i].to] = i;
        flow[edge[i].to] = min(flow[now], edge[i].flow);
        if (!vis[edge[i].to]) {
          vis[edge[i].to] = 1;
          q.push(edge[i].to);
        }
      }
    }
  }
  return pre[t] != -1;
}
void MCMF(int s, int t) {
  while (spfa(s, t)) {
    int now = t;
    maxflow += flow[t];
    mincost += flow[t] * dis[t];
    while (now != s) {
      edge[last[now]].flow -= flow[t];
      edge[last[now] ^ 1].flow += flow[t];
      now = pre[now];
    }
  }
}
int main() {
  int n, m, a, b, c, f, ml[maxn], ans = 0;
  init();
  memset(ml, 0, sizeof(ml));
  scanf("%d%d", &n, &m);
  int S = 0, T = n + 1;
  while (m--) {
    scanf("%d%d%d%d", &a, &b, &c, &f);
    if (c < f) {
      mincost += f - c;
      ml[a] += f, ml[b] -= f;
      add_edge(b, a, f - c, 0), add_edge(b, a, c, 1), add_edge(a, b, INF, 2);
    } else {
      ml[a] += f, ml[b] -= f;
      add_edge(a, b, c - f, 1), add_edge(a, b, INF, 2), add_edge(b, a, f, 1);
    }
  }
  add_edge(n, 1, INF, 0);
  for (int i = 1; i <= n; i++) {
    if (ml[i] >= 0) {
      add_edge(i, T, ml[i], 0);
    } else {
      add_edge(S, i, -ml[i], 0);
    }
  }
  MCMF(S, T);
  cout << mincost << endl;
}

### Prompt

Your task is to create a cpp solution to the following problem:

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.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 20000 + 5;
const int INF = 0x3f3f3f3f;
int vis[maxn];
int dis[maxn], pre[maxn], last[maxn], flow[maxn], maxflow, mincost;
struct Edge {
  int to, next, flow, dis;
} edge[maxn * 2 + 1];
int head[maxn], num_edge;
void init() {
  memset(head, -1, sizeof(head));
  num_edge = -1;
  maxflow = 0;
  mincost = 0;
}
void add_edge(int from, int to, int flow, int dis) {
  edge[++num_edge].next = head[from];
  edge[num_edge].to = to;
  edge[num_edge].flow = flow;
  edge[num_edge].dis = dis;
  head[from] = num_edge;
  edge[++num_edge].next = head[to];
  edge[num_edge].to = from;
  edge[num_edge].flow = 0;
  edge[num_edge].dis = -dis;
  head[to] = num_edge;
}
bool spfa(int s, int t) {
  queue<int> q;
  memset(dis, 0x7f, sizeof(dis));
  memset(flow, 0x7f, sizeof(flow));
  memset(vis, 0, sizeof(vis));
  q.push(s);
  vis[s] = 1;
  dis[s] = 0;
  pre[t] = -1;
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    vis[now] = 0;
    for (int i = head[now]; i != -1; i = edge[i].next) {
      if (edge[i].flow > 0 && dis[edge[i].to] > dis[now] + edge[i].dis) {
        dis[edge[i].to] = dis[now] + edge[i].dis;
        pre[edge[i].to] = now;
        last[edge[i].to] = i;
        flow[edge[i].to] = min(flow[now], edge[i].flow);
        if (!vis[edge[i].to]) {
          vis[edge[i].to] = 1;
          q.push(edge[i].to);
        }
      }
    }
  }
  return pre[t] != -1;
}
void MCMF(int s, int t) {
  while (spfa(s, t)) {
    int now = t;
    maxflow += flow[t];
    mincost += flow[t] * dis[t];
    while (now != s) {
      edge[last[now]].flow -= flow[t];
      edge[last[now] ^ 1].flow += flow[t];
      now = pre[now];
    }
  }
}
int main() {
  int n, m, a, b, c, f, ml[maxn], ans = 0;
  init();
  memset(ml, 0, sizeof(ml));
  scanf("%d%d", &n, &m);
  int S = 0, T = n + 1;
  while (m--) {
    scanf("%d%d%d%d", &a, &b, &c, &f);
    if (c < f) {
      mincost += f - c;
      ml[a] += f, ml[b] -= f;
      add_edge(b, a, f - c, 0), add_edge(b, a, c, 1), add_edge(a, b, INF, 2);
    } else {
      ml[a] += f, ml[b] -= f;
      add_edge(a, b, c - f, 1), add_edge(a, b, INF, 2), add_edge(b, a, f, 1);
    }
  }
  add_edge(n, 1, INF, 0);
  for (int i = 1; i <= n; i++) {
    if (ml[i] >= 0) {
      add_edge(i, T, ml[i], 0);
    } else {
      add_edge(S, i, -ml[i], 0);
    }
  }
  MCMF(S, T);
  cout << mincost << endl;
}

```