#include #include using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; const ll INF=9e18; int main() { ll N,Q; cin>>N>>Q; vector A (N); vector> hai (N); for (ll a = 0; a < N; a++){ cin>>A[a]; hai[a]={A[a],a+1}; } sort(hai.begin(),hai.end()); vector doko (N+1); ll count=1; for (ll a = 0; a < N; a++){ ll hito=hai[a].second; doko[hito]=count; count++; if(a!=0){ if(A[hai[a-1].second]==A[hito]){ doko[hito]=doko[hai[a-1].second]; } } } for (ll a = 0; a < Q; a++){ ll x,y; cin>>x>>y; ll x_juni=doko[x]; ll y_juni=doko[y]; cout<