#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, k) = (v[0], v[1]);
    let mut a = read_vec::<i128>();
    if *a.iter().max().unwrap() < 0 && k % 2 == 1 {
        a.sort();
        a.reverse();
        let mut ans = 1;
        for i in 0..k {
            ans *= a[i];
            ans += 1000_000_000 + 7;
            ans %= 1000_000_000 + 7;
        }
        println!("{}", ans);
        return;
    }
    if *a.iter().max().unwrap() < 0 {
        a.sort();
        let mut ans = 1;
        for i in 0..k {
            ans *= a[i];
            ans %= 1000_000_000 + 7;
        }
        println!("{}", ans);
        return;
    }
    if n == k {
        a.sort();
        a.reverse();
        let mut ans = 1;
        for i in 0..k {
            ans *= a[i] + 1000_000_000 + 7;
            ans %= 1000_000_000 + 7;
        }
        println!("{}", ans);
        return;
    }
    if k == 1 {
        a.sort();
        a.reverse();
        let mut ans = 1;
        for i in 0..k {
            ans *= a[i] + 1000_000_000 + 7;
            ans %= 1000_000_000 + 7;
        }
        println!("{}", ans);
        return;
    }

    let mut positives = a.iter().filter(|&&x| x >= 0).cloned().collect::<Vec<_>>();
    positives.sort();
    positives.reverse();
    let mut negatives = a.iter().filter(|&&x| x < 0).cloned().collect::<Vec<_>>();
    negatives.sort();
    negatives.reverse();
    let mut negatives = negatives.into_iter().collect::<Vec<_>>();
    debug!(negatives);

    let mut uses = VecDeque::new();
    for i in 0..positives.len() {
        uses.push_back(positives[i]);
        if uses.len() == k {
            break;
        }
    }
    if (k - uses.len()) % 2 == 1 {
        uses.pop_back();
        uses.push_front(negatives.pop().unwrap());
        uses.push_front(negatives.pop().unwrap());
    }
    while uses.len() < k {
        uses.push_front(negatives.pop().unwrap());
        uses.push_front(negatives.pop().unwrap());
    }
    debug!(uses);
    let neg = uses.iter().filter(|&&x| x < 0).count();
    assert!(neg % 2 == 0);

    // assert_eq!(uses.len(), k);
    while negatives.len() >= 2 && uses[uses.len() - 1] >= 0 && uses[uses.len() - 2] >= 0 {
        assert_eq!(uses.len(), k);
        let cur_last_two = uses[uses.len() - 1] * uses[uses.len() - 2];
        let next_last_two = negatives[negatives.len() - 1] * negatives[negatives.len() - 2];
        if cur_last_two < next_last_two {
            uses.pop_back();
            uses.pop_back();
            uses.push_front(negatives.pop().unwrap());
            uses.push_front(negatives.pop().unwrap());
        } else {
            break;
        }
    }

    // let neg = uses.iter().filter(|&&x| x < 0).count();
    // assert!(neg % 2 == 0);

    let mut ans = 1;
    for num in uses {
        ans *= num + 1000_000_000 + 7;
        ans %= 1000_000_000 + 7;
    }
    println!("{}", ans);
    return;
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 14948