#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000000 int main(){ int N,M; cin>>N>>M; dsu D(2*N); rep(i,M){ int r,c; scanf("%d %d",&r,&c); r--;c--; D.merge(r,N+c); } auto g = D.groups(); vector x(g.size(),0),y(g.size(),0); rep(i,g.size()){ rep(j,g[i].size()){ if(g[i][j] B; B[0] = 1; rep(i,x.size()){ B |= B << (x[i]*5001 + y[i]); } rep(i,B.size()){ int x = i%5001,y = i/5001; if(B[i]){ ans = min(ans,x*y + (N-x)*(N-y) - M); } } cout<