#include <bits/stdc++.h>
using namespace std;
int reader_pt = 1048576, reader_last;
char reader_buf[1048576];
int writer_pt = 0;
char writer_buf[1048576];
void reader(int *x) {
  int k, m = 0;
  *x = 0;
  for (;;) {
    {
      if (reader_pt == 1048576)
        reader_pt = 0,
        reader_last = fread(reader_buf, sizeof(char), 1048576, stdin);
      (k) = reader_buf[reader_pt++];
    };
    if (k == '-') {
      m = 1;
      break;
    }
    if ('0' <= k && k <= '9') {
      *x = k - '0';
      break;
    }
  }
  for (;;) {
    {
      if (reader_pt == 1048576)
        reader_pt = 0,
        reader_last = fread(reader_buf, sizeof(char), 1048576, stdin);
      (k) = reader_buf[reader_pt++];
    };
    if (k < '0' || k > '9') break;
    *x = (*x) * 10 + k - '0';
  }
  if (m) (*x) = -(*x);
}
void reader(long long *x) {
  int k, m = 0;
  *x = 0;
  for (;;) {
    {
      if (reader_pt == 1048576)
        reader_pt = 0,
        reader_last = fread(reader_buf, sizeof(char), 1048576, stdin);
      (k) = reader_buf[reader_pt++];
    };
    if (k == '-') {
      m = 1;
      break;
    }
    if ('0' <= k && k <= '9') {
      *x = k - '0';
      break;
    }
  }
  for (;;) {
    {
      if (reader_pt == 1048576)
        reader_pt = 0,
        reader_last = fread(reader_buf, sizeof(char), 1048576, stdin);
      (k) = reader_buf[reader_pt++];
    };
    if (k < '0' || k > '9') break;
    *x = (*x) * 10 + k - '0';
  }
  if (m) (*x) = -(*x);
}
void writer(long long x, char c) {
  int i, sz = 0, m = 0;
  char buf[20];
  if (x < 0) m = 1, x = -x;
  while (x) buf[sz++] = x % 10, x /= 10;
  if (!sz) buf[sz++] = 0;
  if (m) {
    if (writer_pt == 1048576)
      writer_pt = 0, fwrite(writer_buf, sizeof(char), 1048576, stdout);
    writer_buf[writer_pt++] = ('-');
  };
  while (sz--) {
    if (writer_pt == 1048576)
      writer_pt = 0, fwrite(writer_buf, sizeof(char), 1048576, stdout);
    writer_buf[writer_pt++] = (buf[sz] + '0');
  };
  {
    if (writer_pt == 1048576)
      writer_pt = 0, fwrite(writer_buf, sizeof(char), 1048576, stdout);
    writer_buf[writer_pt++] = (c);
  };
}
unsigned long long dp[70][2][70];
unsigned long long cntnum(long long C, int k) {
  int i, j, d;
  for (d = 0; d < 65; d++)
    for (i = 0; i < 2; i++)
      for (j = 0; j < 65; j++) dp[d][i][j] = 0;
  dp[63][1][0] = 1;
  for (d = 63; d; d--)
    for (i = 0; i < 2; i++)
      for (j = 0; j < 65; j++)
        if (dp[d][i][j]) {
          if (i && (C & (1ULL << (d - 1)))) {
            dp[d - 1][0][j] += dp[d][i][j];
            dp[d - 1][1][j + 1] += dp[d][i][j];
          } else if (i) {
            dp[d - 1][1][j] += dp[d][i][j];
          } else {
            dp[d - 1][i][j] += dp[d][i][j];
            dp[d - 1][i][j + 1] += dp[d][i][j];
          }
        }
  return dp[0][0][k] + dp[0][1][k];
}
int main() {
  long long m;
  int k;
  int i, j;
  unsigned long long A, B, C, num;
  reader(&m);
  reader(&k);
  A = 1;
  B = 1000000000000000000ULL;
  while (A < B) {
    C = (A + B) / 2;
    num = cntnum(2 * C, k) - cntnum(C, k);
    if (num < m) {
      A = C + 1;
      continue;
    }
    if (num > m) {
      B = C - 1;
      continue;
    }
    A = B = C;
  }
  writer((long long)A, '\n');
  {
    fwrite(writer_buf, sizeof(char), writer_pt, stdout);
    writer_pt = 0;
  };
  return 0;
}
