Anadi and Domino
Contest: Dasha Code Championship - SPb Finals Round (only for onsite-finalists)
Difficulty rating: 1700
Tags: brute force, graphs

Anadi has a set of dominoes. Every domino has two parts, and each part contains some dots. For every $$$a$$$ and $$$b$$$ such that $$$1 \leq a \leq b \leq 6$$$, there is exactly one domino with $$$a$$$ dots on one half and $$$b$$$ dots on the other half. The set contains exactly $$$21$$$ dominoes. Here is an exact illustration of his set:

Also, Anadi has an undirected graph without self-loops and multiple edges. He wants to choose some dominoes and place them on the edges of this graph. He can use at most one domino of each type. Each edge can fit at most one domino. It's not necessary to place a domino on each edge of the graph.

When placing a domino on an edge, he also chooses its direction. In other words, one half of any placed domino must be directed toward one of the endpoints of the edge and the other half must be directed toward the other endpoint. There's a catch: if there are multiple halves of dominoes directed toward the same vertex, each of these halves must contain the same number of dots.

How many dominoes at most can Anadi place on the edges of his graph?

Input format:
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 7$$$, $$$0 \leq m \leq \frac{n\cdot(n-1)}{2}$$$) — the number of vertices and the number of edges in the graph.

The next $$$m$$$ lines contain two integers each. Integers in the $$$i$$$-th line are $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a, b \leq n$$$, $$$a \neq b$$$) and denote that there is an edge which connects vertices $$$a_i$$$ and $$$b_i$$$.

The graph might be disconnected. It's however guaranteed that the graph doesn't contain any self-loops, and that there is at most one edge between any pair of vertices.

Output format:
Output one integer which denotes the maximum number of dominoes which Anadi can place on the edges of the graph.

Constraints:
Time limit: 2.0 s
Memory limit: 256.0 MB

Note:
Here is an illustration of Anadi's graph from the first sample test:

And here is one of the ways to place a domino on each of its edges:

Note that each vertex is faced by the halves of dominoes with the same number of dots. For instance, all halves directed toward vertex $$$1$$$ have three dots.

Example input:
4 4
1 2
2 3
3 4
4 1

Example output:
4

Example input:
7 0

Example output:
0

Editorial:
We can imagine writing an integer from $$$1$$$ to $$$6$$$ in each vertex — if we write an integer $$$x$$$ in vertex $$$v$$$, then we want each half of the domino directed toward vertex $$$v$$$ to have exactly $$$x$$$ dots. Then, it's easy to calculate the result — we should place as many different dominoes as possible according to the written numbers so that we won't place any domino multiple times.
If $$$n \leq 6$$$, then it's optimal to write different numbers everywhere, so the result will be equal to $$$m$$$ (the number of edges).
If $$$n=7$$$, then it's optimal to use only two equal numbers and it doesn't matter which number appears twice. Then, we can iterate over the pair of vertices with the same number and then easily calculate the result.