#include <bits/stdc++.h>

#define Cpy(a, b) memcpy(a, b, sizeof (a))
#define Set(a, b) memset(a, b, sizeof (a))
#define For(i, j, k) for (int i = j; i <= k; ++ i)
#define Forr(i, j, k) for (int i = j; i >= k; -- i)

using namespace std;

inline int read() {
	int x = 0, p = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') p = -1;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x * p;
}

inline void File() {
	freopen("e.in", "r", stdin);
	freopen("e.out", "w", stdout);
}

const int N = 700 + 5;

int G[N][N], n, m, col[N], c[2];

bitset<N << 1> F, T;

inline void dfs(int x, int nw) {
	++ c[col[x] = nw];
	For(v, 1, n) if (v ^ x && !G[v][x]) {
		if (col[v] == nw) { puts("-1"); exit(0); }
		if (col[v] == -1) dfs(v, nw ^ 1);
	}
}

int main() {

	n = read(), m = read();
	For(i, 1, m) {
		int x = read(), y = read();
		G[x][y] = G[y][x] = 1;
	}

	Set(col, -1); F.set(0); 

	For(i, 1, n) if (col[i] == -1) {
		Set(c, 0), dfs(i, 0);	
		T.reset();
		T = (F << c[0]) | (F << c[1]);
		F = T;
	}
	
	int ans = INT_MAX;
	For(i, 0, n) if (F.test(i)) ans = min(ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
	cout << ans << endl;

	return 0;
}
