/// ! 704/ 10^, )!3!+B?!B!/[!]
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vp vector<pi>
#define vpl vector<pl>

#define f first
#define s second

#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define pf push_front

#define FOR(i, a, b) for(ll i = (a); i < (b); i++)
#define ROF(i,a,b) for(ll i = (b) - 1; i >= (a); --i)
#define trav(a, x) for(auto& a : x)

#define nl "\n"

void solve(){
    int n, q;
    cin >> n >> q;
    vi a(n);
    FOR(i, 0, n){
        cin >> a[i];
    }
    vp u(q);
    vi res(q);
    FOR(i, 0, q){
        cin >> u[i].f >> u[i].s;
        int l = u[i].f, r = u[i].s;
        set<int> s;
        FOR(j, l - 1, r){
            s.insert(a[i]);
        }
        int t = s.size();
        res[i] = max(1, (r - l - t));
    }
    trav(i, res) cout << i << nl;
}

int main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}