#include <cstdio>
#include <bitset>
using namespace std;
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
bitset<1008> f;
int e[702][702], vis[702], q[702], cnt[3];
int main(){
	register int n, m, i, j, u, v, qh, qt, ans;
	scanf("%d %d", &n, &m);
	for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) if (i != j) e[i][j] = 1;
	for (i = 1; i <= m; ++i) {
		scanf("%d %d", &u, &v);
		e[u][v] = e[v][u] = 0;
	}
	f.set(0);
	for (i = 1; i <= n; ++i) if (vis[i] == 0) {
		q[qh = qt = 0] = i;
		vis[i] = 1;
		cnt[1] = cnt[2] = 0;
		while (qh <= qt) {
			u = q[qh];
			++qh;
			++cnt[vis[u]];
			for (v = 1; v <= n; ++v) if (e[u][v]) {
				if (vis[v]) {
					if ((vis[u] ^ vis[v]) != 3) {
						puts("-1");
						return 0;
					}
				}
				else {
					vis[v] = vis[u] ^ 3;
					q[++qt] = v;
				}
			}
		}
		f = f << cnt[1] | f << cnt[2];
	}
	ans = n * n;
	for (i = 1; i <= n; ++i) if (f[i]) {
		cmin(ans, i * (i - 1) + (n - i) * (n - i - 1) >> 1);
	}
	printf("%d", ans);
	return 0;
}