using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int k = sc.NextInt();
        long[] a = sc.LongArray();

        long totalNegaCount = a.Where(num => num < 0).Count();
        if (totalNegaCount == n && k % 2 == 1)
        {
            a = a.OrderBy(num => Math.Abs(num)).ToArray();

            ModInt negaAnswer = 1;
            for (int i = 0; i < k; i++)
            {
                negaAnswer *= a[i];
            }
            Console.WriteLine(negaAnswer);
            return;
        }

        if (k == n)
        {
            ModInt tmpAnswer = 1;
            foreach (var num in a)
            {
                tmpAnswer *= num;
            }
            Console.WriteLine(tmpAnswer);
            return;
        }

        long[] posi = a.Where(num => num >= 0).OrderByDescending(num => Math.Abs(num)).ToArray();
        long[] nega = a.Where(num => num < 0).OrderByDescending(num => Math.Abs(num)).ToArray();

        ModInt answer = 1;

        if (k % 2 == 1)
        {
            answer *= posi[0];
            posi = posi.Where((num, index) => index != 0).ToArray();
            k--;
        }

        long posiIndex = 0;
        long negaIndex = 0;

        while (k > 0)
        {
            long nextP = -1;
            long nextN = -1;
            if (posi.Count() > posiIndex + 1)
            {
                nextP = posi[posiIndex] * posi[posiIndex + 1];
            }
            if (nega.Count() > negaIndex + 1)
            {
                nextN = nega[negaIndex] * nega[negaIndex + 1];
            }
            if (nextP >= nextN)
            {
                answer *= posi[posiIndex];
                answer *= posi[posiIndex + 1];
                posiIndex += 2;
            }
            else
            {
                answer *= nega[negaIndex];
                answer *= nega[negaIndex + 1];
                negaIndex += 2;
            }
            k -= 2;
        }

        Console.WriteLine(answer);
    }

    // ModInt
    class ModInt
    {
        public const long Mod = (int)1e9 + 7;

        public long num;

        public ModInt(long n) { num = n; }

        public override string ToString() { return num.ToString(); }
        public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; }
        public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; }
        public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }
        public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); }

        public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }

        public static ModInt Pow(long v, long k)
        {
            long ret = 1;
            for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
                if ((k & 1) == 1) ret = ret * v % Mod;
            return new ModInt(ret);
        }

        public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 66556