#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(void){
  int n,k,m; cin >> n >> k >> m;
  int a[n-1];
  int sum = 0;
  FOR(i,0,n-2) {
    cin >> a[i];
    sum += a[i];
  }

  if(n*m-sum<=k) cout << max(0,n*m-sum) << endl;
  else cout << -1 << endl;

}
#include<bits/stdc++.h>
#include<chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long int
#define FOR(I,a,b) for(ll I=a;I<b;I++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(I,a,b) for(int I=a;I>=b;I--)
#define vec vector
#define vi vec<int>
#define vll vec<ll>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define testcases ll tc;cin>>tc;while(tc--)
#define mem(a,k) memset(a,k,sizeof(a))
#define FF first
#define SS second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<ll,ll>
#define vecin(a,n,index) for(int I=index;I<n;I++)cin>>a[I]
#define vecout(a,n,index) for(int I=index;I<n;I++)cout<<a[I]<<" ";cout<<endl;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// ll mod = 1000000007;
// int max_size = 1000001;
// vi sv(max_size, 1);
// vi primes;
// void sieve();
// ll power(ll a, ll b);
// ll powerMod(ll a, ll b, ll mod);
// ll modIn(ll n);
// vll fact(200001);
ll val(char c) {
	if (c >= '0' && c <= '9')
		rt (ll)c - '0';
	else
		rt (ll)c - 'A' + 10;
}
ll toDecimal(string s, ll base) {
	ll l = s.length();
	ll power = 1;
	ll res = 0;
	ROF(i, l - 1, 0) {
		if (val(s[i]) >= base) {
			rt - 1;
		}
		// cout << power << endl;
		if (res > 1e18 - (val(s[i])*power))rt - 1;
		res += val(s[i]) * power;
		if (power > (1e18 + base - 1) / base && i >= 1)rt - 1;
		power = power * base;
	}
	rt res;
}
bool fun(string x, ll n, ll m) {
	if (toDecimal(x, n) != -1  && toDecimal(x, n) <= m )rt true;
	rt false;
}
void solve() {
	string x;
	ll m;
	cin >> x >> m;
	string k = x;
	sort(all(k));
	int d = k[k.size() - 1] - 48;
	if (x.length() == 1) {
		if (x[0] - 48 <= m)cout << "1\n";
		else cout << "0\n";
		rt;
	}
	ll L = d + 1, H = 1e18, res = 0;

	while (L <= H) {
		ll mid = (L + H) / 2;
		// cout << res << endl;
		if (fun(x, mid, m)) {
			res = mid;
			L = mid + 1;
		}
		else H = mid - 1;
	}
	cout << max(0LL, res - d) << endl;

}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// testcases
	solve();
}



/*void sieve() {
	sv[0] = 0; sv[1] = 0;
	for (int i = 2; i * i <= max_size; i++) {
		if (sv[i]) {
			for (int j = i * i ; j <= max_size; j += i) {
				sv[j] = 0;
			}
		}
	}
}*/

/*ll power(ll a , ll b) {
	ll res = 1;
	while (b) {
		if (b % 2) {res *= a; b--;}
		else {a *= a; b /= 2;}
	}
	rt res;
}*/
/*
ll powerMod(ll a, ll b, ll mod) {
	ll res = 1;
	while (b != 0) {
		if (b % 2) {
			res = (res % mod * a % mod) % mod;
			b--;
		}
		else {
			a = (a % mod * a % mod) % mod;
			b /= 2;
		}
	}
	rt res % mod;
}*/
/*
ll modIn(ll n) {rt powerMod(n, mod - 2) % mod;}
*/