#include <stdio.h>
#include <algorithm>
using namespace std;
bool mp[701][701];
int n,siz[2][701],cnt,clr[701];
bool dfs(int k,int curc)
{
    clr[k]=curc;
    ++siz[curc-1][cnt];
    for (int i=1;i<=n;++i)
        if (mp[k][i])
        {
            if (!clr[i])
            {
                if (!dfs(i,3-curc))
                    return false;
            }
            else if (clr[i]==curc)
                return false;
        }
    return true;
}
bool dp[701][701];
int main()
{
    int m;
    scanf("%d%d",&n,&m);
    for (int i=1;i<n;++i)
        for (int j=i+1;j<=n;++j)
            mp[i][j]=mp[j][i]=true;
    for (int i=1;i<=m;++i)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        mp[a][b]=mp[b][a]=false;
    }
    for (int i=1;i<=n;++i)
        if (!clr[i])
        {
            ++cnt;
            if (!dfs(i,1))
            {
                printf("-1");
                return 0;
            }
        }
    dp[0][0]=1;
    for (int i=0;i<cnt;++i)
        for (int j=0;j<=n;++j)
            if (dp[i][j])
            {
                dp[i+1][j+siz[0][i+1]]=true;
                dp[i+1][j+siz[1][i+1]]=true;
            }
    int ans=1000000000;
    for (int i=0;i<=n;++i)
        if (dp[cnt][i])
            ans=min(ans,i*(i-1)/2+(n-i)*(n-i-1)/2);
    printf("%d\n",ans);
    return 0;
}
