#include <bits/stdc++.h>
using namespace std;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n, m, sz, G[705][705];
int col[705], cnt[705][2];
bool mrk[705], f[2][705];
bool DFS(int u) {
	mrk[u] = true, cnt[sz][0] += !col[u], cnt[sz][1] += col[u];
	for (int v = 1; v <= n; v++) if (G[u][v]) {
		if (mrk[v] && col[u] == col[v]) return false;
		if (!mrk[v]) {col[v] = col[u]^1; if (!DFS(v)) return false;}
	}
	return true;
}
int main() {
	read(n), read(m), memset(G, true, sizeof G);
	for (int i = 1; i <= n; i++) G[i][i] = false;
	for (int i = 1, u, v; i <= m; i++)
		read(u), read(v), G[u][v] = G[v][u] = false;
	for (int i = 1; i <= n; i++) if (!mrk[i])
		{sz++; if (!DFS(i)) return puts("-1"), 0;}
	f[0][0] = true;
	for (int i = 1, c = 1; i <= sz; i++, c ^= 1) {
		memset(f[c], false, sizeof f[c]);
		for (int j = 0; j <= n; j++)
			f[c][j+cnt[i][0]] |= f[c^1][j], 
			f[c][j+cnt[i][1]] |= f[c^1][j];
	}
	int mi = 0x3f3f3f3f;
	for (int i = 0; i <= n; i++) if (f[sz&1][i])
		mi = min(mi, i*(i-1)/2+(n-i)*(n-i-1)/2);
	return printf("%d\n", mi), 0;
}
