#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main(int argc, char** argv) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,q;
	cin >>n>>q;
	vector<int> v(n);
	for(int i=0;i<n;i++)
	{
		cin >>v[i];
	}
	sort(v.begin(),v.end());
	
	for(int z=0;z<q;z++)
	{
		int x;
		cin >>x;
		bool postoji=false;
		
		int l=0,r=n-1;
		while(l<=r)
		{
			int s=l+(r-l)/2;
			if(v[s]==x)
			{
				postoji=true;
				r=s-1;
			}
			else if(v[s]>x)
			{
				r=s-1;
			}
			else
			{
				l=s+1;
			}
		}
		
		//cout <<l<<" "<<r<<"\n";
		if(postoji)
		{
			int l2=l,r2=n-l-1;
			int mn=min(abs((l2-1)-r2),abs(l2-r2));
			l++;
			while(v[l]==x && l<n)
			{
				l2=l;
				r2=n-l-1;
				int h=min(abs((l2-1)-r2),abs(l2-r2));
				if(mn<h)
				{
					break;
				}
				else
				{
					mn=h;
				}
				l++;
			}
			cout <<mn<<"\n";
			
		}
		else
		{
			if(l==n)
			{
				cout <<n<<"\n";
			}
			else if(r==-1)
			{
				cout <<n+1<<"\n";
			}
			else
			{
				int l2=l,r2=n-l;
				cout <<min(abs((l2-1)-r2),abs(l2-r2))<<"\n";
			}
		}
		
	}
	return 0;
}