#include <bits/stdc++.h>
using namespace std;
long long n, k;
vector<pair<long long, long long> > left_, rightInc, rightDec;
const int MAX = 9999999;
int lastCmp = 0;
bool isWavy(long long n) {
  int lastDigit = n % 10;
  n /= 10;
  lastCmp = 0;
  while (n) {
    int curDigit = n % 10;
    n /= 10;
    if (curDigit == lastDigit) return false;
    int curCmp = (curDigit > lastDigit) ? 1 : -1;
    if (curCmp == lastCmp) return false;
    lastDigit = curDigit;
    lastCmp = curCmp;
  }
  return true;
}
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(NULL);
  cout << (fixed) << setprecision(6);
  while (cin >> n >> k) {
    left_.clear();
    rightInc.clear();
    rightDec.clear();
    bool foundSolution = false;
    for (int i = (1), _b = (MAX); i <= _b; i++) {
      if (isWavy(i)) {
        if (i % n == 0) {
          --k;
          if (k == 0) {
            cout << i << endl;
            foundSolution = true;
            break;
          }
        }
        if (i >= MAX / 10) {
          if (lastCmp == 1)
            rightDec.push_back(make_pair(i % n, i));
          else
            rightInc.push_back(make_pair(i % n, i));
        } else if (i >= MAX / 100 && lastCmp == 1)
          rightInc.push_back(make_pair(i % n, i));
        left_.push_back(make_pair(i % n, i));
      }
    }
    sort(rightInc.begin(), rightInc.end());
    sort(rightDec.begin(), rightDec.end());
    if (foundSolution) continue;
    long long found = 0;
    for (int i = 0, _a = (left_.size()); i < _a; i++) {
      long long xmod = (left_[i].first * 10000000LL) % n;
      long long ymod = (n - xmod) % n;
      int leftLastDigit = left_[i].second % 10;
      int leftPrevDigit = (left_[i].second % 100) / 10;
      if (left_[i].second < 10 || leftPrevDigit < leftLastDigit) {
        long long lb = 0 * 1000000LL, ub = (leftLastDigit)*1000000LL - 1;
        auto from =
            lower_bound(rightInc.begin(), rightInc.end(), make_pair(ymod, lb));
        auto to =
            lower_bound(rightInc.begin(), rightInc.end(), make_pair(ymod, ub));
        if (from != rightInc.end() && from->first == ymod &&
            lb <= from->second && from->second <= ub) {
          int cur = to - from;
          if (cur >= k) {
            cout << (left_[i].second * 10000000LL) + (from + k - 1)->second
                 << endl;
            foundSolution = true;
            break;
          } else
            k -= cur;
        }
      }
      if (left_[i].second < 10 || leftPrevDigit > leftLastDigit) {
        long long lb = (leftLastDigit + 1) * 1000000LL, ub = 10 * 1000000LL;
        auto from =
            lower_bound(rightDec.begin(), rightDec.end(), make_pair(ymod, lb));
        auto to =
            lower_bound(rightDec.begin(), rightDec.end(), make_pair(ymod, ub));
        if (from != rightDec.end() && from->first == ymod &&
            lb <= from->second && from->second <= ub) {
          int cur = to - from;
          if (cur >= k) {
            cout << (left_[i].second * 10000000LL) + (from + k - 1)->second
                 << endl;
            foundSolution = true;
            break;
          } else
            k -= cur;
        }
      }
      if (foundSolution) break;
    }
    if (!foundSolution) cout << -1 << endl;
  }
  return 0;
}
