import java.util.*;
import java.io.*;

import static java.lang.Math.min;

public class division_nb_java {
    FastScanner in;
    PrintWriter out;

    public static int MAXL = 14, SQRT = (int) 3e5;

    public void solve() throws IOException {
        long n = in.nextLong();
        long m = in.nextLong();

        ArrayList <Integer> vn = new ArrayList<Integer>();

        long tmp = n;
        while (tmp != 0) {
            vn.add((int) (tmp % 10));
            tmp /= 10;
        }

        if (vn.size() == 1) {
            if (n % m == 0) {
                out.println(n);
            } else {
                out.println(0);
            }
            return;
        }        

        if (m > SQRT) {        
            long ans = -1;
            int best = 100;
            for (int i = 0; ; ++i) {
                tmp = m * i;
                ArrayList <Integer> v = new ArrayList<Integer>();
                while (tmp != 0) {                
                    v.add((int) (tmp % 10));
                    tmp /= 10;
                }
                if (v.size() > vn.size()) {
                    break;
                }
                if (v.size() < vn.size()) {
                    continue;
                }
                int bal = 0;
                for (int j = 0; j < v.size(); ++j) {
                    int num1 = v.get(j);
                    int num2 = vn.get(j);
                    if (num1 != num2) {
                        ++bal;
                    }
                }
                if (best > bal) {
                    best = bal;
                    ans = i * m;
                }
            }
            out.println(ans);
        } else {
            int m2 = (int) m;
            int[][][] d = new int[2][vn.size() + 1][m2];
            for (int i = 0; i <= vn.size(); ++i) {
                for (int j = 0; j < m2; ++j) {
                    d[0][i][j] = 100;
                    d[1][i][j] = -1;
                }
            }
            d[0][0][0] = 0;
            d[1][0][0] = -1;
            for (int i = 1; i <= vn.size(); ++i) {            
                int start = 0;
                if (i == vn.size()) {
                    start = 1;
                }
                int rem = 1;
                for (int j = 0; j < i - 1; ++j) {
                    rem = (rem * 10) % m2;
                }
                for (int j = start; j < 10; ++j) {
                    for (int k = 0; k < m2; ++k) {
                        int tmp2 = d[0][i - 1][k];
                        if (j != vn.get(i - 1)) {
                            ++tmp2;
                        }
                        int q = (k + j * rem) % m2;
                        if (d[0][i][q] > tmp2) {
                            d[0][i][q] = tmp2;
                            d[1][i][q] = j;
                        }
                    }
                }
            }
            if (d[0][vn.size()][0] == 100) {
                out.println(-1);
                return;
            }
            
            ArrayList <Integer> ans = new ArrayList<Integer>();

            int rem = 0;
            for (int i = vn.size(); i > 0; --i) {
                int now = 1;
                for (int j = 0; j < i - 1; ++j) {
                    now = (now * 10) % m2;
                }
                ans.add(d[1][i][rem]);
                rem = (rem - now * d[1][i][rem]) % m2;
                if (rem < 0) {
                    rem += m2;
                }
            }

            for (Integer an : ans) {
                out.print(an);
            }
            out.println();
        }
    }

    public void run() {
        try {
            in = new FastScanner(new File("division.in"));
            out = new PrintWriter(new File("division.out"));

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }

    public static void main(String[] arg) {
        new division_nb_java().run();
    }
}