#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n";
#define int long long
#define double long double

const int N=705;

int n, m, check=1, ans2=1e9;
int ct0=0, ct1=0;
int col[N], vis[N], vis2[N][N], g[N][N];
vector<pair<int, int> > v;

void dfs(int k, int c)
{
	if(vis[k])
	{
		if(col[k]!=c)
		{
			check=0;
		}
		return;
	}
	vis[k]=1;
	ct0+=(c==0);
	ct1+=(c==1);
	col[k]=c;
	for(int i=1;i<=n;i++)
	{
		if(i!=k && g[k][i])
			dfs(i, c^1);
	}
}

void dfs2(int i, int taken)
{
	if(i==v.size())
	{
		ans2=min(ans2, (taken*(taken-1)/2) + ((n-taken)*(n-taken-1)/2));
		return;
	}
	if(vis2[i][taken])
		return;
	vis2[i][taken]=1;
	dfs2(i+1, taken+v[i].first);
	dfs2(i+1, taken+v[i].second);
}

int32_t main()
{
	IOS;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int u, v;
		cin>>u>>v;
		g[u][v]=1;
		g[v][u]=1;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			g[i][j]=!g[i][j];
		}
	}
	int call=0;
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(vis[i])
			continue;
		call++;
		ct0=0;
		ct1=0;
		dfs(i, 0);
		v.push_back({ct0, ct1});
	}
	if(check==0)
	{
		cout<<"-1";
		return 0;
	}
	dfs2(0, 0);
	cout<<ans2;
}