#include <bits/stdc++.h>
#define ll long long

using namespace std;

int cnt[100000000] = {0};
int ind[100000000] = {0};

void spoj(ll a[], ll l, ll k, ll r) {
    int n1 = k - l + 1;
    int n2 = r - k;

    int a1[n1], a2[n2];

    for(int i=0; i<n1; i++)
        a1[i] = a[i + l];
    for(int i=0; i<n2; i++)
        a2[i] = a[k + i + 1];

    int i1 = 0, i2 = 0, sp = l;

    while(i1 < n1 && i2 < n2) {
        if(a1[i1] <= a2[i2]) {
            a[sp] = a1[i1];
            i1++;
        } else {
            a[sp] = a2[i2];
            i2++;
        }
        sp++;
    }

    while(i1 < n1) {
        a[sp] = a1[i1];
        i1++;
        sp++;
    }

    while(i2 < n2) {
        a[sp] = a2[i2];
        i2++;
        sp++;
    }
}

void mergeSort(ll a[], ll l, ll r) {
    if(l >= r) return;

    ll mid = l+(r-l)/2;
    mergeSort(a, l, mid);
    mergeSort(a, mid+1, r);
    spoj(a, l, mid, r);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    ll n, q;
    cin >> n >> q;

    ll a[n+1];

    int i;
    for(i=1; i<=n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
        ind[a[i]] = i;
    }

    ll b;

    mergeSort(a, 1, n);
    
    int med = n/2 + 1;

    for(int i=1; i<=n; i++) {
        if(abs(med - i) < ind[a[i]]) ind[a[i]] = i;
    }

    for(i=0; i<q; i++) {
        cin >> b;

        if(a[med] == b) {
            cout << "0" << endl;
            continue;
        }

        if(!cnt[b]) {
            if(b < a[med]) cout << n+1 << "\n";
            else if(b > a[med]) cout << n << "\n";
        }
        else {
            if(ind[b] == 1 || ind[b] == n) cout << n-1 << endl;
            else cout << abs(med - ind[b]) << endl;
        }
    }

    return 0;
}