// D - Base n
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

string X;
ll M;

string f(ll n){
	ll m = M;
	string res = "";
	while(m){
		ll r = m % n; m = m / n;
		res += r <= 9? to_string(r): "a";
	}
	reverse(res.begin(), res.end());
	return res;
}

bool check(ll n){
	string m = f(n);
	if(X.size() > m.size()) return false;
	else if(X.size() < m.size()) return true;
	for(int i=0; i<(int)X.size(); ++i)
		if(X[i] < m[i]) return true;
		else if(X[i] > m[i]) return false;
	return true;
}

int main(){
	cin>>X>>M;
	if(X.size() == 1){ cout<< (stoi(X) <= M) <<endl; return 0; }
	int d = 0;
	for(auto c:X) d = max(d, c-'0');
	ll ok = d, ng = M + 1;
	while(ng - ok > 1){
		ll n = (ng + ok) / 2;
		(check(n)? ok:ng) = n;
	}
	cout<< ok - d <<endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
void solve(){
  int a,b;
  cin>>a>>b;
  int sum1 =0;
  int sum2 =0;
  while(a){
      int r1 = a%10;
 
    sum1+=r1; 
    a/=10;
 
  }
 
    while(b){
     int r2 = b%10;
 
    sum2 +=r2;
    b/=10;}
	if (sum1>sum2)
  cout<<sum1<<endl;
  else cout<<sum2<<endl;
}
 
signed main(){
  IOS
  solve();
  return 0;
}