#include // clang-format off using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair; const ll INF=4e18; void print0(){}; template void print0(H h,T... t){cout<void print1(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print1(t...);} void ioinit() { cout<> N >> Q; vector A(N); for (ll i = 0; i < N; i++) { cin >> A[i].first; A[i].first = 1000000000 - A[i].first; A[i].second = i; } sort(A.begin(), A.end()); vector player_id(N); for (ll i = 0; i < N; i++) { player_id[A[i].second] = i; } while (Q--) { ll x, y; cin >> x >> y; x--; y--; ll px = player_id[x]; ll py = player_id[y]; ll ax = A[px].first; ll ay = A[py].first; ll fr = lower_bound(A.begin(), A.end(), pll{ax, INF}) - A.begin(); ll bk = lower_bound(A.begin(), A.end(), pll{ay, -1}) - A.begin(); print1(max(bk - fr, 0ll)); } return 0; }