#include using namespace std; using ll = long long; using ld = long double; #ifdef LOCAL #include #else #define debug(...) void(0) #endif #include using namespace atcoder; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, Q; cin >> N >> Q; vector A(N); for(int i = 0; i < N; i++) cin >> A[i]; vector B(N); copy(A.begin(), A.end(), B.begin()); sort(B.begin(), B.end()); B.erase(unique(B.begin(), B.end()), B.end()); map ord; for(int i = 0; i < int(B.size()); i++) ord[B[i]] = i; map idx; for(int i = 0; i < N; i++) idx[i] = ord[A[i]]; while(Q--) { int x, y; cin >> x >> y; x--; y--; if(idx[x] <= idx[y]) cout << 0 << endl; else { cout << (idx[x] - idx[y] - 1) << endl; } } }