//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
struct fenwick_tree
{
    typedef int T;
    T n;
    vector<T> bit;
    T b = 1;
    // 各要素の初期値は 0
    fenwick_tree(T num) : bit(num + 1, 0) { n = num; }

    // a_i += w
    void add(T i, T w)
    {
        for (T x = i; x <= n; x += x & -x)
        {
            bit[x] += w;
        }
    }
    ll get(T i)
    {
        ll s = 0;
        while (i > 0)
        {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    // [1, i] の和を計算.
    T sum(T i)
    {
        T ret = 0;
        for (T x = i; x > 0; x -= x & -x)
        {
            ret += bit[x];
        }
        return ret;
    }
    // [left+1, right] の和を計算.
    T sum(T left, T right)
    {
        return sum(right) - sum(left);
    }
    int get_index(ll x)
    { //something like lower_bound(all(sum), a). O(logn)
        x--;
        while (b * 2 <= n)
            b *= 2;
        int r = b;
        int res = 0;
        while (r > 0)
        {
            if ((r | res) <= n)
            {
                int rv = bit[r | res];
                if (x >= rv)
                {
                    x -= rv;
                    res += r;
                }
            }
            r >>= 1;
        }
        return res + 1;
    }
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    vector<int> c(n);
    rep(i, n) cin >> c[i];
    rep(i, n) c[i]--;
    fenwick_tree ft(n + 1);
    vector<pair<int, int>> que(q);
    vector<pair<pair<int, int>, int>> que1(q);
    vector<int> ans(q), ind(q);
    rep(i, q) cin >> que[i].second >> que[i].first;
    rep(i, q)
    {
        que1[i].first.first = que[i].first;
        que1[i].first.second = que[i].second;
        que1[i].second = i;
    }
    sort(ALL(que1));
    sort(ALL(que));
    rep(i, q)
    {
        ind[i] = que1[i].second;
    }
    vector<int> last(n, -1);
    int k = que[0].first;
    rep(i, k)
    {
        last[c[i]] = i + 1;
    }
    rep(i, n)
    {
        if (last[i] != -1)
        {
            ft.add(last[i], 1);
        }
    }
    ans[ind[0]] = ft.sum(que[0].second - 1, que[0].first);
    for (int i = 1; i < q; i++)
    {
        for (int j = k + 1; j <= que[i].first; j++)
        {
            int r = c[j - 1];
            if (last[r] != -1)
            {
                ft.add(last[r], -1);
            }
            last[r] = j;
            ft.add(j, 1);
        }
        k = que[i].first;
        ans[ind[i]] = ft.sum(que[i].second - 1, que[i].first);
        //cout << que[i].first<<" "<<que[i].second<<"\n";
        //debug(last);
    }
    //debug(ind);
    rep(i,q)cout<<ans[i]<<"\n";
}


Measured memory_bytes: 23288