#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const double EPS  = 1e-10;
const bool debug = 0;
//-----------------------------------//

struct UnionFind {
	vector<int> par, rank;
	vector<int> cnt;
	
	UnionFind() {}
	UnionFind(int n) {
		par.resize(n);
		rank.resize(n);
		cnt.resize(n);
		REP(i, n) {
		 par[i] = i;
		 rank[i] = 0;
		 cnt[i] = 1;
		}
	}
	
	int operator[] (int x) {
		return find(x);
	}
	
	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);
	}
	
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		
		if (rank[x] < rank[y]) swap(x, y);
		
		par[y] = x;
		cnt[x] += cnt[y];
		if (rank[x] == rank[y]) rank[x]++;
	}
	
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	
	int size(int x) {
		return cnt[find(x)];
	}
	
};

vector<int> g[700];
int col[700];
int n;
UnionFind uf;
int N, M;
int rg[700][700];
int dp[701][701];

/*
動的に二部グラフを構築するやつ。
col[i] := -2:二部グラフではない, 0:塗られていない, 1or-1:色
*/


bool binary_color(int u, int c) {
	if (c != -2 && col[u] == -2) {
		binary_color(u, -2);
		return false;
	}
	col[u] = c;
	
	REP(i, g[u].size()) {
		int v = g[u][i];
		
		if (c == 0 || c == -2) {
			if (col[v] != c) binary_color(v, c);
		}
		else {
			if (col[v] == -c) continue;
			
			if (col[v] == c) return false;
			if (!binary_color(v, -c)) return false;
		}
	}
	return true;
}

void add_edge(int x, int y) {
	if (uf.same(x, y)) {
		if (col[x] != 0 && col[y] != 0 && col[x] == col[y]) col[x] = -2;
	}
	else {
		if (col[x] == 0 || col[x] == -2 || col[y] == 0 || col[y] == -2) {
			if (col[y] == 0 || col[y] == -2) swap(x, y);
		}
		else if (col[x] == col[y]) {
			if (uf.size(x) > uf.size(y)) swap(x, y);
			binary_color(x, 0);
		}
	}

	g[x].push_back(y);
	g[y].push_back(x);
	uf.unite(x, y);
	
	if (col[y] == 0) binary_color(y, 1);
	else binary_color(y, col[y]);
}

int main() {
	cin >> N >> M;
	uf = UnionFind(N);
	REP(i, M){
		int a, b;
		scanf("%d %d", &a, &b);
		a--; b--;
		rg[a][b] = rg[b][a] = true;
	}

	REP(i, N) REP(j, N) if (i != j && rg[i][j] == 0) add_edge(i, j);

	int cnt[2] = {}; // 1, -1

	REP(i, N) {
		if (col[i] == 1) cnt[0]++;
		else if (col[i] == -1) cnt[1]++;
		else if (col[i] == -2) {
			cout << -1 << endl;
			return 0;
		}
	}

	vector<pii> v;
	bool done[700] = {};
	int kori = 0;
	REP(i, N) if (!done[i]) {
		pii cur(1, 0);
		REP(j, N) if (i != j && uf.same(i, j)) {
			if (col[i] == col[j]) cur.fi++;
			else cur.se++;
			done[j] = true;
		}
		done[i] = true;
		v.push_back(cur);
	}

	dp[0][0] = 1;
	REP(i, v.size()) {
		REP(j, N) if (dp[i][j]) {
			dp[i + 1][j + v[i].fi] |= true;
			dp[i + 1][j + v[i].se] |= true;
		}
	}
	
	int ans = INF;
	REP(i, N + 1) if (dp[v.size()][i]) {
		int x = i;
		int y = N - i;
		int cx = max(0, x * (x - 1) / 2);
		int cy = max(0, y * (y - 1) / 2);
		chmin(ans, cx + cy);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 7424