#include <iostream>
#include <algorithm>

using namespace std;

const int MAXN = 3001;
int n, q;
int cat[MAXN], inc[MAXN], cnt[MAXN];

int query(int l, int r) {
    fill(cnt, cnt + MAXN, 0);
    for (int i = l; i < r; ++i)
        cnt[cat[i]] += inc[i];
    return max_element(cnt, cnt + MAXN) - cnt;
}
int main() {
    ios::sync_with_stdio(false);
    cin >> n >> q;
    for (int i = 0; i < n; ++i)
        cin >> cat[i];
    for (int i = 0; i < n; ++i)
        cin >> inc[i];
    while (q--) {
        int l, r;
        cin >> l >> r;
        --l;
        cout << query(l, r) << endl;
    }
    return 0;
}
