#include <iostream>
using namespace std;
void swap(int* arr, int a, int b) {
    int z = arr[a];
    arr[a] = arr[b];
    arr[b] = z;
}
int findSpot(int* arr, int start, int end, int el, bool* e) {
    if (end <= start) {
        if (arr[start] != el) return start + 1;
        else return start;
    }
    int l = start + 1;
    int h = end;
    int search = arr[start];
    while (l <= h) {
        while (l < end && arr[l] < search) l++;
        while (h >= start && arr[h] > search) h--;
        if (arr[l] == search || arr[h] == search) *e = true;
        if (l < h)
            swap(arr, l++, h--);
        else
            l++;
    }
    swap(arr, start, h);
    if (arr[h] > el) return findSpot(arr, start, h - 1, el, e);
    else if (arr[h] < el) return findSpot(arr, h + 1, end, el, e);
    return h;
}
int main()
{
    int N, Q;
    int A[20000];
    int B[20000];
    cin >> N >> Q;
    bool exists = false;
    for (int i = 0; i < N; i++)
        cin >>A[i];
    for (int i = 0; i < Q; i++) {
        cin >> B[i];
    }
    for (int i = 0; i < Q; i++) {
        bool e = false;
        int spot = findSpot(A, 0, N - 1, B[i],&e);
        int l = N;
        if (!e)l++;
 
        int right = l - 1 - spot;
        int left = spot;
        if (right == left) spot = 0;
        else if (right > left) spot = right - left - 1;
        else spot=left-right - 1;
        
        cout << spot << endl;
    }
    return 0;
}