#include <bits/stdc++.h>
using namespace std;
inline bool checkBit(long long n, int i) { return n & (1LL << i); }
inline long long setBit(long long n, int i) { return n | (1LL << i); }
inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline double dist(double ix, double iy, double jx, double jy) {
  return sqrt(((ix - jx) * (ix - jx)) + ((iy - jy) * (iy - jy)));
}
int marked[1000000 / 64 + 2];
bool isPrime(int x) {
  return (x > 1) &&
         ((x == 2) ||
          ((x & 1) && (!((marked[x >> 6] & (1 << ((x & 63) >> 1)))))));
}
void seive(int n) {
  int i, j;
  for (i = 3; i * i <= n; i += 2) {
    if (!(marked[i >> 6] & (1 << ((i & 63) >> 1)))) {
      for (j = i * i; j <= n; j += i << 1) {
        marked[j >> 6] |= (1 << ((j & 63) >> 1));
      }
    }
  }
}
long long bigMod(long long a, long long b) {
  long long r = 1;
  while (b) {
    if (b & 1) (r *= a) %= 1000000007;
    b >>= 1;
    (a *= a) %= 1000000007;
  }
  return r;
}
int cum[100], k, i, j, l, n;
long long m, tot, mn, mx, mid, pro, z, on, midd;
int main() {
  scanf("%lld %d", &m, &k);
  mn = 1;
  mx = (long long)1e18;
  while (mn <= mx) {
    mid = (mn + mx) >> 1;
    tot = 0;
    on = 0;
    for (i = 63; i >= 0; i--) {
      if (mid & (1LL << i)) {
        n = k - on;
        if (n < 0) continue;
        pro = z = 1;
        for (j = 0; j < n; j++) {
          pro *= (i - j);
          for (; z <= n;) {
            if (pro % z == 0)
              pro /= z++;
            else
              break;
          }
        }
        tot -= pro;
        on++;
      }
    }
    if (on == k) tot--;
    ;
    midd = 2 * mid;
    on = 0;
    for (i = 63; i >= 0; i--) {
      if (midd & (1LL << i)) {
        n = k - on;
        if (n < 0) continue;
        pro = z = 1;
        for (j = 0; j < n; j++) {
          pro *= (i - j);
          for (; z <= n;) {
            if (pro % z == 0)
              pro /= z++;
            else
              break;
          }
        }
        if (midd == 6)
          ;
        tot += pro;
        on++;
      }
    }
    if (on == k) tot++;
    ;
    if (tot > m)
      mx = mid - 1;
    else if (tot < m)
      mn = mid + 1;
    else
      break;
  }
  printf("%lld\n", mid);
  return 0;
}
