using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        var NK = ReadLine().Split().Select(int.Parse).ToArray();
        var N = NK[0];
        var K = NK[1];
        var A = ReadLine().Split().Select(long.Parse).ToArray();
        Array.Sort(A,(x,y)=>Abs(x).CompareTo(Abs(y)));
        Array.Reverse(A);

        if (N == K)
        {
            WriteLine(CalcFront(A,K));
        }
        else
        {
            var d = new int[N+1];
            for (int i = 0; i < N; i++)
            {
                d[i + 1] = d[i];
                if (A[i] < 0) d[i + 1]++;
            }
            
            if (d[N] == N && K % 2 == 0)
            {
                WriteLine(CalcFront(A,K));
            }
            else if(d[N] ==N&& K % 2 == 1)
            {
                WriteLine(CalcBack(A,K));
            }
            else
            {
                if(d[K]%2==0)
                {
                    WriteLine(CalcFront(A,K));
                }
                else
                {
                    int v1 = -1, v2 = -1, v3 = -1, v4 = -1;
                    double value1 = -1, value2 = -1;
                    if (d[K] < K && (d[N] - d[K]) >= 1)
                    {
                        for (int i = K - 1; i >= 0; i--)
                        {
                            if (A[i] >= 0)
                            {
                                v1 = i;
                                break;
                            }
                        }
                        for (int i = K; i < N; i++)
                        {
                            if (A[i] < 0)
                            {
                                v2 = i;
                                break;
                            }
                        }
                        if (v1 == 0) value1 = 0;
                        else value1 = (double)-A[v2] / A[v1];
                    }
                    if (d[K] > 0 && (d[N] - d[K]) < N - K)
                    {
                        for (int i = K - 1; i >= 0; i--)
                        {
                            if (A[i] < 0)
                            {
                                v3 = i;
                                break;
                            }
                        }
                        for (int i = K; i < N; i++)
                        {
                            if (A[i] >= 0)
                            {
                                v4 = i;
                                break;
                            }
                        }
                        value2 = (double)-A[v4] / A[v3];
                    }

                    if (v1 == -1||v2==-1)
                        A[v3] = A[v4];
                    else if (v3 == -1||v4==-1)
                        A[v1] = A[v2];
                    else
                    {
                        if (A[v2]*A[v3]>A[v1]*A[v4])
                            A[v1] = A[v2];
                        else
                            A[v3] = A[v4];
                    }

                    WriteLine(CalcFront(A,K));
                }
                
            }
        }
        
    }
    static int CalcFront(long[] A,int K)
    {
        Modular ans = 1;
        for (int i = 0; i < K; i++)
        {
            ans *= A[i];
        }
        return (int)ans;
    }
    static int CalcBack(long[] A,int K)
    {
        Modular ans = 1;
        for (int i = A.Length - 1; i >= A.Length-K; i--)
        {
            ans *= A[i];
        }
        return (int)ans;
    }
}
class Modular
{
    private const int M = 1000000007;
    private long value;
    public Modular(long value = 0) { this.value = value; }
    public static implicit operator Modular(long a)
    {
        var m = a % M;
        return new Modular((m < 0) ? m + M : m);
    }
    public static Modular operator +(Modular a, Modular b)
    => a.value + b.value;
    public static Modular operator -(Modular a, Modular b)
    => a.value - b.value;
    public static Modular operator *(Modular a, Modular b)
    => a.value * b.value;
    public static Modular Pow(Modular a, int n)
    {
        switch (n)
        {
            case 0:
                return 1;
            case 1:
                return a;
            default:
                var p = Pow(a, n / 2);
                return p * p * Pow(a, n % 2);
        }
    }
    public static Modular operator /(Modular a, Modular b)
    {
        return a * Pow(b, M - 2);
    }
    private static readonly List<int> facs = new List<int> { 1 };
    public static Modular Fac(int n)   //階乗
    {
        for (int i = facs.Count; i <= n; ++i)
        {
            facs.Add((int)(Math.BigMul(facs.Last(), i) % M));
        }
        return facs[n];
    }
    public static Modular Fac(int r, int n)
    {
        int temp = 1;
        for (int i = r; i <= n; i++)
        {
            temp = (int)(Math.BigMul(temp, i) % M);
        }
        return temp;
    }
    public static Modular Ncr(int n, int r) //nCr
    {
        return (n < r) ? 0
             : (n == r) ? 1
                        : (n < 1000000) ? Fac(n) / (Fac(r) * Fac(n - r))
                            : Fac(n - r + 1, n) / Fac(r);
    }
    public static explicit operator int(Modular a)
    {
        return (int)a.value;
    }
}

Measured memory_bytes: 59388