#include "bits/stdc++.h"
#define puba push_back
#define mapa make_pair
#define ff first
#define ss second
#define bend(_x) (_x).begin(), (_x).end()
#define szof(_x) ((int) (_x).size())

using namespace std;
typedef long long ll;
typedef double dbl;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
const int MAXL = 13, SQRT = 1e6;

ll n, m;

pii d[MAXL][SQRT];

int main() {    
    freopen("division.in", "r", stdin);
    freopen("division.out", "w", stdout);
   
    cin >> n >> m;
    

    ll s = (int) sqrt(n);

    vector <int> vn;
    ll tmp = n;
    while (tmp) {
        vn.puba(tmp % 10);
        tmp /= 10;
    }

    ll ans = -1;
    int best = 100;
    for (int i = 0; ; ++i) {
        ll tmp = m * i;
        vector <int> v;
        while (tmp) {                
            v.puba(tmp % 10);
            tmp /= 10;
        }
        if (szof(v) == 0) {
            v.puba(0);
        }
        if (szof(v) > szof(vn)) {
            break;
        }
        if (szof(v) < szof(vn)) {
            continue;
        }
        int bal = 0;
        for (int j = 0; j < szof(v); ++j) {
            if (v[j] != vn[j]) {
                ++bal;
            }
        }
        if (best > bal) {
            best = bal;
            ans = i * m;
        }
    }
    cout << ans << endl;


    return 0;
}                                    