#include <bits/stdc++.h>
// #include "ane.cpp"

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 705;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
// #define DEBUG

// frequently used macros

#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif

#define fi first
#define se second

#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> lp;
typedef pair<ll, ll> llp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// frequently used structs
struct edge{
  int to,cost;
};

// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
  va_list arg;
  va_start(arg, format);
  vprintf(format, arg);
  va_end(arg);
}
#endif

// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{       \
  printf("%s: ", #v);         \
  for (int i = 0; i < (c); ++i) \
  {                           \
  cout << (v)[i] << " ";      \
  }                           \
  cout << endl;               \
} while(0)
#else
#define DUMPV(v,c)
#endif

// std::fill of multi dimensions
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
  std::fill( reinterpret_cast<T*>(array),
             reinterpret_cast<T*>(array+N),
             val );
}

// binary search
ll BSearch(ll ok, ll ng, bool (*f)(ll)){
  ll mid;
  while(abs(ok - ng) > 1LL) {
    mid =  (ok + ng) / 2LL;
    if(f(mid)) {
      debug("BSearch: f(%d) == true\n", mid);
      ok = mid;
    }
    else
    {
      debug("BSearch: f(%d) == false\n", mid);
      ng = mid;
    }
  }
  return ok;
}

ll NUM_TEST_CASE = 1;

ll N,M,K,A,B,C,D,E;
unordered_set<int> G[NMAX];
vec Gdash[NMAX];
vector<p> island_vertices;

string S;
vec v;

ll ans = {};

p dp[NMAX][NMAX];

p taka_dfs(int m, int i, int tak, int has){
  debug("taka_dfs(%d, %d, %d, %d)\n", m, i, tak, has);
  if(i >= m) return {tak, has};
  if(dp[i][tak] != p{-1, -1}) return dp[i][tak];
  if(dp[i][has] != p{-1, -1}) return dp[i][has];
  p used = taka_dfs(m, i + 1,
              tak + island_vertices[i].fi, has + island_vertices[i].se);
  p unused = taka_dfs(m, i + 1,
              tak + island_vertices[i].se, has + island_vertices[i].fi);
  int diff_used = abs(used.fi - used.se);
  int diff_unused = abs(unused.fi - unused.se);
  return dp[i][tak] = (diff_used <= diff_unused ? used : unused);
}

int col[NMAX];
pair<bool, p>
paint_dfs(int i, int color){
  debug("paint_dfs(%d, %d)\n", i, color);
  col[i] = color;
  int taka = 0, hashi = 0;
  if(color == 0) {
    taka = 1;
  }
  else {
    hashi = 1;
  }
  for (int j : Gdash[i])
  {
    if(col[j] == col[i])
      return {false, {-1, -1}};
    if(col[j] == -1){
      auto ret = paint_dfs(j, !color);
      if(!ret.fi) return ret;
      else{
        taka += ret.se.fi;
        hashi += ret.se.se;
      }
    }
  }
  return {true, {taka, hashi}};
}
void solve(){
  // main algorithm
  // make Gdash
  for (int i = 1; i <= N; ++i)
  {
    for (int j = 1; j <= N; ++j)
    {
      if (i != j && G[i].count(j) == 0)
      {
        Gdash[i].push_back(j);
      }
    }
  }

  // paint digraph
  Fill(col, -1);
  for (int i = 1; i <= N; ++i)
  {
    if(col[i] != -1) continue;
    debug("paint(%d)\n", i);
    auto ret = paint_dfs(i,0);
    DUMP(ret.fi);
    DUMP(ret.se.fi);
    DUMP(ret.se.se);
    if(!ret.fi){
      ans = -1;
      return;
    }
    island_vertices.push_back(ret.se);
  }

  // unit test
  // island_vertices = {1,1,2,1};
  // calc min composition
  // sort(ALL(island_vertices), greater<int>());
  Fill(dp, p{-1, -1});
  p taka_hashi = taka_dfs(island_vertices.size(), 0, 0, 0);
  int taka = taka_hashi.fi;
  int hashi = taka_hashi.se;
  ans = taka * (taka - 1) / 2 + hashi * (hashi - 1) / 2;
  DUMP(taka);
  DUMP(hashi);
}
void debug(){
  // output debug information
  cout << "Gdash:\n";
  for (int i = 1; i <= N; ++i)
  {
    cout << i << ": ";
    for(auto&& j : Gdash[i]) {
      cout << j << " ";
    }
    cout << endl;
  }
  cout << endl;
  cout << "island_vertices:\n";
  for(auto&& p : island_vertices) {
    printf("{%d, %d} ", p.fi, p.se);
  }
  cout << endl;
  cout << "col:\n";
  for (int i = 1; i <= N; ++i)
  {
    cout << col[i] << " ";
  }
  cout << endl;
}
void answer(){
  // output answer
  cout << ans << endl;
}
void init(){
  // initialize for each test case
  // Fill(dp, -1);
}
int main(int argc, char const *argv[])
{
  // operate inputs

  // cin >> NUM_TEST_CASE;

  for (int test_case = 0; test_case < NUM_TEST_CASE; ++test_case)
  {
    init();

    cin >> N >> M;
    for (int i = 0; i < M; ++i)
    {
      int a,b;
      scanf("%d%d", &a,&b);
      G[a].insert(b);
      G[b].insert(a);
    }
    solve();
    #ifdef DEBUG
    debug();
    #endif
    answer();
  }

  return 0;
}

Measured memory_bytes: 24064