#include <bits/stdc++.h>

using namespace std;

const int maxn = 710;
const int oo = 1e9;

int n,m,ed[maxn][maxn],c[3],vis[maxn],f[maxn],lab[maxn];

void visit(int u,int col) {
    vis[u]=1;
    c[col]++;
    lab[u]=col;
    for (int v=1;v<=n;v++) if (v!=u) {
        if (ed[u][v]) continue;
        if (vis[v] && lab[v]==lab[u]) {
            cout<<-1<<endl;
            exit(0);
        }
        if (!vis[v]) visit(v,col^1);
    }
}

int main() {
  //  freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    for (int i=1;i<=m;i++) {
        int a,b;
        cin>>a>>b;
        ed[a][b] = ed[b][a] = 1;
    }
    f[0]=1;
    for (int i=1;i<=n;i++)
        if (!vis[i]) {
            c[0] = c[1] = 0;
            visit(i,0);
            for (int j=n;j>=0;j--) {
                int tmp=0;
                if (j>=c[0]) tmp |= f[j-c[0]];
                if (j>=c[1]) tmp |= f[j-c[1]];
                f[j] = tmp;
            }
        }
    int ans = oo;
    for (int i=0;i<=n;i++)
        if (f[i]) ans = min(ans,i*(i-1)/2 + (n-i)*(n-i-1)/2);
    cout<<ans;
}
