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

#define MX 705
bool mat[MX][MX];
vector<int> g[MX];
int c1, c2, col[MX];
bool flag[MX], tmp[MX];

bool dfs(int u) {
	col[u] == 1 ? c1++ : c2++;
	for(auto v : g[u]) {
		if(!col[v]) {
			col[v] = 3 - col[u];
			if(!dfs(v)) return false;
		}
		else if(col[v] == col[u]) return false;
	}
	return true;
}

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	while(m--) {
		int u, v; scanf("%d%d", &u, &v);
		mat[u][v] = mat[v][u] = true;
	}
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			if(i != j && !mat[i][j]) g[i].push_back(j);
	int cnt = 0;
	flag[0] = true;
	for(int i = 1; i <= n; i++) {
		if(col[i]) continue;
		col[i] = 1; c1 = c2 = 0;
		if(!dfs(i)) {
			puts("-1");
			return 0;
		}
		memcpy(tmp, flag, sizeof tmp);
		memset(flag, 0, sizeof flag);
		for(int j = 0; j <= n; j++)
			if(tmp[j]) {
				flag[j + c1] = flag[j + c2] = true;
			}
	}
	int res = INT_MAX;
	for(int i = 0; i <= n; i++) if(flag[i]) res = min(res, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
	printf("%d\n", res);
	return 0;
}
