#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<bool> vb;
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 const INF = 1 << 30;


int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    int r = 0;
    int ans = -1;
    for(int x = 2; x <= 1100; ++x) {
        int cnt = 0;
        rep(i,n) {
            if(a[i] % x == 0) cnt++;
        }
        if(chmax(r, cnt)) ans = x;
    }
    cout << ans << endl;

    return 0;
}
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
#define inf 0x3f3f3f3f3f3f3f3f
string s;
int dig[65];
ll pow(ll a, ll b) {
	ll res = 1;
	while(b) {
		if(b & 1) res = res * a;
//		if()
		a = a * a;
		
	}
	return res;
} 
int len;
	ll m;
bool solve(ll r) {
	ll sum = 0;
	int f = 1;
	for(int i = 0; i < len; i++) {
		if(inf / r < sum) {
			return false;
		}
		sum = sum * r + dig[i];
		if(sum > m || sum < 0) {
			f = 0;
			break;
		} 
	}
	return f;
}
int main() {
	cin >> s;
	scanf("%lld", &m);
	int d = 0;
	len = s.size();
	for(int i = 0; i < len; i++) {
		d = max(d, s[i] - '0');
		dig[i] = s[i] - '0';
	}
	if(len == 1) {
		printf("%d\n", dig[0] <= m);
		return 0;
	}
	if(!solve(d + 1)) {
		printf("%d\n", 0);
		return 0;
	}
	ll l = d + 1, r = 1e18, mid;
	while(l < r) {
		mid = (l + r + 1) >> 1ll;
		if(solve(mid)) {
			l = mid;
		}
		else {
			r = mid - 1;
		}
	}
	printf("%lld\n", l - d);
} 