#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
    long long x;
public:
    mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
    mint operator-() const {
        return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res *= a;
    }

    mint operator^(const ll& t)const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream& operator<<(ostream& os, const mint& m) {
        os << m.x;
        return os;
    }
};

//////////////////////////


int main() {
    ll N, M;
    cin >> N>>M;
    vector<vector<ll>> gmat(N + 1, vector<ll>(N + 1, 0));

    repn(i, M) {
        ll a, b;
        cin >> a >> b;
        gmat[a][b] = 1;
        gmat[b][a] = 1;
    }
    repn(i, N) gmat[i][i] = 1;

    vector<vector<ll>> g(N + 1);
   
    repn(i, N)repn(j, N) {
        if (gmat[i][j] == 0) {
            //cout << i << j << endl;
            g[i].push_back(j);
        }
    }

    vector<ll> col(N + 1, -1);
    vector<ll> zero;
    vector<ll> one;
    ll b = 1;

    repn(v, N) {
        if (col[v] != -1) { continue; }

        col[v] = 0;
        ll num[2] = { 1,0 };
        queue<ll> q;
        q.push(v);

        while (!q.empty()) {
            ll w = q.front();
            q.pop();
            ll i = (col[w] + 1) % 2;
            for (ll u : g[w]) {
                if (col[u] == -1) {
                    col[u] = i;
                    num[i]++;
                    q.push(u);
                }
                else {
                    if (col[u] != i) { b = 0;}
                }
            }
        }

        zero.push_back(num[0]);
        one.push_back(num[1]);
        
    }

    if (b == 0) { cout << -1; }
    else {
        ll M = zero.size();
        vector<vector<ll>> dp(M + 1, vector<ll>(N + 1, 0));
        dp[0][0] = 1;
        
        repn(i, M)repn(j, N) {
            if (j >= zero[i - 1] && dp[i - 1][j - zero[i - 1]] == 1) { dp[i][j] = 1; }
            if (j >= one[i - 1] && dp[i - 1][j - one[i - 1]] == 1) { dp[i][j] = 1; }
        }

        ll ans = INF;

        rep(i, N+1) {
            if (dp[M][i] == 1) {
                ans = min(i * (i - 1) / 2 + (N - i) * (N - i - 1) / 2, ans);
            }
        }

        cout << ans;
    }


	system("PAUSE");
}

Measured memory_bytes: 9976