#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處
namespace Number {
    typedef long long int LL;
    // 求取 a, b 的最大公因數
    LL gcd(LL a, LL b) {
        if (a % b == 0) {
            return b;
        }
        return gcd(b, a % b);
    }
    // 求取 a, b 的最大公因數 gcd
    // 以及 x, y 使得 a*x + b*y = gcd
    LL gcd_extend(LL a, LL b, LL *x, LL *y) { 
        if (a == 0) { 
            *x = 0, *y = 1; 
            return b; 
        } 
    
        LL x1, y1; // To store results of recursive call 
        LL gcd = gcd_extend(b%a, a, &x1, &y1); 
    
        *x = y1 - (b/a) * x1; 
        *y = x1; 
    
        return gcd; 
    }
    // 求 a_inv 使得 (a * a_inv) % m = gcd(a, m)
    // 若 a, m 互質，即求 a 在 mod m 群的反元素 a_inv 
    LL mod_inv(LL a, LL m) { 
        LL x, y; 
        LL g = gcd_extend(a, m, &x, &y); 
        // 處理 x 爲負的情形 
        LL a_inv = (x%m + m) % m; 
        return a_inv;
    }
    // 求 x^n % m
    LL mod_pow(LL x, LL n, LL m) {
        if (n == 0) {
            return 1;
        } else if (n & 1) {
            LL half = mod_pow(x, n/2, m);
            return (half * half % m) * x % m;
        } else {
            LL half = mod_pow(x, n/2, m);
            return half * half % m;
        }
    }
    // 連乘
    LL mul(LL from, LL to, LL m) {
        LL ret = 1;
        for (LL i = from; i <= to; i++) {
            ret *= i;
            ret %= m;
        }
        return ret;
    }
    // 求 (C n 取 k) % m
    LL mod_comb(LL n, LL k, LL m) {
        LL mi = k < n-k ? k : n-k;
        LL up = mul(n - mi + 1, n, m);
        LL down = mul(1, mi, m);
        return (up * mod_inv(down, m)) % m;
    }
}
  

LL a[200005];

LL M = (1e9) + 7;

struct Signed {
    LL num;
    int sign;
};

bool cmp(Signed x, Signed y) {
    return x.num > y.num;
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<Signed> nums;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] > 0) {
            nums.push_back({a[i], 1});
        } else if (a[i] == 0) {
            nums.push_back({a[i], 0});
        } else {
            nums.push_back({-a[i], -1});
        }
    }
    sort(nums.begin(), nums.end(), cmp);
    int sign = 1;
    LL ans = 1;
    for (int i = 0; i < k; i++) {
        sign *= nums[i].sign;
        ans *= nums[i].num;
        ans %= M;
    }
    if (sign == -1) {
        LL sm_pos = 0;
        LL sm_neg = 0;
        for (int i = 0; i < k; i++) {
            if (nums[i].sign == 1) {
                sm_pos = nums[i].num;
            }
            if (nums[i].sign == -1) {
                sm_neg = nums[i].num;
            }
        }
        LL big_pos = 0;
        LL big_neg = 0;
        for (int i = n - 1; i >= k; i--) {
            if (nums[i].sign == 1) {
                big_pos = nums[i].num;
            }
            if (nums[i].sign == -1) {
                big_neg = nums[i].num;
            }
        }
        if ((sm_pos == 0 || big_neg == 0) && (sm_neg == 0 || big_pos == 0)) {
            // 只能是負的
            LL ans = 1;
            for (int i = n - 1; i >= n - k; i--) {
                ans *= nums[i].num;
                ans %= M;
            }
            ans *= -1;
            ans += M;
            ans %= M;
            cout << ans << endl;
        } else if (sm_pos == 0 || big_neg == 0) {
            ans *= big_pos;
            ans %= M;
            ans *= Number::mod_inv(sm_neg, M);
            ans %= M;
            cout << ans << endl;
        } else if (sm_neg == 0 || big_pos == 0) {
            ans *= big_neg;
            ans %= M;
            ans *= Number::mod_inv(sm_pos, M);
            ans %= M;
            cout << ans << endl;
        } else {
            if (big_neg * sm_neg > big_pos * sm_pos) {
                ans *= big_neg;
                ans %= M;
                ans *= Number::mod_inv(sm_pos, M);
                ans %= M;
            } else {
                ans *= big_pos;
                ans %= M;
                ans *= Number::mod_inv(sm_neg, M);
                ans %= M;
            }
            cout << ans << endl;
        }
    } else if (sign == 1) {
        cout << ans << endl;
    } else if (sign == 0) {
        printf("0\n");
    }
}


Measured memory_bytes: 8488