Dream Team
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Summer training is coming soon, and in order to achieve good results in the upcoming contests, everyone wants to find their favorite teammates to form their own dream team!

There are 3n students in the training team with corresponding numbers 1 to 3n , and they will form n teams, each consisting of 3 students . It is now known that there are m pairs of students (x_i, y_i) who are directly familiar with each other (i.e. x_i is directly familiar with y_i , and y_i is directly familiar with x_i ) .

Friends of friends are friends. We define that student a is familiar with student b if one of the following conditions is met:
1. a is directly familiar with b , or
2. There exists a series of students x_1,x_2,\dots, x_k\ (k > 0) satisfies:
  • a is directly familiar with x_1
  • For all 1\le i< k , x_i is directly familiar with x_{i+1}
  • x_k is directly familiar with b
As a retired contestant, Colin clearly knows that it is important for teammates to be familiar with each other. We define a student's anxiety level as the number of students in his team that he is not familiar with (of course everyone is familiar with himself) . Now Colin wants you to find a plan satisfies: divide all 3n students into n teams, and each student is in exactly one team, and each team has exactly 3 students, and minimize the sum of anxiety level of all 3n students.

You only need to tell Colin the minimum sum of anxiety level of all 3n students.

输入描述:

The first line contains two integers n, m\text{ }(1\le n\le 10^6,1\le m\le 2\times 10^5) , representing there are 3n students and m pairs of students directly familiar with each other.
For the following m lines, each line contains two integers x_i, y_i\ (1 \le x_i,y_i \le 3\times n, x_i \ne y_i) , representing x_i, y_i are directly familiar with each other.

输出描述:

A single integer, represents the minimum sum of anxiety level of all 3n students.
示例1

输入

复制
3 5
1 2
1 3
4 5
4 6
7 8

输出

复制
4