#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
void read(int &x){
	static char c;
	while(!isdigit(c=getchar())); x=c^48;
	while(isdigit(c=getchar()))x=(x*10)+(c^48);
}
void read(ll &x){
	static char c;
	while(!isdigit(c=getchar())); x=c^48;
	while(isdigit(c=getchar()))x=(x*10)+(c^48);
}
void chkmax(int &x,int y){if(y>x)x=y;}
void chkmin(int &x,int y){if(y<x)x=y;}
void chkmax(ll &x,ll y){if(y>x)x=y;}
void chkmin(ll &x,ll y){if(y<x)x=y;}

int n;

int A[10],tot;

void Work(){
	read(n);
	while(n&&n%10==0) n/=10;
	while(n) A[++tot]=n%10,n/=10;
	for(int i=1;i<=tot/2;++i)
		if(A[i]!=A[tot-i+1]) return puts("No"),void();
	puts("Yes");
}

int main(){Work();}

#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
    #include <atcoder/all>
    using namespace atcoder;
#endif

using namespace std;
using Graph = vector<vector<int>>;
using vst= vector<string>;
using vin= vector<int>;
using ll=long long;
using ull=unsigned long long;
using vll= vector<ll>;
using P=pair<int ,int>;
using pqi=priority_queue<int, vector<int>, greater<int>>;
using pqp=priority_queue<P, vector<P>, greater<P>>;

//const long double pi=acos(-1);
#define ft first
#define sd second
#define fn front
#define pb push_back
#define eb emplace_back
#define it insert
#define vvi vector<vector<int>>
#define si(v) int((v).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sot(x) sort(x.begin(), x.end())
#define rese(x) reverse(x.begin(), x.end())
#define gsot(x) sort(x.begin(), x.end(), greater<ll>());
#define vnn(x,y,s,name) vector<vector<int>> name(x, vector<int>(y,s))
#define mse(x) memset(x, 0, sizeof(x)
#define all(x) (x).begin(),(x).end()
#define mii(x,y,z) min(x,min(y,z))
#define maa(x,y,z) max(x,max(y,z))
#define cps CLOCKS_PER_SEC
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"
#define cset(x) cout<<fixed<<setprecision(x)

const ll INF=(1e18)+(1e17);
const ll ma=(1e18)+100;
//const int INF=1001001001;
//998244353  1000000007

int f(string &x){
    int d=1;
    for(auto c:x){
        if(d<c-'0') d=c-'0';
    }
    return d;
}
ll g(string &x, ll a){
    ll ans=0;
    rep(i,x.size()){
        if((ans)>(ma/a)) return INF;
        ans*=a;
        ans+=(x[i]-'0');
        if(ans>=ma) return INF;
    }
    return ans;
}



int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string x;
    ll m;
    cin>>x>>m;
    ll d=f(x);
    //cout<<g(x,6)<<endl;
    //cout<<d<<endl;
    //cout<<g(x,d+1)<<endl;
    if(g(x,d+1)>m){
        cout<<0<<endl;
        return 0;
    }
    if(x.size()==1){
        cout<<1<<endl;
        return 0;
    }
    ll ok=d+1,ng=m;
    while(ng-ok>1){
        ll mid=(ok+ng)/2;
        if(g(x,mid)>m) ng=mid;
        else ok=mid;
    }
    if(x=="10") cout<<m-1<<endl;
    else cout<<ok-d<<endl;
}


















