#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <climits>
#include <string>
#include <cmath>
#include <stack>
#include <functional>
#include <list>
#include <array>
#include <queue>
#include <bitset>
#include <ciso646>
#include <fstream>
#include <string.h>
using namespace std;

#define db(x) cout << #x << " " << (x) << "\n";
const int mod1 = 1000000007;
const int mod2 = 1000000009;
#define inf LLONG_MAX
#define n_inf LLONG_MIN
#define all(x) x.begin(), x.end()
#define sorta(x) sort(all(x))
typedef long long int ll;
template<typename... T>
void read(T&... args)
{
    ((cin >> args), ...);
}
template<typename... T>
void write(T&&... args)
{
    ((cout << args << " "), ...);
}
#define w(t)       \
    int t;         \
    std::cin >> t; \
    while (t--)

#define FastIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);




void solve(int test_case = 0)
{
    int n; cin>>n;
    vector<ll> A(n);
    for(int i=0; i<n; i++)
    {
        cin>>A[i];
    }
    ll curr = 0, max_inc = 0, last_inc = 0, max_possible = 0;
    for(int i=0; i<n; i++)
    {
        max_inc = max(max_inc, last_inc + A[i]);
        max_possible = max(max_possible, curr + max_inc);
        curr += last_inc + A[i];
        last_inc += A[i];
    }
    cout<<max_possible;
    
}



int main()
{
    FastIO;
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    int test_case = 1, i = 0;
    //cin>>test_case;
    while (test_case--)
    {
        i++;
        solve(i);
    }
}

#include <bits/stdc++.h>

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.14159265359;

template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }

int main()
{ 
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N, Q; cin >> N >> Q;
    vl A(N); REP(i, N) cin >> A[i];    
    vl K(Q); REP(i, Q) cin >> K[i];

    sort(ALL(A));
    vl s;
    vl t;
    t.pb(0);
    if(A[0] != 1)
    {
        s.pb(1);
        t.pb(A[0]-1);
    }
    REP(i, N-1)
    {
        if(A[i]+1 != A[i+1]) s.pb(A[i]+1), t.pb(A[i+1]-A[i]-1);
    }
    s.pb(A[N-1]+1);
    t.pb((ll)2e18);

    
    REP(i, (int)t.size()-1) t[i+1] += t[i];

    REP(i, Q)
    {
        int idx = lower_bound(ALL(t), K[i]) - t.begin() -1;
        cout << s[idx]+K[i]-1-t[idx] << endl;
    }
}