#include <bits/stdc++.h>
#define nfs_mw ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
 
const int inf = 1e9;
 
int n,m,g[705][705],col[705],vis[705],num[705][705],bk,f[705][705];
 
void dfs(int x){
	vis[x] = 1;++ num[col[x]][bk];
	for(int i=1;i<=n;i++)
		if(i!=x && !g[x][i]){
			if(!vis[i])col[i] = col[x] ^ 1, dfs(i);
			else if(col[i] == col[x]){ puts("-1"); exit(0); }
		}
}
int c(int x,int y){return (x*(x-1) + y*(y-1)) / 2;}
 
int main(){
	nfs_mw;
	cin>>n>>m;
	
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		g[x][y] = g[y][x] = 1;
	}
	
	for(int i=1;i<=n;i++)
		if(!vis[i])++bk, dfs(i);
	
	f[0][0] = 1;
	for(int i=0;i<bk;i++) for(int j=0;j<=n;j++)
		f[i+1][j+num[0][i+1]] |= f[i][j],
		f[i+1][j+num[1][i+1]] |= f[i][j];
	
	int ans = 700*700*700;
	for(int i=n; i>=0; i--) if(f[bk][i]) ans = min(ans,c(i,n-i));
	printf("%d\n",ans);
 
	return 0;
}