use core::cmp::max;
use std::cmp::Reverse;

fn read_line() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("No Line");
    buffer
}
fn read_lines<R, T: Fn(&str)->R> (count: usize, transformer: T) -> Vec<R> {
    let mut buffer = String::new();
    let mut vec = Vec::with_capacity(count);
    for _ in 0 .. count {
        std::io::stdin().read_line(&mut buffer).expect("No Line");
        vec.push(transformer(buffer.trim()));
        buffer.clear();
    }
    vec
}
fn read_value<T: std::str::FromStr>() -> T {
    read_line().trim().parse().ok().unwrap()
}
fn read_values<T: std::str::FromStr>() -> Vec<T> {
    read_line().trim().split(' ').map(|x| x.parse().ok().expect("Can't Parse")).collect::<Vec<T>>()
}
fn read_tabulate<T: std::str::FromStr>(count: usize) -> Vec<T> {
    let mut buffer = String::new();
    let mut vec = Vec::with_capacity(count);
    for _ in 0 .. count {
        std::io::stdin().read_line(&mut buffer).expect("No Line");
        vec.push(buffer.trim().parse().ok().expect("Can't Parse"));
        buffer.clear();
    }
    vec
}
macro_rules! assign {
    () => {};
    ($($token:tt)*) => {
        let mut iter = read_values::<String>().into_iter();
        assign_iter!(iter, $($token)*);
    };
}
macro_rules! assign_iter {
    ($iter:expr) =>{};
    ($iter:expr,) =>{};
    ($iter:expr, $id:ident:$t:tt $($tail:tt)*) => {
        let $id: $t = $iter.next().unwrap().parse().ok().expect("Can't Parse");
        assign_iter!($iter, $($tail)*);
    };
    ($iter:expr, mut $id:ident:$t:tt $($tail:tt)*) => {
        let mut $id: $t = $iter.next().unwrap().parse().ok().expect("Can't Parse");
        assign_iter!($iter, $($tail)*)
    };
}
macro_rules! freeze {
    ($($id:ident), *) => {
        $(let $id = $id;)*
    };
}
fn pow_mod(base: i64, exp: usize, modulo: i64) -> i64 {
    match exp {
        0usize => 1i64,
        1usize => base % modulo,
        _ => pow_mod(base * base % modulo, exp >> 1, modulo) * pow_mod(base, exp & 1, modulo) % modulo
    }
}
fn main() {
    assign! {
        n: usize
        k: usize
    }
    let modulo = 1000000007i64;
    let mut values = read_values::<i64>();
    values.sort_by_cached_key(|&v| Reverse(v.abs()));
    let mut last_positive: Option<usize> = None;
    let mut last_negative: Option<usize> = None;
    let mut result = 1i64;
    for i in 0 .. k {
        result = result * values[i] % modulo;
        if values[i] > 0 {
            last_positive = Some(i);
        }else if values[i] < 0 {
            last_negative = Some(i);
        }
    }
    if result >= 0 {
        println!("{}", result);
    }else if values.iter().any(|&v| v > 0) {
        let mut pair:Option<(i64, i64)> = None;
        if let Some(pos) = last_positive {
            let remove = values[pos];
            if let Some(neg) = (k .. n).find(|&i| { values[i] < 0 }) {
                let add = values[neg];
                if let Some((max_add, max_remove)) = pair {
                    if max_remove.abs() * add.abs() > max_add.abs() * remove.abs() {
                        pair = Some((add, remove));
                    }
                }else {
                    pair = Some((add, remove));
                }
            }
        } 
        if let Some(neg) = last_negative {
            let remove = values[neg];
            if let Some(pos) = (k .. n).find(|&i| { values[i] > 0}) {
                let add = values[pos];
                if let Some((max_add, max_remove)) = pair {
                    if max_remove.abs() * add.abs() > max_add.abs() * remove.abs() {
                        pair = Some((add, remove));
                    }
                }else {
                    pair = Some((add, remove));
                }
            }
        }
        if let Some((max_add, max_remove)) = pair {
            let result = result * pow_mod(max_remove, (modulo - 2) as usize, modulo) % modulo * max_add % modulo;
            println!("{}", (modulo + result) % modulo);
        }else {
            println!("{}", (modulo + result) % modulo);
        }
    }else {
        result = 1i64;
        for i in n - k .. n {
            result = result * values[i] % modulo;
        }
        println!("{}", (modulo + result) % modulo);
    }
}

Measured memory_bytes: 6684