#include <bits/stdc++.h>
using namespace std;
const int mm = 1e7;
long long n, k;
int L[1000000];
int tot = 0;
vector<pair<long long, int> > R[10][2];
void dfs(int d, int pre1, int pre2, int cur) {
  L[tot++] = cur;
  if (d == 7) return;
  if (pre1 > pre2) {
    for (int j = pre2 + 1; j < 10; j++) dfs(d + 1, pre2, j, cur * 10 + j);
  } else {
    for (int j = 0; j < pre2; j++) dfs(d + 1, pre2, j, cur * 10 + j);
  }
}
int main() {
  int T;
  for (int i = 1; i < 10; i++) L[tot++] = i;
  for (int i = 1; i < 10; i++)
    for (int j = 0; j < 10; j++)
      if (i != j) dfs(2, i, j, i * 10 + j);
  sort(L, L + tot);
  long long up = 1e14;
  while (cin >> n >> k) {
    if (n % 100 == 0) {
      cout << -1 << endl;
      return 0;
    }
    long long kth = k;
    for (int i = 0; i < tot; i++) {
      if (L[i] % n == 0) kth--;
      if (kth == 0) {
        cout << L[i] << endl;
        return 0;
      }
    }
    for (int i = tot - 1; i >= 0 && L[i] > 1e5; i--) {
      int d1 = L[i] / 1000000;
      int d2 = L[i] / 100000 % 10;
      int d3 = L[i] / 10000 % 10;
      if ((d2 - d1) * (d2 - d3) <= 0) continue;
      int d = d1 > d2;
      R[d1][d].push_back(pair<long long, int>(L[i] % n, L[i]));
    }
    for (int i = 0; i < 10; i++)
      for (int j = 0; j < 2; j++) sort(R[i][j].begin(), R[i][j].end());
    for (int i = 0; i < tot; i++) {
      long long r = (n - L[i] * 10000000ll % n) % n;
      int last1 = L[i] / 10 % 10, last0 = L[i] % 10;
      for (int j = 0; j < 10; j++)
        if (last0 != j) {
          if (L[i] < 10 || (L[i] >= 10 && (last0 - last1) * (last0 - j) > 0)) {
            vector<pair<long long, int> > &v = R[j][j > last0];
            int x = lower_bound(v.begin(), v.end(),
                                pair<long long, int>(r + 1, 0)) -
                    v.begin();
            int y =
                lower_bound(v.begin(), v.end(), pair<long long, int>(r, 0)) -
                v.begin();
            if (kth <= x - y) {
              cout << L[i] * 10000000ll + v[y + kth - 1].second << endl;
              return 0;
            } else
              kth -= x - y;
          }
        }
    }
    cout << -1 << endl;
    return 0;
  }
  return 0;
}
