#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
using namespace std;

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))

struct UnionFind
{
    vector< int > data;
    
    UnionFind(int sz)
    {
        data.assign(sz, -1);
    }
    
    bool unite(int x, int y)
    {
        x = find(x), y = find(y);
        if(x == y) return(false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return(true);
    }
    
    int find(int k)
    {
        if(data[k] < 0) return(k);
        return(data[k] = find(data[k]));
    }
    
    int size(int k)
    {
        return(-data[find(k)]);
    }
};

struct Bipartite_Graph : UnionFind
{
    vector< int > color;
    
    Bipartite_Graph(int v) : color(v + v, -1), UnionFind(v + v) {}
    
    bool bipartite_graph_coloring()
    {
        for(int i = 0; i < color.size() / 2; i++) {
            int a = find(i);
            int b = find(i + (int) color.size() / 2);
            if(a == b) return (false);
            if(color[a] < 0) color[a] = 0, color[b] = 1;
        }
        return (true);
    }
    
    bool operator[](int k)
    {
        return (bool(color[find(k)]));
    }
};

int N;
vector<pair<int, int>> continuities;

int dp[1000][1000];

int choose(int now, int sum){
    if(now == continuities.size()){
        return sum * (sum - 1) / 2 + (N - sum) * (N - sum - 1) / 2;
    }else if(dp[now][sum] != -1){
        return dp[now][sum];
    }else{
        return dp[now][sum] = min(choose(now + 1, sum + continuities[now].first), choose(now + 1, sum + continuities[now].second));
    }
}

int main(){
    int M;
    cin >> N >> M;
    vector<vector<bool>> roads(N, vector<bool>(N, false));
    for(int i = 0; i < M; i++){
        int A, B;
        cin >> A >> B;
        roads[A - 1][B - 1] = true;
        roads[B - 1][A - 1] = true;
    }
    UnionFind uf(N);
    Bipartite_Graph bg(N);
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(!roads[i][j] && i != j){
                uf.unite(i, j);
                bg.unite(i, j + N);
                bg.unite(i + N, j);
            }
        }
    }
    if(!bg.bipartite_graph_coloring()){
        cout << -1 << endl;
        return 0;
    }
    vector<bool> is_came(N, false);
    for(int i = 0; i < N; i++){
        if(is_came[i]){
            continue;
        }
        pair<int, int> this_white = {0, 0};
        for(int j = 0; j < N; j++){
            if(uf.find(i) == uf.find(j)){
                if(bg[j]){
                    this_white.first++;
                }else{
                    this_white.second++;
                }
                is_came[j] = true;
            }
        }
        continuities.push_back(this_white);
    }
    memset(dp, -1, sizeof(dp));
    cout << choose(0, 0) << endl;
}


Measured memory_bytes: 4352