#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1e9+7;
const int N = 2e5 + 10;
ll nums[N], n, k;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

bool cmp(ll a, ll b) {
    return abs(a) > abs(b);
}

ll solve() {
    ll res = 1;
    ll cnt_nega = 0;
    ll minpos = 0x3f3f3f3f;
    int minposidx = -1;
    int maxnegidx = -1;
    ll maxneg = -0x3f3f3f3f;
    if(n != k) {
    for(int i = 0; i < k; i ++) {
        if(nums[i] < 0) {
            cnt_nega ++;
            maxneg = nums[i];
            maxnegidx = i;
        } else if(nums[i] > 0){
            minpos = nums[i];
            minposidx = i;
        } else {
            return 0;
        }
    }
    if((cnt_nega & 1) == 0) {
        for(int i = 0; i < k; i ++) {
            res *= nums[i];
            res %= mod;
        }
        return res;
    } else {
        ll next_pos = -1;
        ll next_neg = 1;
        for(int i = k; i < n; i ++) {
            if(nums[i] > 0 && next_pos == -1) {
                next_pos = nums[i];
            }
            if(nums[i] < 0 && next_neg == 1) {
                next_neg = nums[i];
            }
            if(i == n - 1 && next_pos == -1 && next_neg == 1) {
                return 0;
            }
        }
        if(next_neg != 1) {
            if(next_pos == -1) {
                if(minposidx == -1) {
                    return 0;
                } else {
                    nums[minposidx] = next_neg;
                }
            } else {
                if(minposidx == -1) {
                    nums[maxnegidx] = next_pos;
                } else {
                    ll pos = minpos * next_pos;
                    ll neg = maxneg * next_neg;
                    if(pos >= neg) {
                        nums[maxnegidx] = next_pos;
                    } else {
                        nums[minposidx] = next_neg;
                    }
                }
            }
        } else {
            nums[maxnegidx] = next_pos;
        }
    }
    }
    for(int i = 0; i < k; i ++) {
        res *= nums[i];
        res %= mod;
    }
    return (res + mod) % mod;
}

int main() {
    quickread();
    cin >> n >> k;
    bool flag = true;
    for(int i = 0; i < n; i ++) {
        cin >> nums[i];
        if (nums[i] >= 0) flag = false;
    }
    sort(nums, nums + n, cmp);
    if(flag) {
        ll res = 1;
        if(k & 1) {
            for(int i = n - 1; i >= n - k; i --) {
                res *= nums[i];
                res %= mod;
            }
            cout << (res + mod) % mod << endl;
            return 0;
        } else {
            for(int i = 0; i < k; i ++) {
                res *= nums[i];
                res %= mod;
            }
            cout << (res+mod) % mod << endl;
            return 0;
        }
    }
    cout << (solve() + mod) % mod << endl;
    return 0;
}


Measured memory_bytes: 5204