#![allow(unused_imports)]
//use itertools::{iproduct, Itertools};
//use proconio::input;
//use proconio::marker::*;
use std::collections::*;

fn main() {
    input! {
        n:usize,
        q:usize,
        a:[usize;n],
        xy:[(usize1,usize1);q],
    }

    let mut acp = a.clone();
    acp.sort();
    acp.dedup();
    let mut comped = HashMap::new();
    for (i, ai) in acp.iter().enumerate() {
        comped.insert(*ai, i);
    }
    let mut ranks = vec![0; n];
    for i in 0..n {
        ranks[i] = comped[&a[i]];
    }

    for &(x, y) in xy.iter() {
        let ans = ranks[x].saturating_sub(ranks[y] + 1);
        println!("{}", ans);
    }
}

use math::*;
mod math {
    #[allow(dead_code)]
    pub fn pow(mut n: usize, mut e: usize, m: usize) -> usize {
        let mut res = 1;
        while 0 < e {
            if e & 1 != 0 {
                res *= n;
                res %= m;
            }

            n *= n;
            n %= m;
            e >>= 1;
        }

        res
    }

    #[allow(dead_code)]
    pub fn gcd(a: usize, b: usize) -> usize {
        if b == 0 {
            a
        } else {
            gcd(b, a % b)
        }
    }

    #[allow(dead_code)]
    pub fn lcm(a: usize, b: usize) -> usize {
        a / gcd(a, b) * b
    }

    #[allow(dead_code)]
    pub fn prime_factor(mut n: usize) -> std::collections::HashMap<usize, usize> {
        let mut pfacs = std::collections::HashMap::new();
        for d in 2.. {
            if d * d > n {
                break;
            }

            while n % d == 0 {
                *pfacs.entry(d).or_insert(0) += 1;
                n /= d;
            }
        }
        if n != 1 {
            *pfacs.entry(n).or_insert(0) += 1;
        }

        pfacs
    }

    #[allow(dead_code)]
    pub fn divisors(n: usize) -> Vec<usize> {
        let mut divs = vec![];
        for d in (1..).take_while(|&d| d * d <= n) {
            if n % d == 0 {
                divs.push(d);
                if n / d != d {
                    divs.push(n / d);
                }
            }
        }

        divs
    }

    #[allow(dead_code)]
    pub fn eratosthenes_sieve(n: usize) -> Vec<usize> {
        let mut is_primes = vec![true; n + 1];
        is_primes[0] = false;
        is_primes[1] = false;
        let mut primes = vec![];

        for i in 2..=n {
            if !is_primes[i] {
                continue;
            }

            for j in (2 * i..=n).step_by(i) {
                is_primes[j] = false;
            }
        }

        for (val, is_prime) in is_primes.into_iter().enumerate() {
            if is_prime {
                primes.push(val);
            }
        }

        primes
    }

    #[allow(dead_code)]
    pub fn base_n(mut base10: usize, base: usize, len: usize) -> Vec<usize> {
        let mut base_n = vec![];
        for _ in 0..len {
            base_n.push(base10 % base);
            base10 /= base;
        }
        base_n.reverse();

        base_n
    }

    #[allow(dead_code)]
    pub fn div_floor(mut a: i64, mut b: i64) -> i64 {
        if b < 0 {
            a = -a;
            b = -b;
        }

        if a >= 0 {
            a / b
        } else {
            (a + 1) / b - 1
        }
    }

    #[allow(dead_code)]
    pub fn div_ceil(mut a: i64, mut b: i64) -> i64 {
        if b < 0 {
            a = -a;
            b = -b;
        }
        if a > 0 {
            (a - 1) / b + 1
        } else {
            a / b
        }
    }
}
use input::*;
mod input {
    #[macro_export]
    macro_rules! input {
        (source = $s:expr, $($r:tt)*) => {
            let mut iter = $s.split_whitespace();
            input_inner!{iter, $($r)*}
        };
        ($($r:tt)*) => {
            let s = {
                use std::io::Read;
                let mut s = String::new();
                std::io::stdin().read_to_string(&mut s).unwrap();
                s
            };
            let mut iter = s.split_whitespace();
            input_inner!{iter, $($r)*}
        };
    }

    #[macro_export]
    macro_rules! input_inner {
        ($iter:expr) => {};
        ($iter:expr, ) => {};

        ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
            let $var = read_value!($iter, $t);
            input_inner!{$iter $($r)*}
        };
    }

    #[macro_export]
    macro_rules! read_value {
        ($iter:expr, ( $($t:tt),* )) => {
            ( $(read_value!($iter, $t)),* )
        };

        ($iter:expr, [ $t:tt ; $len:expr ]) => {
            (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        };

        ($iter:expr, chars) => {
            read_value!($iter, String).chars().collect::<Vec<char>>()
        };

        ($iter:expr, usize1) => {
            read_value!($iter, usize) - 1
        };

        ($iter:expr, $t:ty) => {
            $iter.next().unwrap().parse::<$t>().expect("Parse error")
        };
    }
}