#include <bits/stdc++.h>
using namespace std;
  
// p^q
long long sisu(long long p, long long q){
  long long ans = 1;
  for (int i=0; i<q; i++){
    ans *= p;
  }
  return ans;
}

//log(p^q)
int hantei(long long p, long long q){
  return q*log(p);
}

int main(){
  string X_;
  long long M;
  cin >> X_ >> M; 
  int S = X_.size();
  vector<int> X(S);
  for (int i = 0; i<S; i++){
    X.at(i) = (int)X_.at(i) - (int)'0' ; //0番目に最上位桁が収納
  }
  
  int d = 1;
  for (int i=0; i< S; i++){
    if (d < X.at(i)){
      d = X.at(i);
    }
  }
  
  long long m;
  long long D;
  if (S != 1){
    D = 10000 + exp(log((double)M / (double)X.at(0)) / (double)(S-1));
  }else{
    D = X.at(0);
  }
  long long count = D - d;
  if (count > 0){
    
    while (true){
      m=0;
      if ( log((double)X.at(0)) + (double)(S-1)*log((double)D) > log((double)M) ){
        count--;
        D--;
        continue;
      }
      for (int i =0; i<S; i++){
        m += X.at(i)*sisu(D,S-i-1);
      }
      if (M >= m)break;
      count--;
      D--;
    }
    
  }
  if (count < 0){
    count = 0;
  }
  if (S == 1){
    if (X.at(0) <= M){
      count = 1;
    }else{
      count = 0;
    }
  }
  cout << count << endl;
}
/*
{
######################
#       Author       #
#        Gary        #
#        2020        #
######################
*/
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
int n;
vector<int> v[2];
LL rest=0;
int a[100000+20],b[100000+20];
int main(){
	cin>>n;
	rb(i,1,n)
	{
		cin>>a[i];
		rest+=a[i];
	}
	rb(i,1,n)
	{
		cin>>b[i];
		v[i&1].PB(b[i]-a[i]);
	}
	sort(ALL(v[0]));
	sort(ALL(v[1]));
	LL MAX=0;
	LL sum=0; 
	reverse(ALL(v[0]));
	reverse(ALL(v[1]));
	rep(i,n/2){
		sum+=v[0][i]+v[1][i];
		check_max(MAX,sum);
	}
	rest+=MAX;
	cout<<rest<<endl;
	return 0;
}
/** 程序框架：
  *
  *
  *
  *
  **/
