#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 705
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int n,m,mp[maxn][maxn],cnt,vis[maxn],col[maxn],f;
int t[maxn][2],dp[maxn][maxn];

inline void dfs(int u)
{
	t[cnt][col[u]]++; vis[u]=1;
	for(int i=1;i<=n;i++)
	{
		if(i==u) continue;
		if(mp[u][i]==0&&vis[i]==0) col[i]=col[u]^1,dfs(i);
		else if(mp[u][i]==0&&col[i]==col[u]) {f=1; return;}
	}
}

inline int cal(int x,int y){return x*(x-1)/2+y*(y-1)/2;}

int main()
{
	n=read(); m=read();
	for(int i=1;i<=m;i++) {int u=read(),v=read(); mp[u][v]=mp[v][u]=1;}
	for(int i=1;i<=n;i++) if(!vis[i]) cnt++,dfs(i); dp[0][0]=1;
	for(int i=1;i<=cnt;i++)
	{
		for(int j=0;j<=n;j++)
		{
			dp[i][j+t[i][0]]|=dp[i-1][j];
			dp[i][j+t[i][1]]|=dp[i-1][j];
		}
	}
	int ans=inf;
	for(int i=1;i<=n;i++) if(dp[cnt][i]) ans=min(ans,cal(i,n-i));
	if(f==1) puts("-1"); else cout<<ans<<endl;
	return 0;
}