using System;
using System.Collections.Generic;
using System.Linq;
using static Constans;

public static class Constans
{
    public const long Mod = (long)1e9 + 7;
}
public class PriorityDeque<T> where T : IComparable<T>
{
    readonly SortedSet<T> set = new SortedSet<T>();
    readonly Dictionary<T, int> counter = new Dictionary<T, int>();

    public int Count { get; private set; } = 0;

    public int GetCount(T key)
    {
        counter.TryGetValue(key, out int count);
        return count;
    }

    public void Enqueue(T key)
    {
        if (!counter.ContainsKey(key))
        {
            set.Add(key);
            counter[key] = 1;
        }
        else
        {
            counter[key]++;
        }
        Count++;
    }

    public T DequeueMin()
    {
        var min = set.Min;
        counter[min]--;
        if (counter[min] == 0)
        {
            set.Remove(min);
            counter.Remove(min);
        }
        Count--;
        return min;
    }

    public T DequeueMax()
    {
        var max = set.Max;
        counter[max]--;
        if (counter[max] == 0)
        {
            set.Remove(max);
            counter.Remove(max);
        }
        Count--;
        return max;
    }

    public T PeekMin()
    {
        return set.Min;
    }

    public T PeekMax()
    {
        return set.Max;
    }
}

public struct ModInt
{
    public long Num;

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

    // x^n
    public static long Power(long x, long n)
    {
        long pow = 1;
        while (n > 0)
        {
            if (n % 2 == 0)
            {
                x *= x;
                x %= Mod;
                n /= 2;
            }
            else
            {
                pow *= x;
                pow %= Mod;
                n--;
            }
        }

        return pow;
    }

    public static ModInt GetInv(long f)
    {
        // フェルマーの小定理 a^(-1) = a^(mod-2)
        return new ModInt(Power(f, Mod - 2));
    }

    public ModInt GetInv()
    {
        return GetInv(Num);
    }

    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 class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = vals[0];
        var K = vals[1];
        var A = Console.ReadLine().Split(' ').Select(long.Parse).Where(a => a != 0).ToArray();
        var plus = A.Count(a => a > 0);
        var minus = A.Length - plus;

        if (A.Length < K)
        {
            Console.WriteLine(0);
            return;
        }

        if (K > plus)
        {
            var p = plus;
            var m = minus;
            var t = Math.Min(K / 2 * 2, m / 2 * 2);
            m -= t;
            var k = K - t;
            t = Math.Min(k, p);
            p -= t;
            k -= t;
            // 積は負になる
            if (k > 0)
            {
                if (A.Length != N)
                {
                    Console.WriteLine(0);
                    return;
                }

                var prod = A.OrderBy(a => Math.Abs(a)).Take(K).Aggregate(new ModInt(1), (a, b) => a * b);
                Console.WriteLine(prod);
                return;
            }
        }

        // 積は正になる
        var q = new PriorityDeque<long>();
        foreach (var a in A)
        {
            q.Enqueue(a);
        }

        {
            var prod = new ModInt(1);
            var max = q.DequeueMax();
            var min = q.DequeueMin();
            for (int i = 0; i < (K / 2 * 2); i += 2)
            {
                if (q.Count == 0)
                {
                    prod *= max;
                    prod *= min;
                    break;
                }

                var max2 = q.PeekMax();
                var min2 = q.PeekMin();

                var xx = max * max2;
                var nn = min * min2;
                if (xx > nn)
                {
                    prod *= xx;
                    q.DequeueMax();
                    if (q.Count != 0)
                    {
                        max = q.DequeueMax();
                    }
                }
                else
                {
                    prod *= nn;
                    q.DequeueMin();
                    if (q.Count != 0)
                    {
                        min = q.DequeueMin();
                    }
                }
            }

            if (K % 2 != 0)
            {
                prod *= max;
            }
            Console.WriteLine(prod);
        }
    }
}

Measured memory_bytes: 68924