#pragma GCC optimize("O3")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#define re return
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define PI 3.14159265358979323846
#define E 2.71828182845904523536
#define er erase
#define in insert
#define fo(i,n) for((i)=0;(i)<(n);(i)++)
#define ro(i,n) for((i)=n-1;(i)>=0;(i)--)
#define fr(i,j,n) for((i)=(j);(i)<(n);(i)++)
#define rf(i,j,n) for((i)=((n)-1);(i)>=(j);(i)--)
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
void eras(map<int,int> &m,int x)
{
    m[x]--;
    if (!m[x])
        m.erase(x);
}
const int N=(int)3e5+100;
const int M=(int)2e6+100;
const int inf=(int)1e9+100;
#define filename ""
    vector<int> prost;
    vector<int> v;
    bool was[73][(1<<20)];
    ll table[73][(1<<20)];
ll f(int x,int mask)
{
    if (x==v.size()) re 1;
    if (was[x][mask]) re table[x][mask];
    was[x][mask]=1;
    ll o=f(x+1,mask);
    if ((mask&v[x])==0) o+=f(x+1,mask|v[x]);
    re table[x][mask]=o;
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen(filename".in","r",stdin);
    //freopen(filename".out","w",stdout);
    //freopen("ans.txt","w",stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll a,b;
    int i,j;
    for(i=2;i<72;i++)
    {
        for(j=2;j<i;j++)
        {
            if (i%j==0) break;
        }
        if (j==i)
        {
            prost.pb(j);
        }
    }
    cin>>a>>b;
    while(a<=b)
    {
        int mask=0;
        fo(i,prost.size())
        {
            j=prost[i];
            if (a%j==0)
            {
                mask|=(1<<i);
            }
        }
        v.pb(mask);
        a++;
    }
    cout<<f(0,0);
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
int n,k;
cin>>n>>k;
for(int i=0;i<k;i++){
string s = to_string(n);
sort(s.begin(),s.end());
string s1 = s;
sort(s.rbegin(),s.rend());
string s2 = s;
n = stoi(s2) - stoi(s1);
}
cout<<n;
}
