// ===== 2018/06/30 00:39:26 =====

// ../../../lib/template/includes.hpp

#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <vector>

// ../../../lib/template/const_value.hpp

namespace sub {
template <typename T>
constexpr typename std::enable_if<std::is_integral<T>::value, T>::type
inf_sub() {
  return std::numeric_limits<T>::max() / 2 - 1000;
}

template <typename T>
constexpr typename std::enable_if<std::is_floating_point<T>::value, T>::type
inf_sub() {
  return std::min(std::numeric_limits<T>::max() / 2 - 1000, T(1e50));
}
}  // namespace sub

template <typename T> constexpr T inf() {
  static_assert(std::is_arithmetic<T>::value, "T must be arithmetic value");
  return sub::inf_sub<T>();
}

template <typename T> constexpr T zero() {
  static_assert(std::is_arithmetic<T>::value, "T must be arithmetic value");
  return T(0);
}

const long double pi = acos(-1.0);

// ../../../lib/template/initialize.cpp

struct yes_no : std::numpunct<char> {
  string_type do_truename() const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

struct Initialize {
  Initialize() {
    std::locale loc(std::locale(), new yes_no);
    std::cout << std::boolalpha << std::setprecision(11) << std::fixed;
    std::cout.imbue(loc);
  }
};

const Initialize initialize;

// ../../../lib/template/macros.hpp

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

// ../../../lib/template/misc.hpp

template <typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }

template <typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }

// ../../../lib/template/range.hpp

class range {
  class index_type {
    int x;

  public:
    index_type(int x_) : x(x_) {}
    int operator*() const { return x; }
    bool operator!=(index_type &r) { return x < r.x; }
    void operator++() { ++x; }
  };
  index_type i, n;

public:
  range(int n_) : i(0), n(n_) {}
  range(int i_, int n_) : i(i_), n(n_) {}
  index_type &begin() { return i; }
  index_type &end() { return n; }
};

// ../../../lib/template/typedef.hpp

using ll = long long;
using ld = long double;

// ../../../lib/template/template.cpp

using namespace std;

// ../../../lib/template/cout.cpp

template <typename T, int M, int N> struct tuple_printer {
  static void print(std::ostream &os, const T &x) {
    os << std::get<M>(x) << " ";
    tuple_printer<T, M + 1, N>::print(os, x);
  }
};

template <typename T, int N> struct tuple_printer<T, N, N> {
  static void print(std::ostream &os, const T &x) { os << std::get<N>(x); }
};

template <typename... Args>
std::ostream &operator<<(std::ostream &os, const std::tuple<Args...> &t) {
  tuple_printer<std::tuple<Args...>, 0, sizeof...(Args) - 1>::print(os, t);
  return os;
}

template <typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << " ";
    os << *it;
  }
  return os;
}

template <typename T>
std::ostream &operator<<(std::ostream &os, const std::set<T> &v) {
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << " ";
    os << *it;
  }
  return os;
}

// ../../../lib/structure/unionfind.cpp

class UnionFind {
  std::vector<int> p;

public:
  UnionFind(int n) : p(n, -1) {}

  int root(int x) { return p[x] < 0 ? x : p[x] = root(p[x]); }

  bool same(int x, int y) { return root(x) == root(y); }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (p[y] < p[x]) std::swap(x, y);
    if (p[x] == p[y]) --p[x];
    p[y] = x;
    return true;
  }
};

// E.cpp

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

int e[700][700];
bool visited[700];

int dfs(int v, int c, int N) {
  if (visited[v]) return 0;
  visited[v] = true;
  int res = 0;
  REP(w,N) {
    if (e[v][w] == 0) res += dfs(w, 1 - c, N);
  }
  if (c == 0) ++res;
  return res;
}

void solve(ll N, ll M, vector<ll> A, vector<ll> B) {
  UnionFind uf(N * 2);
  REP(i,M) {
    --A[i]; --B[i];
    e[A[i]][B[i]] = 1;
    e[B[i]][A[i]] = 1;
  }
  REP(i,N) REP(j,i) {
    if (e[i][j] == 0) {
      uf.unite(i * 2 + 0, j * 2 + 1);
      uf.unite(i * 2 + 1, j * 2 + 0);
    }
  }
  REP(i,N) {
    if (uf.root(i * 2 + 0) == uf.root(i * 2 + 1)) {
      cout << -1 << endl;
      return;
    }
  }
  set<int> roots;
  vector<int> cnt(N * 2);
  REP(i,2*N) {
    int r = uf.root(i);
    roots.insert(r);
    ++cnt[r];
  }
  vector<int> dp(720);
  dp[0] = 1;
  while (!roots.empty()) {
    int r1 = *roots.begin();
    roots.erase(r1);
    int r2 = uf.root(r1 ^ 1);
    roots.erase(r2);
    int sum = cnt[r1];
    int c1 = dfs(r1 / 2, 0, N);
    int c2 = sum - c1;
    vector<int> dp2(720);
    for (int i = 700; i >= 0; --i) {
      if (dp[i]) {
        dp2[i + c1] = 1;
        dp2[i + c2] = 1;
      }
    }
    dp = move(dp2);
  }
  ll res = 1e9;
  REP(i,N+1) {
    if (dp[i]) chmin(res, i * (i - 1) / 2 + (N - i) * (N - i - 1) / 2);
  }
  cout << res << endl;
}

int main() {
	ll M;
	ll N;
	scanf("%lld", &N);
	scanf("%lld", &M);
	vector<ll> B(M-1+1);
	vector<ll> A(M-1+1);
	for (int i = 0 ; i <= M-1 ; i++) {
	  scanf("%lld", &A[i]);
	  scanf("%lld", &B[i]);
	}
	solve(N, M, A, B);
	return 0;
}
// ===== 2018/06/30 00:39:26 =====



Measured memory_bytes: 9856