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 mod = 1_000_000_007L;

struct Mint {
    long x;

    this(long a) {
        x = a % mod;
        if (x < 0)
            x += mod;
    }

    this(Mint a) {
        x = a.x;
    }

    ref Mint opAssign(long a) {
        this = Mint(a);
        return this;
    }

    ref Mint opOpAssign(string op)(Mint rhs) {
        static if (op == "+") {
            x += rhs.x;
            if (x >= mod)
                x -= mod;
        }
        static if (op == "-") {
            x -= rhs.x;
            if (x < 0)
                x += mod;
        }
        static if (op == "*") {
            (x *= rhs.x) %= mod;
        }
        static if (op == "/") {
            this *= rhs.inv();
        }
        return this;
    }

    ref Mint opOpAssign(string op)(long rhs) {
        static if (op == "^^") {
            this = powmod(this, rhs);
            return this;
        }
        else {
            return mixin("this " ~ op ~ "= Mint(rhs)");
        }
    }

    const Mint powmod(Mint a, long b) {
        Mint res = 1, p = a;
        while (b > 0) {
            if (b & 1)
                res *= p;
            p *= p;
            b /= 2;
        }
        return res;
    }

    const Mint inv() {
        return powmod(this, mod - 2);
    }

    Mint opUnary(string op)() if (s == "-") {
        return Mint(-x);
    }

    Mint opBinary(string op, T)(const T rhs) {
        return mixin("Mint(this) " ~ op ~ "= rhs");
    }

    Mint opBinaryRight(string op)(const long rhs) {
        return mixin("Mint(rhs) " ~ op ~ "= this");
    }

    bool opEquals(Mint a, Mint b) {
        return a.x == b.x;
    }

    bool opEquals(long rhs) {
        long y = rhs % mod;
        if (y < 0)
            y += mod;
        return x == y;
    }

    string toString() {
        import std.conv : to;

        return x.to!string;
    }
}

void main() {
    int n, k;
    scan(n, k);
    auto a = readln.split.to!(long[]);

    if (n == k) {
        Mint ans = 1;
        foreach (i; 0 .. n) {
            ans *= a[i];
        }
        writeln(ans);
        return;
    }

    long[] pos, neg;
    foreach (i; 0 .. n) {
        if (a[i] >= 0) {
            pos ~= a[i];
        }
        else {
            neg ~= -a[i];
        }
    }

    if (k % 2 == 1 && pos.length == 0) {
        neg.sort!"a < b"();
        Mint ans = 1;
        foreach (i; 0 .. k) {
            ans *= mod - neg[i];
        }
        writeln(ans);
        return;
    }

    pos.sort!"a > b"();
    neg.sort!"a > b"();

    while (pos.length < k) {
        pos ~= 0;
    }
    while (neg.length < k) {
        neg ~= 0;
    }
    auto b = pos[0 .. k];
    int r = k;
    int l = 0;
    for (; l < k;) {
        if (r <= 1 || (l + 2) > k)
            break;
        long x = pos[r - 1] * pos[r - 2];
        long y = neg[l] * neg[l + 1];
        if (x > y)
            break;
        r -= 2;
        l += 2;
    }

    debug {
        writefln("%s %s", r, l);
    }

    Mint ans = 1;
    foreach (i; 0 .. r) {
        ans *= pos[i];
    }
    foreach (i; 0 .. l) {
        ans *= neg[i];
    }
    writeln(ans);
}

void scan(T...)(ref T args) {
    auto line = readln.split; // @suppress(dscanner.suspicious.unmodified)
    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);
}


Measured memory_bytes: 16268