import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;

alias Pair = Tuple!(int, "a", int, "b");

void main() {
    int N, M;
    scan(N, M);

    auto g = new bool[][](N, N);
    foreach (i ; 0 .. M) {
        int ai, bi;
        scan(ai, bi);
        ai--, bi--;
        g[ai][bi] = g[bi][ai] = 1;
    }

    // 補グラフを作る
    auto adj = new int[][](N, 0);
    foreach (i ; 0 .. N) {
        foreach (j ; 0 .. N) if (j != i) {
            if (!g[i][j]) {
                adj[i] ~= j;
            }
        }
    }

    debug {
        writeln(adj);
    }
    auto col = new int[](N);
    col[] = -1;

    Pair nibu(int v, int c) {
        col[v] = c;
        auto res = c ? Pair(0, 1) : Pair(1, 0);

        foreach (u ; adj[v]) {
            if (col[u] == -1) {
                auto p = nibu(u, c ^ 1);
                if (p == Pair(-1, -1)) {
                    return Pair(-1, -1);
                }
                res = Pair(res.a + p.a, res.b + p.b);
            }
            else if (col[u] == col[v]) {
                return Pair(-1, -1);
            }
        }

        return res;
    }

    Pair[] ps;

    foreach (i ; 0 .. N) {
        if (col[i] == -1) {
            auto p = nibu(i, 0);
            if (p == Pair(-1, -1)) {
                writeln(-1);
                return;
            }
            ps ~= p;
        }
    }

    debug {
        writeln(ps);
    }

    auto U = ps.length.to!int;

    auto dp = new bool[][](U + 1, N + 1);
    dp[0][0] = true;

    foreach (i ; 0 .. U) {
        foreach (j ; 0 .. N + 1) {
            if (dp[i][j]) {
                dp[i + 1][j + ps[i].a] = true;
                dp[i + 1][j + ps[i].b] = true;
            }
        }
    }

    auto k = 0;
    foreach (i ; 0 .. N + 1) {
        if (dp[U][i]) {
            chmax(k, i * (N - i));
        }
    }

    debug {
        writefln("%(%s\n%)", dp);
    }

    auto L = N * (N - 1) / 2 - M;
    auto ans = M - (k - L);
    writeln(ans);
}




void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}
