#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;
vector<pair<int, int> > headd[10][2];
bitset<10000000> used;
int ad[10000000];
bool valid(long long x) {
  int lt = x % 10;
  x /= 10;
  int flag = 0;
  while (x) {
    int tmp = x % 10;
    x /= 10;
    if (tmp < lt) {
      if (flag == -1) return false;
      flag = -1;
    } else if (tmp > lt) {
      if (flag == 1) return false;
      flag = 1;
    } else
      return false;
    lt = tmp;
  }
  return true;
}
int check(int st, long long N, int ud, long long& K, long long need) {
  if (need >= 10000000) return -1;
  int ker = lower_bound((headd[st][ud]).begin(), (headd[st][ud]).end(),
                        make_pair((int)need, 0)) -
            headd[st][ud].begin();
  int ker2 = lower_bound((headd[st][ud]).begin(), (headd[st][ud]).end(),
                         make_pair((int)need + 1, 0)) -
             headd[st][ud].begin();
  if (ker2 - ker < K) {
    K -= ker2 - ker;
    return -1;
  }
  for (int i = (ker); i < (((int)(headd[st][ud]).size())); ++i) {
    K--;
    if (K == 0) return headd[st][ud][i].second;
  }
  return -1;
}
int main() {
  long long N, K;
  cin >> N >> K;
  if (N > (1e14 + 3) / K) {
    puts("-1");
    return 0;
  }
  if (N > 10000000) {
    for (long long now = N; now < 100000000000000LL; now += N) {
      if (valid(now)) {
        K--;
        if (!K) {
          cout << now << endl;
          return 0;
        }
      }
    }
    cout << -1 << endl;
    return 0;
  }
  int tmp[8] = {};
  for (int i = (1); i < (10000000); ++i) {
    tmp[0]++;
    int now = 0;
    while (tmp[now] == 10) {
      tmp[now] = 0;
      now++;
      tmp[now]++;
    }
    bool err = 0;
    for (int j = (1); j < (6); ++j) {
      if ((tmp[j] - tmp[j - 1]) * (tmp[j] - tmp[j + 1]) <= 0) {
        err = 1;
        break;
      }
    }
    if (!err) {
      headd[tmp[6]][(tmp[6] < tmp[5]) ? 1 : 0].push_back(make_pair(i % N, i));
    }
  }
  for (int i = 0; i < (10); ++i)
    for (int j = 0; j < (2); ++j)
      sort((headd[i][j]).begin(), (headd[i][j]).end());
  for (long long now = 1; now < 10000000; now++) {
    if ((now / 10) % 10 == now % 10) continue;
    int ha = ((now / 10) % 10) < (now % 10) ? 1 : -1;
    if (now < 10 || (used[now / 10] && (ad[now / 10] != ha))) {
      if (now < 10) ha = 0;
      if (now % N == 0) {
        K--;
        if (K == 0) {
          cout << now << endl;
          return 0;
        }
      }
      ad[now] = ha;
      used[now] = 1;
    }
  }
  for (int i = (1); i < (10000000); ++i) {
    if (used[i]) {
      int tail = i % 10;
      int flag = 0;
      if (i >= 10) {
        if ((i / 10) % 10 < tail)
          flag = 1;
        else
          flag = -1;
      }
      long long r = (i * 10000000LL) % N;
      long long need = N - r;
      if (need == N) need = 0;
      if (flag != -1) {
        for (int j = 0; j < (tail); ++j) {
          int res = check(j, N, 1, K, need);
          if (res >= 0) {
            printf("%d%07d\n", i, res);
            return 0;
          }
        }
      }
      if (flag != 1)
        for (int j = (tail + 1); j < (10); ++j) {
          int res = check(j, N, 0, K, need);
          if (res >= 0) {
            printf("%d%07d\n", i, res);
            return 0;
          }
        }
    }
  }
  puts("-1");
  return 0;
}
