macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};
use std::collections::BTreeSet;

fn main() {
    input!{
        n: usize,
        m: usize,
        es: [(usize1, usize1); m]
    }
    let mut g = vec![(0..n).collect::<BTreeSet<usize>>(); n];
    for i in 0..n {
        g[i].remove(&i);
    }
    for &(a, b) in &es {
        g[a].remove(&b);
        g[b].remove(&a);
    }
    let g = g.iter().map(|s| s.iter().cloned().collect::<Vec<usize>>()).collect::<Vec<_>>();
    let mut done = vec![None; n];
    let mut ds = vec![];
    for i in 0..n {
        if done[i].is_some() {
            continue;
        }
        let mut ct: i64 = 1;
        let mut cf: i64 = 0;
        done[i] = Some(true);
        let mut st = vec![i];
        while let Some(v) = st.pop() {
            let f = !done[v].unwrap();
            for &c in &g[v] {
                if let Some(fc) = done[c] {
                    if fc ^ f {
                        println!("-1");
                        return;
                    }
                    continue;
                }
                if f {
                    ct += 1;
                } else {
                    cf += 1;
                }
                done[c] = Some(f);
                st.push(c);
            }
        }
        ds.push((ct - cf).abs() as usize);
    }
    let mut dp = vec![false; n + 1];
    dp[ds[0]] = true;
    for i in 1..ds.len() {
        let mut next = vec![false; n + 1];
        for j in 0..n + 1 - ds[i] {
            next[j + ds[i]] |= dp[j];
        }
        for j in 0..n + 1 {
            next[(j as i64 - ds[i] as i64).abs() as usize] |= dp[j];
        }
        dp = next;
    }
    for i in 0..n + 1 {
        if dp[i] {
            println!("{}", ((n + i) / 2) * ((n + i) / 2 - 1) / 2 + ((n - i) / 2) * ((n - i) / 2 - 1) / 2);
            return;
        }
    }
}


Measured memory_bytes: 18684