use std::cmp::Ordering;
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")
}

struct SlideMin<'a, T: 'a> {
    vs: &'a Vec<T>,
    k: usize,
    i: usize,
    end: usize,
    deq: VecDeque<usize>,
    ord: Ordering,
}

impl<'a, T: Ord> SlideMin<'a, T> {
    pub fn min(aa: &Vec<T>, k: usize) -> SlideMin<T> {
        return SlideMin::new(&aa, k, Ordering::Greater);
    }

    pub fn max(aa: &Vec<T>, k: usize) -> SlideMin<T> {
        return SlideMin::new(&aa, k, Ordering::Less);
    }

    pub fn new(aa: &Vec<T>, window: usize, ordering: Ordering) -> SlideMin<T> {
        let mut this = SlideMin {
            vs: aa,
            k: window,
            i: 0,
            end: aa.len() - window,
            deq: VecDeque::new(),
            ord: ordering,
        };

        for i in 0..window - 1 {
            this.push(i);
        }
        return this;
    }

    pub fn next(&mut self) -> Option<&T> {
        let i = self.i;
        let &k = &self.k;
        if i <= self.end {
            self.i += 1;
            self.push(i + k - 1);
            return self.pop(i);
        } else {
            return None;
        }
    }

    fn push(&mut self, i: usize) {
        while let Some(&x) = self.deq.back() {
            let cmp = self.vs[x].cmp(&self.vs[i]);
            if cmp == self.ord || cmp == Ordering::Equal {
                self.deq.pop_back();
            } else {
                break;
            }
        }
        self.deq.push_back(i)
    }

    fn pop(&mut self, i: usize) -> Option<&T> {
        while let Some(&x) = self.deq.front() {
            if x >= i {
                return Some(&self.vs[x]);
            } else {
                self.deq.pop_front();
            }
        }
        return None;
    }
}

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

    let mut s_min = SlideMin::min(&pp, k);
    let mut s_max = SlideMin::max(&pp, k);

    let mut prev_min = s_min.next().unwrap().to_owned();
    let mut prev_max = s_max.next().unwrap().to_owned();

    let mut ans: usize = 1;
    while let Some((min, max)) = next(&mut s_min, &mut s_max) {
        let same_with_prev = prev_min < min && prev_max < max;
        if !same_with_prev {
            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 next<'a>(
        s_min: &'a mut SlideMin<usize>,
        s_max: &'a mut SlideMin<usize>,
    ) -> Option<(usize, usize)> {
        if let Some(&a) = s_min.next() {
            if let Some(&b) = s_max.next() {
                return Some((a, b));
            }
        }
        return None;
    }
}


Measured memory_bytes: 8444