package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	m := getNextInt(scanner)
	ee := makeGrid(n, n)
	for i := 0; i < m; i++ {
		a := getNextInt(scanner) - 1
		b := getNextInt(scanner) - 1
		ee[a][b] = 1
		ee[b][a] = 1
	}
	g := newGraph(n)

	id := 0
	for i := 0; i < n; i++ {
		for j := 0; j < i; j++ {
			if ee[i][j] == 1 {
				continue
			}
			g.appendEdge(i, j, id)
			g.appendEdge(j, i, id)
			id++
		}
	}
	group := 0
	for i := 0; i < n; i++ {
		if g.v[i].color == 0 {
			g.dfs(i, 1, group)
			group++
		}
	}
	cnt := makeGrid(group, 3)
	for i := 0; i < n; i++ {
		if g.v[i].invalid {
			fmt.Fprintln(writer, -1)
			return
		}
		cnt[g.v[i].group][g.v[i].color]++
	}

	b := newBint(0)
	geta := 1000
	b.x.SetBit(b.x, geta, 1)
	for i := 0; i < group; i++ {
		shift := cnt[i][1] - cnt[i][2]
		if cnt[i][1] < cnt[i][2] {
			shift = -shift
		}
		b = b.lsh(shift).or(b.rsh(shift))
	}
	var ans int
	ans = n * n
	for i := 0; i < n; i++ {
		if b.x.Bit(geta+i) == 1 || b.x.Bit(geta-i) == 1 {
			a := count((n-i)/2) + count(n-(n-i)/2)
			if ans > a {
				ans = a
			}
		}
	}
	fmt.Fprintln(writer, ans)
}

func count(n int) int {
	return n * (n - 1) / 2
}
func makeGrid(h, w int) [][]int {
	index := make([][]int, h, h)
	data := make([]int, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

type vertex struct {
	color, group int
	invalid      bool
}
type edge struct {
	to, id int
}
type graph struct {
	v []vertex
	e [][]edge
}

func newGraph(n int) graph {
	return graph{
		v: make([]vertex, n),
		e: make([][]edge, n),
	}
}
func (g *graph) appendEdge(from, to, id int) {
	g.e[from] = append(g.e[from], edge{
		to: to,
		id: id,
	})
}
func (g *graph) dfs(i, color, group int) {
	g.v[i].color = color
	g.v[i].group = group
	for _, e := range g.e[i] {
		if g.v[e.to].color == 0 {
			g.dfs(e.to, 3-color, group)
			continue
		}
		if g.v[e.to].color != 3-color {
			g.v[e.to].invalid = true
		}
	}
}

type bint struct {
	x *big.Int
}

func newBint(x int64) *bint {
	return &bint{x: big.NewInt(x)}
}
func (x *bint) add(y *bint) *bint {
	z := newBint(0)
	z.x.Add(x.x, y.x)
	return z
}
func (x *bint) sub(y *bint) *bint {
	z := newBint(0)
	z.x.Sub(x.x, y.x)
	return z
}
func (x *bint) mul(y *bint) *bint {
	z := newBint(0)
	z.x.Mul(x.x, y.x)
	return z
}
func (x *bint) div(y *bint) *bint {
	z := newBint(0)
	z.x.Div(x.x, y.x)
	return z
}
func (x *bint) lsh(n int) *bint {
	z := newBint(0)
	z.x.Lsh(x.x, uint(n))
	return z
}
func (x *bint) rsh(n int) *bint {
	z := newBint(0)
	z.x.Rsh(x.x, uint(n))
	return z
}
func (x *bint) or(y *bint) *bint {
	z := newBint(0)
	z.x.Or(x.x, y.x)
	return z
}


Measured memory_bytes: 19184