#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define MOD                1000000007
#define F                  first
#define S                  second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define REP(i,l,r)         for(int i=l;i<r;i++)
#define RER(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
#define remax(a,b)         a=max(a,b)
#define remin(a,b)         a=min(a,b)
#define bitcount(x)        __builtin_popcountll(x)
#define iceil(n,x)         (((n)-1)/(x)+1)
#define flush              fflush(stdout)
#define pf                 push_front()
#define pob                pop_back()
#define ins                insert
#define mii                map<int,int> 
#define show(x)            for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define show2(x)           for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";
#define test()             int x;cin >> x;while(x--){solve();}
#define test2()            int x;cin >> x;for(int i=1;i<=x;i++){cout << "Case #" << i << " : ";solve();}
#define watch(x)           cout << (#x) << " is " << (x) << endl
using namespace std;


/* Mathematical Functions */
int power(int x,int y);
bool isPrime(int n);
int modInv(int a,int b);
int gcdExtended(int a,int b,int *x,int* y);
int mpower(int a,int b,int p);

const int inf = (int)1e17;
const int N = (int)3e5+5;
int32_t main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
        FASTIO;
        int t = 1;
       // cin >> t;
        int mod = 1e9+7;
        while(t--)
        {
            int n,k,arr[200002];
            cin >> n >> k;
            for(int i=0;i<n;i++)
            {
                cin >> arr[i];
            }
            sort(arr,arr+n);

            long long start = 0,end = n-1,ans = 1,val = 0;
            if(arr[n-1]<0&&k%2)
            {
                for(int i=0;i<k;i++)
                {
                    ans = (ans*arr[n-1-i])%mod;
                }
            }
            else
            {
                while(k)
                {
                    if(k>1)
                    {
                        if(arr[start]*arr[start+1]>arr[end]*arr[end-1])
                        {
                            ans = (((arr[start]*arr[start+1])%mod)*ans)%mod;
                            start+=2;
                            k-=2;
                        }
                        else
                        {
                            ans = (ans*arr[end])%mod;
                            end--;
                            k--;
                        }
                    }
                    else
                    {
                        ans = (ans*arr[end])%mod;
                        end--;
                        k--;
                    }
                }
            }
            ans = (ans+mod)%mod;
           cout << ans << "\n";
        }
        return 0;
    }


Measured memory_bytes: 4720