#include <bits/stdc++.h>
using namespace std;
const int mid = 10000000;
int fx(long long x) { return x < 0 ? -1 : x > 0; }
int isnumber(long long n) {
  if (n < 10) {
    return 1;
  }
  if (n < 100 && n % 10 != n / 10) {
    return 1;
  }
  while (n) {
    int de = fx(n % 10 - n / 10 % 10);
    if (de != 0 && (n < 100 || de + fx(n / 10 % 10 - n / 10 / 10 % 10) == 0)) {
      n /= 10;
      continue;
    } else
      return 0;
  }
  return 1;
}
vector<int> lower, higher;
int mapping[mid + 5];
int coun[1000000][10][2];
void getlower(int n, int cent) {
  if (cent < 7) {
    if (cent == 0)
      for (int i = 0; i < 10; i++) {
        getlower(n * 10 + i, cent + 1);
      }
    else {
      if (n < 10) {
        for (int i = 0; i < 10; i++)
          if (i != n) getlower(n * 10 + i, cent + 1);
      } else if (n % 10 < n / 10 % 10) {
        for (int i = n % 10 + 1; i < 10; i++) getlower(n * 10 + i, cent + 1);
      } else
        for (int i = 0; i < n % 10; i++) getlower(n * 10 + i, cent + 1);
    }
  } else
    lower.push_back(n);
}
int main() {
  long long n, k;
  cin >> n >> k;
  if (n >= mid) {
    for (long long i = n; i <= (long long)mid * mid; i += n) {
      if (isnumber(i) && !(--k)) {
        cout << i << endl;
        return 0;
      }
    }
    printf("-1\n");
  } else {
    for (int i = 1; i < mid; i++) {
      if (isnumber(i)) {
        higher.push_back(i);
        if (i % n == 0 && !(--k)) {
          cout << i << endl;
          return 0;
        }
      }
    }
    getlower(0, 0);
    int L = lower.size();
    memset(mapping, -1, sizeof(mapping));
    for (int i = 0; i < L; i++) {
      mapping[lower[i] % n] = 1;
    }
    int top = 0;
    for (int i = 0; i < n; i++) {
      if (mapping[i] != -1) {
        mapping[i] = top++;
      }
    }
    for (int i = 0; i < L; i++) {
      int x = lower[i];
      coun[mapping[x % n]][x / (mid / 10)][max(fx(x % 10 - x / 10 % 10), 0)]++;
    }
    int L2 = higher.size();
    int mo = mid % n;
    for (int i = 0; i < L2; i++) {
      int x = mapping[(n - (long long)higher[i] * mo % n) % n];
      if (x != -1) {
        for (int d = 0; d < 10; d++) {
          int de = fx(d - higher[i] % 10);
          if (de != 0 && (higher[i] < 10 ||
                          fx(higher[i] / 10 % 10 - higher[i] % 10) == de)) {
            int res = coun[x][d][max(de, 0)];
            if (res < k)
              k -= res;
            else {
              for (int j = 0; j < L; j++) {
                long long num = (long long)higher[i] * mid + lower[j];
                if (num % n == 0 && lower[j] / (mid / 10) == d &&
                    isnumber(num) && !(--k)) {
                  cout << num << endl;
                  return 0;
                }
              }
            }
          }
        }
      }
    }
    printf("-1\n");
  }
  return 0;
}
