const Main = input => {
    input = input.split("\n");
    const nk = input[0].split(" ");
    const n = parseInt(nk[0], 10);
    const k = parseInt(nk[1], 10);
    const a = input[1].split(" ").map(value => parseInt(value, 10)).sort((a, b) => {b - a});

    let product = 1;
    for(let i = 0; i < k; i++) {
        product *= a[i];
    }

    const result = product % (10 ** 9 + 7);
    console.log(result);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));