/*

  AUTHOR:    nit1n
  CREATED:   21.03.2021 21:41:12

*/
#include<bits/stdc++.h>
#define int long long
using namespace std ;


signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ;

	int n ; 
	cin >> n ;
	int l = 0 , h = 1e6 +10 ;
	while(l<h){
		int mid = (l+h)/2 ;
		string s = to_string(mid) + to_string(mid) ;
		int m = stoll(s) ;
		if( m >=n){
  			h = mid ; 
		}else{
			l = mid + 1; 
		}
	}
	string s = to_string(h) + to_string(h) ; 
	int m = stoll(s) ; 
	if(m > n){
		h-- ; 
	}
	cout << h ;
}

#include<bits/stdc++.h>
#define int long long
#define rint regester int
const int maxn = 1e6 + 10;
const int INF = 1e9;
using std::ios;
using std::cin;
using std::cout;
using std::max;
using std::min;
using std::sort;
using std::unique;
using std::lower_bound;
using std::swap;
using std::abs;
using std::acos;
using std::queue;
using std::map;
using std::string;
int read(){int x = 0,f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){if(ch == '-')f = -1; ch = getchar();}while(ch >= '0' && ch <= '9'){x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar();} return x * f;}
int n, a[maxn], q, k;//find i -->> a_i < k + i < a_{i+1} 
signed main(){
	n = read(), q = read();
	for(int i = 1; i <= n; i++)a[i] = read();
	while(q--){
		k = read();
		int l = 0, r = n, mid, ans = 0;
		while(l <= r){
			mid = (l + r) >> 1;
			if(k + mid <= a[mid]){
				r = mid - 1;
			}else
			if(k + mid >= a[mid + 1]){
				l = mid + 1;
			}else
			{ans = mid; break;}
		}
		cout << mid + k << "\n";
	}
}