#include <bits/stdc++.h>
#define eb emplace_back
#define INF (0x3f3f3f3f)
using namespace std;
void fuk() { puts("-1"); exit(0); }

const int MAXN = 755;

bitset<MAXN> dp;

vector<int> G[MAXN];
bitset<MAXN> T[MAXN], chk, col;

int N, M, Ans = INF;

void f(int i, int &a, int &b) {
	chk[i] = true; a++;
	for(int v : G[i]) {
		if(chk[v]) {
			if(col[i] == col[v]) fuk();
			continue;
		}
		col[v] = !col[i];
		f(v, b, a);
	}
}

int main() {
	ios::sync_with_stdio(false);

	cin >> N >> M;
	for(int i = 0, a, b; i < M; i++) {
		cin >> a >> b;
		T[a][b] = T[b][a] = true;
	}
	for(int i = 1; i <= N; i++) {
		T[i][i] = true;
		for(int j = 1; j <= N; j++)
			if(!T[i][j]) G[i].eb(j);
	}

	dp[0] = true;
	for(int i = 1; i <= N; i++) if(!chk[i]) {
		int a = 0, b = 0;
		f(i, a, b);
		dp = (dp << a) | (dp << b);
	}

	for(int i = 0; i <= N; i++) if(dp[i]) {
		int t = i*(i-1) + (N-i)*(N-i-1);
		t >>= 1;
		if(t < Ans) Ans = t;
	}

	cout << Ans << endl;
	return 0;
}