#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e3 + 20;
vector<int> adj[maxx];
pair<int, int> e[maxx];
int match[maxx], dp[maxx], q[maxx], dm[maxx], n, m, deg[maxx], ans = 3 * maxx,
                                                               toghe[maxx];
bool vis[maxx];
bool dfs(int root) {
  vis[root] = true;
  for (int x : adj[root])
    if (match[x] == -1 || (!vis[match[x]] && dfs(match[x])))
      return match[x] = root, match[root] = x, true;
  return false;
}
int center(int x) {
  for (int i = 0; i < maxx; i++) adj[i].clear();
  for (int i = 0; i < m; i++)
    if (e[i].first != x && e[i].second != x)
      adj[e[i].first].push_back(e[i].second + n);
  fill(match, match + maxx, -1);
  int t = 0;
  for (int i = 0; i < n; i++) {
    if (i == x) continue;
    fill(vis, vis + maxx, false);
    t += dfs(i);
  }
  return n + n + n - 2 - t - t + m - q[x] - q[x];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    if (u == v)
      toghe[u] = 1, q[u]++;
    else
      dp[u]++, dm[v]++, q[u]++, q[v]++;
    e[i] = {u, v};
  }
  for (int i = 0; i < n; i++) ans = min(ans, center(i));
  cout << ans << endl;
  return 0;
}

### Prompt

Construct a cpp code solution to the problem outlined:

George loves graphs. Most of all, he loves interesting graphs. We will assume that a directed graph is interesting, if it meets the following criteria: 

  * The graph doesn't contain any multiple arcs; 
  * There is vertex v (we'll call her the center), such that for any vertex of graph u, the graph contains arcs (u, v) and (v, u). Please note that the graph also contains loop (v, v). 
  * The outdegree of all vertexes except for the center equals two and the indegree of all vertexes except for the center equals two. The outdegree of vertex u is the number of arcs that go out of u, the indegree of vertex u is the number of arcs that go in u. Please note that the graph can contain loops. 



However, not everything's that simple. George got a directed graph of n vertices and m arcs as a present. The graph didn't have any multiple arcs. As George loves interesting graphs, he wants to slightly alter the presented graph and transform it into an interesting one. In one alteration he can either remove an arbitrary existing arc from the graph or add an arbitrary arc to the graph. 

George wonders: what is the minimum number of changes that he needs to obtain an interesting graph from the graph he's got as a present? Help George and find the answer to the question.

Input

The first line contains two space-separated integers n and m (2 ≤ n ≤ 500, 1 ≤ m ≤ 1000) — the number of vertices and arcs in the presented graph.

Each of the next m lines contains two space-separated integers ai, bi (1 ≤ ai, bi ≤ n) — the descriptions of the graph's arcs. Pair (ai, bi) means that the graph contains an arc from vertex number ai to vertex number bi. It is guaranteed that the presented graph doesn't contain multiple arcs.

Assume that the grah vertices are numbered 1 through n.

Output

Print a single integer — the answer to George's question.

Examples

Input

3 7
1 1
2 2
3 1
1 3
3 2
2 3
3 3


Output

0


Input

3 6
1 1
2 2
3 1
3 2
2 3
3 3


Output

1


Input

3 1
2 2


Output

6

Note

For more information about directed graphs, please visit: http://en.wikipedia.org/wiki/Directed_graph

In the first sample the graph already is interesting, its center is vertex 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e3 + 20;
vector<int> adj[maxx];
pair<int, int> e[maxx];
int match[maxx], dp[maxx], q[maxx], dm[maxx], n, m, deg[maxx], ans = 3 * maxx,
                                                               toghe[maxx];
bool vis[maxx];
bool dfs(int root) {
  vis[root] = true;
  for (int x : adj[root])
    if (match[x] == -1 || (!vis[match[x]] && dfs(match[x])))
      return match[x] = root, match[root] = x, true;
  return false;
}
int center(int x) {
  for (int i = 0; i < maxx; i++) adj[i].clear();
  for (int i = 0; i < m; i++)
    if (e[i].first != x && e[i].second != x)
      adj[e[i].first].push_back(e[i].second + n);
  fill(match, match + maxx, -1);
  int t = 0;
  for (int i = 0; i < n; i++) {
    if (i == x) continue;
    fill(vis, vis + maxx, false);
    t += dfs(i);
  }
  return n + n + n - 2 - t - t + m - q[x] - q[x];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    if (u == v)
      toghe[u] = 1, q[u]++;
    else
      dp[u]++, dm[v]++, q[u]++, q[v]++;
    e[i] = {u, v};
  }
  for (int i = 0; i < n; i++) ans = min(ans, center(i));
  cout << ans << endl;
  return 0;
}

```