use std::collections::VecDeque;
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let n = read::<usize>();
    let k = read::<usize>();
    let pp = (0..n).map(|_| read::<usize>()).collect::<Vec<_>>();
    let end = n - k + 1;

    let mut deq: VecDeque<usize> = VecDeque::new();
    let mut deq_max: VecDeque<usize> = VecDeque::new();

    for i in 0..k {
        push(&mut deq, &pp, i);
        push_max(&mut deq_max, &pp, i);
    }

    let i = 0;
    let min = pop(&mut deq, &pp, i);
    let max = pop_max(&mut deq_max, &pp, i);
    let mut prev_min = min;
    let mut prev_max = max;

    let mut ans = 1;
    for i in 1..end {
        push(&mut deq, &pp, i + k - 1);
        push_max(&mut deq_max, &pp, i + k - 1);
        let min = pop(&mut deq, &pp, i);
        let max = pop_max(&mut deq_max, &pp, i);

        let is_duplicated = prev_min < min && prev_max < max;

        /*
        let is_duplicated = pp[i - 1] == prev_min
            && pp[i - 1] < pp[i]
            && pp[i - 1 + k - 1] == prev_max
            && pp[i - 1 + k - 1] < pp[i + k - 1];
            */
        if !is_duplicated {
            ans += 1;
        }

        prev_min = min;
        prev_max = max;
    }

    let mut already_sorted = 0;
    let mut prev = pp[0];
    let mut count = 1;

    for i in 1..n {
        if prev < pp[i] {
            count += 1;
            if count == k {
                already_sorted += 1;
            }
        } else {
            count = 1;
        }
        prev = pp[i];
    }

    let ans = if already_sorted > 0 {
        ans - already_sorted + 1
    } else {
        ans
    };
    println!("{}", ans);

    fn push(deq: &mut VecDeque<usize>, aa: &Vec<usize>, i: usize) {
        while let Some(&x) = deq.back() {
            if aa[x] > aa[i] {
                deq.pop_back();
            } else {
                break;
            }
        }
        deq.push_back(i)
    }

    fn pop(deq: &mut VecDeque<usize>, aa: &Vec<usize>, i: usize) -> usize {
        while let Some(&x) = deq.front() {
            if x >= i {
                return aa[x];
            } else {
                deq.pop_front();
            }
        }
        panic!("program error");
    }
    fn push_max(deq: &mut VecDeque<usize>, aa: &Vec<usize>, i: usize) {
        while let Some(&x) = deq.back() {
            if aa[x] < aa[i] {
                deq.pop_back();
            } else {
                break;
            }
        }
        deq.push_back(i)
    }

    fn pop_max(deq: &mut VecDeque<usize>, aa: &Vec<usize>, i: usize) -> usize {
        while let Some(&x) = deq.front() {
            if x >= i {
                return aa[x];
            } else {
                deq.pop_front();
            }
        }
        panic!("program error");
    }
}


Measured memory_bytes: 8444