#include<bits/stdc++.h>
using namespace std;

#define mem(t, v)   memset ((t) , v, sizeof(t))
#define all(x)      x.begin(),x.end()
#define un(x)       x.erase(unique(all(x)), x.end())
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sl(n)       scanf("%lld", &n)
#define sll(a,b)    scanf("%lld %lld", &a, &b)
#define slll(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define D(x)        cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define DD(x,y)     cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << '\n'
#define DDD(x,y,z)  cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << '\n'
#define DBG         cerr << __LINE__ << ": Hi" << '\n'
#define pb          push_back
#define PI          acos(-1.00)
#define xx          first
#define yy          second
#define eps         1e-9

typedef unsigned long long int ULL;
typedef long long int LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;


inline int setBit(int N, int pos) { return N=N | (1<<pos); }
inline int resetBit(int N, int pos) { return N= N & ~(1<<pos); }
inline bool checkBit(int N, int pos) { return (bool)(N & (1<<pos)); }

//int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
//int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; //Four & Eight Direction
#define MAX         700
int n, m;
int vis[MAX+10];
vector<pii>A;
vector<int>E[MAX+10];
bool bfs(int source)
{
    int nodes[3] = {0};
    queue<int>Q;
    Q.push(source);
    vis[source] = 1;
    nodes[1]++;
    while(!Q.empty())
    {
        int u = Q.front();
        Q.pop();
        for(auto v: E[u])
        {
            if(vis[v] && (vis[v] == vis[u]))
                return false;
            else if(vis[v] == 0)
            {
                if(vis[u] == 1)
                    vis[v] = 2;
                else
                    vis[v] = 1;
                Q.push(v);
                nodes[vis[v]]++;
            }
        }
    }
    A.pb({nodes[1], nodes[2]});
    return true;
}

bool build()
{
    for(int i = 1; i<=n; i++)
    {
        if(!vis[i])
        {
            if(bfs(i) == false)
                return false;
        }
    }
    return true;
}

bool d[MAX+10][MAX+10];

LL dp[MAX+10][MAX+10];

LL call(int pos, int f)
{
    if(pos == A.size())
    {
        int s = n - f;
//        DD(f, s);
        return (f*(f-1))/2 + (s*(s-1))/2;
    }
    LL &ret = dp[pos][f];
    if(ret != -1)
        return ret;
    ret = min(call(pos+1, f+A[pos].xx), call(pos+1, f+A[pos].yy));
    return ret;
}

int main()
{
//    freopen("maxon.txt","r",stdin);
    //freopen("out.txt","w",stdout);
//    D(pow(700,3));
    sff(n,m);
    int u, v;
    mem(dp, -1);
    for(int i= 1; i<=m; i++)
    {
        sff(u,v);
        d[u][v] = d[v][u] = 1;
    }
    for(int i = 1; i<=n; i++)
    {
        for(int j = i+1; j<=n; j++)
        {
            if(d[i][j] == 0)
                E[i].pb(j), E[j].pb(i);
        }
    }
    if(build()==false)
    {
        puts("-1");
        return 0;
    }
//    DD(A[0].xx, A[0].yy);
//    D(A.size());
    cout << call(0, 0) << endl;
    return 0;
}




Measured memory_bytes: 7168