//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}

template<typename T> 
struct BIT{
  int n;
  vector<T> bit;//1-indexed

  BIT():n(-1){}
  //initialization

  BIT(int n_,T d):n(n_),bit(n_+1,d){}
  //initialization2 n_要素数 d初期値
  
  T sum(int i){
    T s=bit[0];
    for(int x=i;x>0;x-=(x&-x))
      s+=bit[x];
    return s;
  }
  //1からiまでの和(1-indexed)
  
  void add(int i,T a){
    if(i==0) return;
    for(int x=i;x<=n;x+=(x&-x))
      bit[x]+=a;
  }
  //iにa加える
  
  T lower_bound(T w){
    if(w<=0) return 0;
    T x=0,r=1;//xは横の位置を管理するイメージ
    while(r<n) r<<=1;
    for(T k=r;k>0;k>>=1){//上の層から見る
      if(x+k<=n && bit[x+k]<w){
        w-=bit[x+k];
        x+=k;//右の要素に移る
      }
    }
    return x+1;
  }
  //indまでの区間和がw以上になるような最小のindを求める
  
  T sum0(int i){
    return sum(i+1);
  }
  void add0(int i,T a){
    add(i+1,a);
  }//0-index用

  T query(int l,int r){
    return sum(r-1)-sum(l-1);
  }//[l,r)の和を求める

  T query0(int l,int r){
    return sum(r)-sum(l);
  }//0-index用
};

signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,q;cin>>n>>q;
  V<ll> c(n+1);rep(i,0,n)cin>>c[i];

  V<tuple<ll,ll,ll>> qs(q);
  rep(i,0,q){
    ll l,r;cin>>l>>r;
    --l;--r;
    qs[i]=mt(r,l,i);
  }

  sort(all(qs));

  int nowr=0;
  V<ll> last(n+2,-1),ans(q);
  BIT<ll> bit(n+3,0);

  rep(i,0,q){
    ll l,r,id;
    tie(r,l,id)=qs[i];
    while(nowr<=r){
      if(last[c[nowr]]>=0)bit.add0(last[c[nowr]],-1);
      last[c[nowr]]=nowr;
      bit.add0(nowr,1);
      ++nowr;
    }

    ans[id]=bit.query0(l,r+1);
  }

  rep(i,0,q)cout<<ans[i]<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 31144