#include<bits/stdc++.h>
using namespace std;  
#define pb push_back 
#define ppb pop_back 
#define make make_pair
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long int ll;
typedef double dd;
#define test int t;cin>>t;while(t--)
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fr(j,a,b) for(ll j=a;j>=b;j--)
#define ln cout<<"\n";
#define se second
#define fi first
#define vll vector<ll>
using namespace std;
const ll mod=1e9+7;
const ll MAX=LLONG_MAX;
const ll MIN=LLONG_MIN;
int main()
{FAST;

ll n,q;
cin>>n>>q;
ll a[n];
f(i,0,n)
cin>>a[i];
ll pref[n];
for(ll i=0;i<n;i++)
{
    if(i==0)
    {
        pref[i]=a[i]-1;
    }
    else
    {
        pref[i]=a[i]-1-(i);
    }
    
}
while(q--)
{
    ll x;
    cin>>x;
    if(x>pref[n-1])
    {
        cout<<a[n-1]+(x-pref[n-1])<<"\n";
    }
    else
    {
        ll k=lower_bound(pref,pref+n,x)-pref;
        
        ll ans=(a[k]-1)-(pref[k]-x);
        cout<<ans<<"\n";
    }
}

return 0;
}
#include <bitset>
#include <iostream>
#include <climits>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <math.h>


using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef vector<vector<ll>> vvll;


#define mp(x, y) make_pair(x, y)

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define repm(i, n) for(int i=n; i >= 0; i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える

//nが素数かをO(√n)で判断
bool is_prime(int n) {
    bool res = true;

    if (n == 1) return false;
    else if (n == 2) return true;

    else {
        for (int i = 2; i * i <= n; i++) {
            if (n % i == 0) {
                res = false;
                break;
            }
        }
    }

    return res;
}



int perm(int n, int r) {
    if (r == 1) return n;
    return n * perm(n - 1, r - 1);
}

int fact(int n) {
    if (n == 1) return 1;
    return fact(n - 1) * n;
}

int comb(int n, int r) {
    int a = min(n, r), b = max(n, r);
    return perm(a, b) / fact(a);
}





//aの逆元　（a^(-1)）を求める
ll inv_mod(ll a, ll mod) {
    ll b = mod, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}

//n!
ll fact_mod(ll n, ll mod) {
    ll f = 1; for (int i = 2; i <= n; i++) f = f * (i % mod) % mod;
    return f;
}

ll pow_mod(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = (res * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return res;
}

ll my_pow(ll x, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = (res * x);
        x = (x * x);
        n >>= 1;
    }
    return res;
}

// nCr
ll comb_mod(ll n, ll r, ll mod) {
    if (r > n - r) r = n - r;
    if (r == 0) return 1;
    ll a = 1;
    for (int i = 0; i < r; i++) a = a * ((n - i) % mod) % mod;
    ll b = pow_mod(fact_mod(r, mod), mod - 2, mod);
    return (a % mod) * (b % mod) % mod;
}

//bool v included in S
bool contain(int v, int s) {
    return s & (1 << v);
}


//unionFind

/*
int n;

struct unionFind{
  vector<int> par,R;

  unionFind(int n){
    par.resize(n);
    r.resize(n);
    init(n);
  }

  void init(int n){
    for(int i = 0; i < n; i++) par[i] = i;
    for(int i = 0; i < n; i++) R[i] = 0;
  }

  int find(int x){
    if(par[x] == x) return x;
    else return find(par[x]);
  }

  void unite(int x,int y){
    rx = find(x);
    ry = find(y);


    if(rx == rx) return;
    if(R[rx] < R[ry]){
      par[rx] = y;
    }else{
      par[ry] = rx;
      if(R[rx] == R[ry]) R[rx]++;
    }
  }

  bool same(int x,int y){
    return find(x) == find(y);
  }
};
*/

#define P pair<int, int>


//int: 2,147,483,647;
//ll 9,223,372,036,854,775,80
//小数点以下15コまで出力
//cout << fixed << setprecision(15);

const int INF = 1e9;
const ll LINF = 1e18;                           

int main() {
    ll N;
    cin >> N;
    
    for (ll b = 1; b <= 26; b++) {
        if (my_pow(5, b) >= N) break;

        for (ll a = 1; a <= 38; a++) {
            if (my_pow(3, a) + my_pow(5, b) > N) break;
            if (my_pow(3, a) + my_pow(5, b) == N) {
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }

    cout << -1 << endl;

    return 0;
}