#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int,int>P;

class UnionFind {
	vector<int>par, sz;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (sz[x] > sz[y]) {
			par[y] = x;
			sz[x] += sz[y];
		}
		else {
			par[x] = y;
			sz[y] += sz[x];
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};
int cnt[2000][2];
bitset<2000>dp;
int main(){
	int n,m;scanf("%d%d",&n,&m);
	set<P>se;
	rep(i,m){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		if(a>b)swap(a,b);
		se.insert(P(a,b));
	}
	UnionFind uf(n*2);
	rep(i,n)for(int j=i+1;j<n;j++){
		if(!se.count(P(i,j))){
			uf.unite(i,j+n);
			uf.unite(i+n,j);
		}
	}
	rep(i,2*n){
		if(i<n&&uf.same(i,n+i)){
			puts("-1");return 0;
		}
		cnt[uf.find(i)][i>=n]++;
	}
	dp[0]=1;
	rep(i,n){
		if(uf.find(i)==i){
			dp=dp<<cnt[i][0]|dp<<cnt[i][1];
		}
	}
	int Min=INT_MAX;
	rep(i,n+1){
		if(dp[i]){
			Min=min(Min,i*(i-1)/2+(n-i)*(n-i-1)/2);
		}
	}
	cout<<Min<<endl;
}