#include <bits/stdc++.h>
using namespace std;
//long long n, p, d;
typedef long long ll;
ll n, p, d;
int main()
{
    freopen("boi.inp","r",stdin);
    freopen("boi.out","w",stdout);
    cin>>p>>n;
    d = 9%p;
    for (ll i = 1; i<=n; i++)
    {
        if (d==0)
        {
            cout<<n/i;
            return 0;
        }
        d = (d*10+9)%p;
    }
cout<<0;
    return 0;
}
