#include <bits/stdc++.h>
using namespace std;
const long long MX = (long long)2e18 + 1;
const long long LIM = (long long)2e18 + 1;
long long c[70][70];
void init() {
  c[0][0] = 1;
  for (long long i = 1; i <= 64; i++) {
    c[i][0] = 1;
    for (long long j = 1; j <= i; j++) {
      c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
    }
  }
}
long long get_cnk(long long n, long long k) {
  if (n < 0 || k < 0) {
    return 0;
  }
  return c[n][k];
}
long long count_pref(long long k, long long ones) {
  long long len = sizeof(k) * 8;
  long long p = 1ll << (len - 2);
  long long was = 0;
  long long res = 0;
  for (long long i = 0; i < len; i++, p >>= 1) {
    if (k & p) {
      long long t = len - i - 2;
      res += get_cnk(t, ones - was);
      was++;
    }
  }
  return res;
}
long long calc(long long m, long long ones) {
  return count_pref(2 * m + 1, ones) - count_pref(m + 1, ones);
}
int main() {
  init();
  long long m, k;
  cin >> m >> k;
  long long l = 0, r = MX;
  while (r - l > 1) {
    long long n = (l + r) / 2;
    if (calc(n, k) < m) {
      l = n;
    } else {
      r = n;
    }
  }
  cout << r << endl;
  return 0;
}
