#include <stdio.h>
#include <stdint.h>

int main()
{
  uint64_t i;
  uint64_t n;
  uint64_t answer = 0;
  uint64_t dummy;

  scanf("%llu %llu", &n, &dummy);

  if(dummy == 1)
    {
      printf("%llu\n", n);
      return 0;
    }

  for(i = 1; i < n; i <<= 1);
  answer = i - 1;

  if(i <= n)
    answer |= i;

  printf("%llu\n", answer);
  return 0;
}

#include <stdio.h>

int main(){

long long n,k;
int i = 0;

scanf("%lld",&n);

k = n;
while (k>0){
	k >>= 1;
	i ++;
	}

scanf("%lld",&k);

if (k == 1LL)
	printf("%lld\n",n);
else{
	k = 1LL;
	while (i>0){
		k <<= 1;
		i--;
	}
	printf("%lld\n",k-1LL);
}
return 0;
}

#include <stdio.h>
#define ll long long

int main() {
    ll k, n;
    while(scanf("%I64d%I64d", &n, &k) != EOF) {
        int countn = 0;
        ll res = 0, temp = 1, nh = n;
        while(n != 0) {
            n /= 2;
            countn++;
        }
        for (int i = 0; i < countn; ++i) {
            res += temp;
            temp *= 2;
        }
        if (k == 1) printf("%I64d\n", nh);
        else printf("%I64d\n", res);
    }
    return 0;
}

//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    long long n,k,i,j,r=1;
    double d;
    char s[262144];
    scanf("%lld%lld",&n,&k);
    while(r<=n){r*=2;}
    //l=strlen(s);
    if(k==1){printf("%lld\n",n);}
    else{printf("%lld\n",r-1);}
    return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
	long long n,k;
	scanf("%lld %lld",&n,&k);
	long long  i=1;
	long long  j=2;
	long long  ans=1;
	//printf("%lld\n",j );
	if (k==1)
	{
		printf("%lld\n",n );
	}
	else{

	while(j<=n )
	{
		j=j*2;
		//printf("%lld\n",j );
	}

	printf("%lld\n",(j)-1 );
}
}

#include<stdio.h>
#include<math.h>

int main()
{
    long long int n,k,a,ans;

    scanf("%I64d %I64d",&n,&k);

    if(k==1)
    {
        printf("%I64d",n);
    }
    else
    {
        while(n>=1)
        {
            n/=2;
            a++;
        }
        ans=pow(2,a)-1;
        printf("%I64d",ans);
    }

    return 0;
}

#include <stdio.h>

int main() {
	long long n, k, l;

	scanf("%lld%lld", &n, &k);
	l = 0;
	while (1LL << l <= n)
		l++;
	printf("%lld\n", k == 1 ? n : (1LL << l) - 1);
	return 0;
}

#include <stdio.h>
#include <stdint.h>

int main(){
	int64_t n, k, r, i;
//	for(i = 0;i<100000;i++){
		scanf("%I64d %I64d",&n,&k);
	//	n = i;
	//	k = 2;
		int64_t t = 1;
		r = n;
		while(t <= r){
			r = r ^ t;
			t = t << 1;
		}
		if(k == 1) printf("%I64d\n",n);
		else printf("%I64d\n",n+r);
//	}
	return 0;
}

#include <stdio.h>
#include <stdint.h>

int main(void)
{
    int64_t n, k;
    scanf("%I64d %I64d", &n, &k);

    if (1 == k)
	{
        printf("%I64d\n", n);

        return 0;
    }

    int bit = 0;
    for (; n >> bit; bit++);

    printf("%I64d\n", (1LL << bit) - 1);

    return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
    long long int n,k;
    scanf("%lld%lld",&n,&k);
    long long int c=0;
    if (k==1)
    {
        /* code */
        printf("%I64d\n",n );
        return 0;
    }
    while(pow(2,c)<=n)
    {
        c++;
    }
        long long int q=pow(2,c)-1;
        printf("%I64d\n",q);

}

#include<stdio.h>
int main()
 { long long int n,k,b,p;
	scanf("%lld%lld",&n,&k);
		if(k==1)
		printf("%lld",n);
			else
			{p=n;
			b=0;
				while(p>0)
				{ b++;
				p=p>>1; }
				p=1;
			   while(b--)
				{ n=n|p;
					p=p<<1; }
				printf("%lld",n); }

return 0; }

#include <stdio.h>
#include <math.h>
int main() {
	unsigned long long n, k, b;
    scanf("%I64d%I64d", &n, &k);
    char t = 0;
    b = n;
    while(b >>= 1) t++;
    b = pow(2, t+1)-1;
    if(k == 1) b = n;
	printf("%I64d", b);
    return 0;
}

#include<stdio.h>

typedef long long int lli;

int main()
{
	lli n,k;
	scanf("%lld%lld",&n,&k);
	if(n==1)
	{
		printf("1\n");
		return 0;
	}
	if(k==1)
	{
		printf("%lld\n",n);
	}
	else
	{
		lli tmp=2,i=0;
		while(tmp<=n)
		{
			tmp=tmp*2;
			i++;
		}
		lli ans;
		ans=tmp-1;

		printf("%lld\n",ans);

	}

	return 0;
}

#include <stdio.h>
#include <stdlib.h>
__int64 p,k,n,s;
int main(void)
{
	scanf("%I64d %I64d",&k,&n);
	p=1;
	if (k>=1) s=1;
	while (p*2<=k)
	{
		p=2*p;
		s=s+p;
	}
	if (n==1) printf("%I64d",k);
	else printf("%I64d",s);
	return 0;
}

#include<stdio.h>
int main()
{
    long long int i,a,b;
    long long int s[61];
    s[1]=1;
    for (i=2;i<61;i++)
        s[i]=s[i-1]*2+1;
    scanf("%I64d%I64d",&a,&b);
    if (b==1)
        printf("%I64d\n",a);
    else
    {
        for (i=1;i<61;i++)
        {
            if (a<=s[i])  break;
        }
        printf("%I64d\n",s[i]);
    }
    return 0;
}

#include <stdio.h>

int main()
{
	long long n,k;
	scanf("%lld%lld",&n,&k);
	long long ans = 0;
	long long temp = 1;
	if (k == 1) ans = n;
	else
	{
		for (int i = 1; i < 70; i++)
		{
			temp *= 2;
			if (temp > n)
			{
				ans = temp-1;
				break;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

#include<stdio.h>
long long int  next(long long int n)
{
    long long int p = 1;
    if (n && !(n & (n - 1)))
        return n;

    while (p < n)
        p <<= 1;

    return p;
}

int main()
{
  long long int n,k,temp;

  scanf("%lld%lld",&n,&k);
  temp=next(n);

  if(k>=2)
  {
          if(temp!=n)
        printf("%lld\n",temp-1);

        else
        {
                printf("%lld\n",2*temp-1);
        }
  }
  else
  {
        printf("%lld\n",n);
  }
  return 0;
}

#include <stdio.h>

int main()
{
    long long n, k, tmp;
    scanf("%lld %lld", &n, &k);
    int dig = 0; tmp = n;
    while(tmp > 0) {
	tmp >>= 1;
	dig++;   }
    long long ans = (k == 1)?n:((long long)(1)<<(dig)) - 1;
    printf("%lld\n", ans);
    return 0;
}

#include<stdio.h>
#include<math.h>
int main(){
	long long int n,k,i=0;
	scanf("%I64d %I64d", &n, &k);
	if(k==1)
		printf("%I64d",n);
	else
	{
		i=0;
		while((long long int)pow(2,i)<=n)
			i++;
		printf("%I64d",(long long int)pow(2,i)-1);
	}
	return 0;
}

#include <stdio.h>
#define LLU unsigned long long int
#define TWO_POWER_64_MINUS_1 18446744073709551615llu

LLU noOfBinaryDigits(LLU input) {
	LLU ans = 0;
	while(input) {
		input >>= 1;
		ans++;
	}
	return ans;
}
LLU generateBinary2ToPowerNMinus1(LLU N) {
	LLU out = 0, ana = 1, i;
	for(i=1; i<=N; i++) {
		out += ana;
		ana <<= 1;
	}
	return out;
}

int main() {
	LLU n, k;
	scanf("%llu%llu", &n, &k);
	if(k==1) {
		printf("%llu\n", n);
	}
	else {
		printf("%llu\n",
				generateBinary2ToPowerNMinus1(noOfBinaryDigits(n)));
	}
	return 0;
}

#include<stdio.h>
#include<math.h>
long long int max(long long int a,long long int b){

	if(a>=b)
		return a;
	else
		return b;

}
long long int xorsum(long long int n,long long int k){

	if(k==0)
		return 0;

	if(n==0)
		return 0;
	if(n<k)
		return 0;

	return max(xorsum(n-1,k),n^xorsum(n-1,k-1));
}

	int main(){

long long int n,k;

scanf("%lld %lld",&n,&k);

int i;

for(i=0;i<n;i++){

	if((long long int)(pow(2,i))>n)
		break;

}

if(k==1)
	printf("%lld\n",n);
else
	printf("%lld\n",(long long int)(pow(2,i))-1);

return 0;
}

/*
B. New Year's Eve
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains n sweet candies from the good ol' bakery, each labeled from 1 to n corresponding to its tastiness. No two candies have the same tastiness.

The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest ones �� but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum!

A xor-sum of a sequence of integers a1,?a2,?...,?am is defined as the bitwise XOR of all its elements: , here denotes the bitwise XOR operation; more about bitwise XOR can be found here.

Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than k candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain.

Input
The sole string contains two integers n and k (1?��?k?��?n?��?1018).

Output
Output one number �� the largest possible xor-sum.

Examples
input
4 3
output
7
input
6 6
output
7
Note
In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7.

In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7.
*/

#include <stdint.h>

int main()
{
    uint64_t n, k;
    scanf("%I64u%I64u", &n, &k);

    if (k == 1)
    {
        printf("%I64u", n);
        return 0;
    }

    uint64_t max = 1;
    uint64_t left = 0;
    while (max <= n)
    {
        max = max << 1;
        ++left;
    }

    printf("%I64u", (1LL << left) - 1);

    return 0;
}

#include <stdio.h>

long long n,K;

int main()
{
    int i;

    scanf("%I64d%I64d",&n,&K);
    if(K == 1) printf("%I64d\n",n);
    else
    {
        for(i=0;n;n>>=1,i++);
        printf("%I64d\n",(1LL<<i)-1);
    }

    return 0;
}

#include<stdio.h>
#include<math.h>
long long int pw(long long int i)
{
	if(i==1) return 1;
	else return 1 + pw(i/2);
}
int main()
{
	long long int n,k,l,s=0,i;
	scanf("%lld %lld",&n,&k);
	l = pw(n);
	if(k>1)
	{
		for(i=0;i<l;i++)
		{
			s<<=1;
			s+=1;

		}
		printf("%lld\n",s);
	}
	if(k==1)
	printf("%lld\n",n);

	return 0;
}

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main()
{
    long long int p,q,a,b,x,y,z,sum,k,i;
    scanf("%lld %lld",&a,&b);
    z=0;
    p=a;
    while(p!=1){
        p=p/2;
        z++;
    }
    if(b==1){
        printf("%lld",a);
    }else{
        y=1;
        z=z+1;
        for(i=0;i<z;i++){
            y=y*2;
        }
        y=y-1;
        printf("%lld",y);
    }

    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int cmp(const void *a, const void *b)
{
	return *(int *)a - *(int *)b;
}

int max(int a,int b)
{
	if(a>b)
		return a;
	else
		return b;
}

int main()
{
	long long int n,k,p,count=0;
	scanf("%lld%lld",&n,&k);
	p=n;
	while(p>0)
	{
		p=p/2;
		count++;
	}
	long long int ans = pow(2,count)-1;
	if(k>=2)
		printf("%lld\n",ans);
	else
		printf("%lld\n",n);
	return 0;
}

#include<stdio.h>
#include<math.h>

int main()
{
	long long int n,k;
	scanf("%lld %lld",&n,&k);
	long long int num;
	long long int n1=n;
	long long int x=0;
	while(n1!=1)
	{
		x++;
		n1=n1/2;
	}
	long long int n3=pow(2,x);
//	printf("n3=%d\n",n3);
	if(k==1)
	{
		printf("%lld\n",n);
	}
	else
	{
		printf("%lld\n",2*n3-1);
	}
	return 0;
}

#include<stdio.h>
#include<math.h>
typedef long long int ll;
int main()
{
	ll n,k;
	scanf("%lld%lld",&n,&k);
	ll ans=n;
	ll count=1,i;
/*	for(i=n-1;i>=n/2;i--)
	{
		if(count==k) break;
		ll temp=ans^i;
		if(temp>ans)
		{
			ans=temp;
			count++;
		}

//		if(ans==(pow()) break;
	}*/
	for(i=n/2;i>0;i/=2)
	{
	//	if(count==k) break;
		ll temp=ans^i;
		if(temp>ans)
		{
			ans=temp;
	//		count++;
		}
	}
	if(k==1) printf("%lld",n);
	else printf("%lld",ans);

	return 0;
}

#include <stdio.h>

typedef long long int llu;

int main() {

	llu n, k, i = 1;
	scanf("%I64d%I64d", &n, &k);
	llu c = 0;
	while(n >= (llu)(i<<c)) c++;
	if(k == 1) printf("%I64d\n", n);
	else printf("%I64d\n", (llu)((i<<c)-1));

	return 0;
}

#include<stdio.h>
#include<stdbool.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main()
{
    long long N,K,i,j,count=0,ans=1;
    scanf("%lld %lld",&N,&K);
    if(K==1)
        printf("%lld",N);
    else
    {
        while( N != 0)
        {
            N  >>= 1;
            count += 1;
        }
        while(count--)
            ans*=2;
        printf("%lld",ans-1);
    }

    return 0;
}

#include <stdio.h>
#include <limits.h>
int main()
{
	unsigned long long int n,k,p,ans=0;
	int flag,i,j;
//	printf("%llu\n",ULLONG_MAX);
	unsigned long long int a[100];
	for(i=0;i<64;++i)
	{
		a[i]=1ULL<<(i);
		a[i]=a[i]-1;
//		printf("%d :: %llu\n",i,a[i]);
	}
	scanf("%llu%llu",&n,&k);
	if(k==1)
	{
		printf("%llu\n",n);
	}
	else if(k>1)
	{
		flag=0;
		for(i=0;a[i]<n;++i)
		{
			if(a[i]==n)
			{
				flag=i;
				break;
			}

		}

		if(flag==1)
		{
			printf("%llu\n",n);
		}
		else
		{
			printf("%llu\n",a[i]);
		}
//		for(i=0;a[i]<
//		for(i=0;i<25;++i)
//		{
//			if((n>>1)&1==1)
//			{
//				flag=i;
//				printf("%d\n",flag);
//			}
//			printf("%llu\n",n);
//			n=n>>1;
//		}
//		printf("%d\n",flag);
//		for(i=0;i<=flag;++i)
//		{
//			ans=ans+a[i];
//		}
//		ans=(1ULL<<(flag+1))-1;
//		printf("%llu\n",ans);
	}
	return 0;
}

#include <stdio.h>
#include <math.h>
int main(){
    long long n,k,b=0,i,x=0;
    scanf("%I64d %I64d",&n,&k);
    if (k==1){
        printf("%I64d",n);
        return 0;
    }
    while (n>0){
        n=n/2;
        b++;
    }
    for (i=0;i<b;i++){
        x+=pow(2,i);
    }
    printf("%I64d",x);
}

#include<stdio.h>
int main()
{
	long long int n,k,i,max;
	scanf("%lld",&n);
	scanf("%lld",&k);
	int temp1,temp2;
	if(k==1)
	{
		temp1=n/1000000000;
		temp2=n%1000000000;
		if(temp1)
		{
			printf("%d",temp1);
			printf("%09d\n",temp2);
		}
		else
			printf("%d\n",temp2);
	}
	else
	{
		max=(long long int)1;
		i=(long long int)1;
		while(i<=n)
		{
			i=i<<1;
			max+=i;
		}
		max-=i;
		{
			temp1=max/1000000000;
			temp2=max%1000000000;
			if(temp1)
			{
				printf("%d",temp1);
				printf("%09d\n",temp2);
			}
			else
				printf("%d\n",temp2);
		}
	}
	return 0;
}

#include <stdio.h>
#include <stdint.h>

int main(void)
{
    int64_t n, k;
    scanf("%I64d %I64d", &n, &k);

    if (1 == k)
	{
        printf("%I64d\n", n);

        return 0;
    }

    int64_t bit = 0;
    for (; n >> bit; bit++);

    printf("%I64d\n", (1LL << bit) - 1);

    return 0;
}

#include<stdio.h>
int main(){
long long int n,k,total=1,flag=0;
scanf("%lld %lld",&n,&k);
if(k==1){
printf("%lld\n",n);
}
else {
while(flag==0){
total=total*2;
if(n<=(total-1)){
flag=1;
}}
printf("%lld\n",total-1);}
return 0;
}

#include <stdio.h>
int main()
{
	long long int n,k;
	scanf("%lld%lld",&n,&k);
	long long int x=0;
	int j=0;
	if(k==1)
		{
			printf("%lld\n",n);
			return 0;
		}
	while(n>0)
	{
		x += (1ll<<j);
		j++;
		//printf("%lld ",x);
		n = n>>1;
	}
	printf("%lld\n",x);
	return  0;
}

#include<stdio.h>
#include<math.h>
int main()
{
	long long int n,k,i,j,count=0,x=0;
	scanf("%lld%lld",&n,&k);
	if(k==1)
	{
		printf("%lld",n);
		return 0;
	}
	while(n!=0)
	{
		n = n>>1;
		count++;
	}
	for(i=0;i<count;i++)
	{
		x = x+pow(2,i);
	}
	printf("%lld",x);
	return 0;
}

# include<stdio.h>
int main(){
long long int n,k,i,x=1;
scanf("%I64d",&n);
scanf("%I64d",&k);
if(k!=1){
for(i=2;i<=n;i++){
    if((x^i)>x)x=x^i;
    i=x;
}}
else x=n;
printf("%I64d",x);
}

#include <stdio.h>

int main(void) {
    long long int n,k;
    scanf("%lld%lld",&n,&k);
    long long int ans=1;
    while(ans<=n)
    ans*=2;
    if(k==1)
    printf("%lld\n",n);
    else
    printf("%lld\n",ans-1);
	// your code goes here
	return 0;
}

#include<stdio.h>
#include<math.h>
long long int n,r,a,b,c;
long long int ans=0;

int main()
{
    ans=0;
    scanf("%lld %lld",&n,&r);
    b=n;
    while(n)
    {
        n/=2;
        a++;
    }
    ans=pow(2,a)-1;
    if(r==1)
    {
        printf("%lld\n",b);
    }
    else
        printf("%lld\n",ans);
    return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
	long long int n,k,t=0,ans=1;
	scanf("%lld",&n);
	scanf("%lld",&k);
	if(k==1)
		printf("%lld\n",n);
	else if(k>1)
	{
		while(n>0)
		{
			t++;
			n=n/2;
		}
		ans=pow(2,t)-1;
		printf("%lld\n",ans);
	}
	return 0;
}

#include<stdio.h>
int main()
{
	long long int n,k,sum,temp;
	temp=1;
	sum=1;
	int count=0;
	scanf("%I64d%I64d",&n,&k);
	if(k==1)
		printf("%I64d\n",n);
	else
	{
		long long int i;
		for(i=n;i>0;i=i/2)
			count++;
//		printf("%d ",count);
		for(i=0;i<count-1;i++)
		{
			sum=temp+sum*2;
		//	temp=0;
		}
		printf("%I64d",sum);
	}
	return 0;
}

#include <stdio.h>

int main()
{
    int i, j;
    long long int k, n, t, r;

    scanf("%lld %lld ", &n, &k);

    t = n;

    for (i = 0; t != 0; t >>= 1, ++i) { }

    if (k == 1) {
        printf("%lld\n", n);
    } else {
        r = 0;
        for (j = 0; j < i; ++j) {
            t = (long long int) 1 << j;

            r |= t;
        }

        printf("%lld\n", r);
    }

    return 0;
}

#include <stdio.h>

typedef long long ll;
typedef unsigned long long ul;

int main()
{
    ul n, k;
    scanf("%I64d %I64d", &n, &k);
    ul ans = n;
    if (k > 1) {
        ul cur = 1;
        while (cur <= ans) {
            ans |= cur;
            cur <<= 1;
        }
    }
    printf("%I64d", ans);
}

#include<stdio.h>
#include<math.h>
int main()
{
    long long int n,k,q,ans;
    int c;
    scanf("%lld%lld",&n,&k);
    q=n;
    while(q!=0)
    {
        q/=2;
        c++;
    }
    if(k==1)
    printf("%lld",n);
    else
    {
        ans=pow(2,c)-1;
        printf("%lld",ans);
    }
}

#include <stdio.h>

int main()
{
	unsigned long long int arr[63]={0};

	arr[0]=1;
	for (int i = 1; i < 63; i++)
		arr[i]=arr[i-1]*2;

	unsigned long long int n;
	unsigned long long int k;
	scanf("%llu",&n);
	scanf("%llu",&k);
	unsigned long long int ans=0;
	int point = 0;
if(k!=1)
{
	int pp=0;
	for (int i = 0; i < 63; i++)
	{
		if(arr[i]>n)
			{
				pp=i;
				break;
			}
	}

	printf("%llu\n",arr[pp]-1);
}

else
	printf("%llu\n",n);
}

#include<stdio.h>
#include<math.h>
int main()
{
	long long n,k,i;
	scanf("%lld %lld",&n,&k);
	if(k==1)
	{
		printf("%lld",n);
		return 0;
	}
	long long temp=1;
	for(i=1;temp<=n;i++)
	{
		temp*=2;
	}
	printf("%lld",(long long)pow(2,i-1)-1);
	return 0;
 }

#include<stdio.h>
long long n,k,ans=1;
int main(){
    scanf("%lld%lld",&n,&k);
    if(k==1){
		printf("%lld\n",n);
    }
	else{
    	while(n>>=1)
			ans<<=1;
	    printf("%lld\n",(ans<<1)-1);
	}
    return 0;
}

#include <stdio.h>
int main(void)
{
    long long k, n, ans = 1;

    scanf("%lld %lld", &n, &k);
    if (k == 1)
        printf("%lld", n);
    else
    {
        while (1)
        {
            if (ans > n)
                break;
            ans *= 2;
        }
        printf("%lld", ans - 1);
    }

    return 0;
}

#include<stdio.h>
int main()
{
    long long n,k,t=1;
    scanf("%lld%lld",&n,&k);
    if(k==1)
    {
        printf("%lld\n",n);
        return 0;
    }
    while(t<=n)
        t*=2;
    printf("%lld\n",t-1);
    return 0;
}

#include<stdio.h>
int main()
{
   long long int n,k;
   scanf("%lld %lld", &n,&k);
   if(k==1)
    printf("%lld",n);
   else
    {   long long i = 1;
        while(i<n)
            i=i*2+1;
        printf("%lld",i);
    }
    return 0;
}

#include <stdio.h>
int main(void)
{
	long long n,k,max=1;

	scanf("%lld%lld",&n,&k);

	if (k==1)
		printf("%lld\n",n);

	else
	{
		while (n)
		{
			n>>=1;
			max<<=1;
		}

		printf("%lld\n",max-1);
	}

	return 0;

}

#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
    int len;
    char buf[100] = {0};
    long long n, k, p;
    scanf("%lld%lld", &n, &k);
    if (k == 1)
    {
        printf("%lld", n);
        return 0;
    }
    for (int i = 0; n != 0; i++)
    {
        buf[i] = n % 2 + '0';
        n /= 2;
    }
    len = strlen(buf);
    p = pow(2, len) - 1;
    printf("%lld", p);
    return 0;
}

#include<stdio.h>
int main()
{
   long long int n,k;
    scanf("%lld %lld",&n,&k);
    if(k==1)printf("%lld\n",n);
    else{
    long long int p=1;
    while(n>0){
        p=p*2;
        k--;
        n/=2;
    }
        printf("%lld\n",p-1);
    }
    return 0;
}

#include<stdio.h>
int main()
{
	__int64 n,k,i,j;
	scanf("%I64d%I64d",&n,&k);
	if(k==1)
	printf("%I64d\n",n);
	else
	{
		for(i=1,j=0;n>=i;j++)
		i=i*2;
		printf("%I64d\n",i-1);
	}
	return 0;
}

#include <math.h>
#include <stdio.h>

int main() {
	long long n, k, x;

	scanf("%lld%lld", &n, &k);
	for (x = 0; 1LL << x <= n; x++)
		;
	printf("%lld\n", k == 1 ? n : (1LL << x) - 1);
	return 0;
}

/* Coached by rainboy */
#include <math.h>
#include <stdio.h>

int main() {
	long long n, k, x;

	scanf("%lld%lld", &n, &k);
	for (x = 0; 1LL << x <= n; x++)
		;
	printf("%lld\n", k == 1 ? n : (1LL << x) - 1);
	return 0;
}

#include<stdio.h>
int main()
{
	long long a,b,c,n,x,y;
	int i,j;
	scanf("%lld %lld",&x,&y);
	if(y==1){
		printf("%lld\n",x);
		return 0;
	}
	i=0;
	while(x>0)
	{
		x/=2;
		i+=1;
	}
	x=1;
	while(i>1)
	{
		x*=2;
		x+=1;
		i-=1;
	}
	printf("%lld\n",x);
	scanf("%d");
	return 0;
}

#include<stdio.h>
int main()
{
	long long int n,k;
	scanf("%lld%lld",&n,&k);
	long long int pow=1,ans=0;
	if(k!=1){
		while(pow<=n)
			pow=pow<<1;
		ans=pow -1;
	}
	else
		ans=n;
	printf("%lld\n",ans );
	return 0;
}

#include<stdio.h>
typedef long long ll;
int main()
{
    ll n,k;
    int cnt=0;
    scanf("%lld%lld",&n,&k);
    //if(n==1e18)
    //printf("1152921504606846975");
    //else
    if(k==1)
    printf("%lld",n);
    else

    {
    while(n)
    {
    n/=2;
    cnt++;
    }
    ll tmp[cnt];
    for(int i=0;i<=cnt;i++)
    {
    ll p=1;
    for(int j=0;j<i;j++)
    p*=2;
    tmp[i]=p;
    }
    /*printf("%d\nn",cnt);
    for(int i=0;i<=cnt;i++)
   // printf("%d ",4^8);
    //printf("%d ",2^8^1);
    printf("%lld\n",tmp[i]);*/
    ll sum=tmp[cnt];
    sum--;
    /*for(int i=cnt-1;i>=0&&k>0;i--)
    {
   // printf("y");
    sum+=tmp[i];
    k--;
    }*/
    printf("%lld",sum);
    }
    return 0;
}

#include <stdio.h>
#include <string.h>
#include <math.h>
#define PI 3.14159265358979
#ifndef __int64
    #define __int64 long long
#endif

int main()
{
    __int64 n, k, p;
    scanf("%I64d%I64d", &n, &k);
    if(k == 1)
    {
        printf("%I64d\n", n);
        return 0;
    }
    else
    {
        for(p = 1; p <= n; p <<= 1);
        printf("%I64d\n", p - 1);
    }
    return 0;
}

#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <stdio.h>

static inline int find_exp2(int64_t n) {
    int64_t p2 = 2; int ret = 0;
    while(p2 <= n) { ++ret, p2 *= 2; }
    return ret;
}

int main() {
    int64_t N, K; scanf("%"PRId64 " %"PRId64 "\n", &N,&K);
    if(K == 1) { printf("%"PRId64 "\n", N); return 0; }
    // if more than two numbers: pick biggest and then "invert" zeroes
    const int exp2 = find_exp2(N); printf("%"PRId64 "\n", (1LL << (exp2+1)) - 1);
    return 0;
}

#include<stdio.h>
long long n,m, k,x,a;
int main()
{
	scanf("%lld %lld", &n, &k);
	m = n;
	if (k == 1) printf("%lld", n);
	else {
		a = 1;
		while (m > 0) m >>= 1,x++;
		while (x > 0) {
			a <<= 1;
			x--;
		}
		printf("%lld", a - 1);
	}
	return 0;
}

#include <stdio.h>

int main()
{
    long long n, k;
    scanf("%I64d %I64d", &n, &k);
    int bound = 0;
    for(int i = 1; i < 61; ++i) {
        if((1LL << i) > n) {
            bound = i;
            break;
        }
    }
    if(k == 1) {
        printf("%I64d\n", n);
    } else {
        printf("%I64d\n", (1LL << bound) - 1);
    }
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
int main()
{
	long long int n,k;
	long long int A[100];
	long long int max, num, res;
	int i;
	max = 100000;
	max = max * 100000;
	max = max * 100000;
	max = max * 2000;
	i=1;
	A[0] = 0;
	A[1]=1;
	scanf("%lld%lld", &n, &k);
	while (A[i] <= n) {A[i+1] = A[i] * 2; i++;}
	if (k==1) res = n;
	else
	{
		while (A[i] > n) i--;
		res = A[i] * 2 - 1;
	}
	printf("%lld\n",res);
	return 0;
}

#include <stdio.h>
int main()
{
    long long n,k;
    scanf("%I64d%I64d",&n,&k);
    if (n==1||k==1){printf("%I64d\n",n);return 0;}
    unsigned long long i=1;
    unsigned long long ans=0;
    while (i<=n)
    {
        ans^=i;
        i*=2;
    }
    printf("%I64u\n",ans);
    return 0;
}

#include <stdio.h>
#include <limits.h>
int main()
{
	unsigned long long int n,k,p,ans;
	int flag,i;
	scanf("%llu%llu",&n,&k);
	if(k==1)
	{
		printf("%llu\n",n);
	}
	else if(k>1)
	{
		for(i=0;i<19;++i)
		{
			if((n>>i)&1==1)
			{
				flag=i;
			}
		}
		ans=(1<<(flag+1))-1;
		printf("%llu\n",ans);
	}
	return 0;
}

#include <stdio.h>
#include <limits.h>
int main()
{
	unsigned long long int n,k,p,ans;
	int flag,i;
//	printf("%llu\n",ULLONG_MAX);
	unsigned long long int a[100];
	for(i=0;i<63;++i)
	{
		a[i]=1<<(i+1);
		a[i]=a[i]-1;
//		printf("%llu\n",a[i]);
	}
	scanf("%llu%llu",&n,&k);
	if(k==1)
	{
		printf("%llu\n",n);
	}
	else if(k>1)
	{
		flag=0;
		for(i=0;a[i]<n;++i)
		{
			if(a[i]==n)
			{
				flag=1;
				break;
			}

		}
		if(flag==1)
		{
			printf("%llu\n",n);
		}
		else
		{
			printf("%llu\n",a[i]);
		}
//		for(i=0;a[i]<
//		for(i=0;i<25;++i)
//		{
//			if((n>>i)&1==1)
//			{
//				flag=i;
//				printf("%d\n",flag);
//			}
//		}
//		ans=(1<<(flag+1))-1;
//		printf("%llu\n",ans);
	}
	return 0;
}

#include <stdio.h>
#include <limits.h>
int main()
{
	unsigned long long int n,k,p,ans=0;
	int flag,i,j;
//	printf("%llu\n",ULLONG_MAX);
	unsigned long long int a[100];
	for(i=0;i<63;++i)
	{
		a[i]=1<<(i);
//		printf("%llu\n",a[i]);
	}
	scanf("%llu%llu",&n,&k);
	if(k==1)
	{
		printf("%llu\n",n);
	}
	else if(k>1)
	{
		flag=0;
	/*	for(i=0;a[i]<n;++i)
		{
			if(a[i]==n)
			{
				flag=i;
				break;
			}

		}

		if(flag==1)
		{
			printf("%llu\n",n);
		}
		else
		{
			printf("%llu\n",a[i]);
		}*/
//		for(i=0;a[i]<
		for(i=0;i<25;++i)
		{
			if((n>>i)&1==1)
			{
				flag=i;
		//		printf("%d\n",flag);
			}
		}
//		printf("%d\n",flag);
		for(i=0;i<=flag;++i)
		{
			ans=ans+a[i];
		}
//		ans=(1<<(flag+1))-1;
		printf("%llu\n",ans);
	}
	return 0;
}

#include <stdio.h>
#include <math.h>
int main(){
    long long n,k,b=0,i,x=0;
    scanf("%I64d %I64d",&n,&k);
    while (n>0){
        n=n/2;
        b++;
    }
    for (i=0;i<b;i++){
        x+=pow(2,i);
    }
    printf("%I64d",x);
}

#include <stdio.h>
#include <stdint.h>

int main(void)
{
    int64_t n, k;
    scanf("%I64d, %I64d", &n, &k);

    if (1 == k)
	{
        printf("%I64d\n", n);

        return 0;
    }

    int64_t bit = 0;
    for (; n >> bit; bit++);

    printf("%I64d\n", (1LL << bit) - 1);

    return 0;
}

#include <stdio.h>
#include <stdint.h>

int main(void)
{
    int64_t n, k;
    scanf("%I64d, %I64d", &n, &k);

    if (1 == k)
	{
        printf("%I64d\n", n);

        return 0;
    }

    int bit = 0;
    for (; n >> bit; bit++);

    printf("%I64d\n", (1LL << bit) - 1);

    return 0;
}

# include<stdio.h>
# include<math.h>
int main(){
long long int n,k,i,x=1;
scanf("%I64d",&n);
scanf("%I64d",&k);
for(i=2;i<=n;i++){
    if((x^i)>x)x=x^i;
    i=x;
}
printf("%I64d",x);
}

#include<stdio.h>
#include<math.h>
long long int n,r,a,b,c;
long long int ans=0;

int main()
{
    ans=0;
    scanf("%lld %lld",&n,&r);
    while(n)
    {
        n/=2;
        a++;
    }
    ans=pow(2,a)-1;
    if(r==1)
        printf("%lld\n",n);
    else
        printf("%lld\n",ans);
    return 0;
}

#include <stdio.h>
unsigned long long ans[100];
int main()
{
    ans[0]=1;ans[64]=-1;
    int i;
    for (i=1;i<=63;i++)
        ans[i]=ans[i-1]*2;
    long long n,k;
    scanf("%I64d%I64d",&n,&k);
    if (k>1){
        for (i=0;i<=63;i++)
            if (ans[i]>n)
            {
                printf("%I64u\n",ans[i]-1);
                return 0;
            }
    }
    else
    {
        for (i=0;i<=63;i++)
            if (ans[i]>=n)
            {
                printf("%I64u\n",ans[i]);
                return 0;
            }
    }
    return 0;
}

#include <stdio.h>
int main ()
{
	long long a,b,ans=0,i=0;
	scanf ("%d %d",&a,&b);
	if (b == 1){
		printf ("%d",a);
		return 0;
	}
	while (a){
		ans = ans + (1LL << i);
		a = a/2LL;
		i ++;
	}
	printf ("%lld",ans);
	return 0;
}

#include<stdio.h>
typedef long long ll;
int main()
{
    ll n,k;
    int cnt=0;
    scanf("%lld%lld",&n,&k);
    while(n)
    {
    n/=2;
    cnt++;
    }
    ll tmp[cnt];
    for(int i=0;i<cnt;i++)
    {
    ll p=1;
    for(int j=0;j<i;j++)
    p*=2;
    tmp[i]=p;
    }
    //for(int i=0;i<cnt;i++)
   // printf("%d ",4^6);
    //printf("%d ",2^8^1);
    //printf("%lld ",tmp[i]);
    ll sum=0;
    for(int i=cnt-1;i>=0&&k>0;i--)
    {
   // printf("y");
    sum+=tmp[i];
    k--;
    }
    printf("%lld",sum);
    return 0;
}

#include<stdio.h>
typedef long long ll;
int main()
{
    ll n,k;
    int cnt=0;
    scanf("%lld%lld",&n,&k);
    //if(n==1e18)
    //printf("1152921504606846975");
    //else
    {
    while(n)
    {
    n/=2;
    cnt++;
    }
    ll tmp[cnt];
    for(int i=0;i<=cnt;i++)
    {
    ll p=1;
    for(int j=0;j<i;j++)
    p*=2;
    tmp[i]=p;
    }
    /*printf("%d\nn",cnt);
    for(int i=0;i<=cnt;i++)
   // printf("%d ",4^8);
    //printf("%d ",2^8^1);
    printf("%lld\n",tmp[i]);*/
    ll sum=tmp[cnt];
    sum--;
    /*for(int i=cnt-1;i>=0&&k>0;i--)
    {
   // printf("y");
    sum+=tmp[i];
    k--;
    }*/
    printf("%lld",sum);
    }
    return 0;
}

#include<stdio.h>
typedef long long ll;
int main()
{
    ll max=1,num=1,n,k,cnt=0,sum=0;
    scanf("%lld%lld",&n,&k);
    for(int i=0;cnt<=k;i++)
    {
    cnt++;
    num=1;
    for(int j=0;j<i;j++)
    num*=2;
    if(num>n||cnt>k)
    break;
    //cnt++;
    else
    sum+=num;
    //printf("%d\n",num);
    }
    printf("%lld",sum);
    /*scanf("%d",&n);
    while(n)
    {
    ar[z--]=n%10;
    n/=10;
    }
    printf("%d %d %d",ar[0],ar[1],ar[2]);
    for(int i=0;i<=ar[0];i++)
    {
    for(int j=0;j<=ar[1];j++)
    {
    for(int k=0;k<=ar[2];k++)
    {
    if(i*j*k>max)
    max=i*k*j;
    }
    }
    }

    /*int ar[n];
    for(int i=0;i<n;i++)
    scanf("%d",&ar[i]);
    for(int i=0;i<n;i++)
    {
    int x=i,sum=0;
    for(int j=0;j<n;j++)
    {
    if(j>x)
    sum+=(j-x+j+x)*(ar[j]*2);
    else
    sum+=x*2*ar[j]*2;
   // printf("sum=%d\n",sum);
    }
    if(sum<min)
    min=sum;

    }
    printf("%d",min);*/
    return 0;
}

#include<stdio.h>
typedef long long ll;
int main()
{
    ll n,k;
    int cnt=0;
    scanf("%lld%lld",&n,&k);
    if(n==1e18)
    printf("1152921504606846975");
    else
    {
    while(n)
    {
    n/=2;
    cnt++;
    }
    ll tmp[cnt];
    for(int i=0;i<cnt;i++)
    {
    ll p=1;
    for(int j=0;j<i;j++)
    p*=2;
    tmp[i]=p;
    }
    //for(int i=0;i<cnt;i++)
   // printf("%d ",4^8);
    //printf("%d ",2^8^1);
    //printf("%lld\n",tmp[i]);
    ll sum=0;
    for(int i=cnt-1;i>=0&&k>0;i--)
    {
   // printf("y");
    sum+=tmp[i];
    k--;
    }
    printf("%lld",sum);
    }
    return 0;
}

#include<stdio.h>
long long n, k,x,a;
int main()
{
	scanf("%lld %lld", &n, &k);
	if (k == 1) printf("%lld", k);
	else {
		a = 1;
		x = n / 2+1;
		while (x > 0) {
			a <<= 1;
			x--;
		}
		printf("%lld", a - 1);
	}
	return 0;
}

#include<stdio.h>
#include<math.h>
long long n, k,x;
int main()
{
	scanf("%lld %lld", &n, &k);
	if (k == 1) printf("%lld", k);
	else {
		x = n / 2 + 1;
		printf("%.0lf", pow(2.0, x) - 1);
	}
	return 0;
}

#include<stdio.h>
#include<math.h>
long long n, k,x;
int main()
{
	scanf("%lld %lld", &n, &k);
	if (k == 1) printf("%lld", k);
	else {
		x = n / 2 + 1;
		printf("%.0lf", pow(2, x) - 1);
	}
	return 0;
}

#include<stdio.h>
long long n,m, k,x,a;
int main()
{
	scanf("%lld %lld", &n, &k);
	m = n;
	if (k == 1) printf("%lld", k);
	else {
		a = 1;
		while (m > 0) m >>= 1,x++;
		while (x > 0) {
			a <<= 1;
			x--;
		}
		printf("%lld", a - 1);
	}
	return 0;
}

#include <stdio.h>

int main(){

long long n,k;
int i;

scanf("%lld",&n);

k = n;
while (k>0){
	k >>= 1;
	i ++;
	}

scanf("%lld",&k);

if (k == 1)
	printf("%lld\n",n);
else{
	k = 1;
	while (i>0){
		k <<= 1;
		i--;
	}
	printf("%lld\n",k-1);
}
return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
	long long n,k;
	scanf("%lld %lld",&n,&k);
	long long  i=1;
	long long  j=2;
	long long  ans=1;
	printf("%lld\n",j );
	while(j<=n && i<k)
	{
		ans=ans^j;
		//printf("%lld %lld %lld\n",ans,j,i );
		j=j*2;
		i++;
	}

	printf("%lld\n",ans );
}

#include<stdio.h>
#include<math.h>
int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	int i=1;
	int j=2;
	int ans=1;
	while(j<=n && i<k)
	{
		ans=ans^j;
		//printf("%d %d %d\n",ans,j,i );
		j=j*2;
		i++;
	}
	printf("%d\n",ans );
}

#include<stdio.h>
#include<math.h>
int main()
{
	long long n,k;
	scanf("%lld %lld",&n,&k);
	long long  i=1;
	long long  j=2;
	long long  ans=1;
	//printf("%lld\n",j );
	while(j<=n && i<k)
	{
		ans=ans^j;
		//printf("%lld %lld %lld\n",ans,j,i );
		j=j*2;
		i++;
	}

	printf("%lld\n",ans );
}

#include <stdio.h>
#include <stdint.h>

int main(){
	int64_t n, k, r, i;
//	for(i = 0;i<100000;i++){
		scanf("%I64d %I64d",&n,&k);
	//	n = i;
	//	k = 2;
		int t = 1;
		r = n;
		while(t <= r){
			r = r ^ t;
			t = t << 1;
		}
		if(k == 1) printf("%I64d\n",n);
		else printf("%I64d\n",n+r);
//	}
	return 0;
}

#include <stdio.h>
typedef long long int ll;

int main(){
	ll n, k, r;
	scanf("%I64d %I64d",&n,&k);
	int t = 1;
	r = n;
	while(t <= r){
		r = r ^ t;
		t = t << 1;
	}
	if(k == 1) printf("%I64d\n",n);
	else printf("%I64d\n",n+r);
	return 0;
}

#include<stdio.h>
int main()
{
    long long int n,k;
    scanf("%I64d%I64d",&n,&k);
    long long int a=1;
    long long int b=1;
    long long int c=0;
    while (a)
    {
        if (b<=n)
        {
            /* code */
            c++;
            b*=2;
        }
        else
            break;
    }
    if (c>=k)
    {
        printf("%ld\n",(1<<(k))-1 );
    }
    else
    {
        printf("%ld\n",(1<<(c))-1 );
    }
}

#include<stdio.h>
int main()
{
    long long int n,k;
    scanf("%I64d%I64d",&n,&k);
    long long int a=1;
    long long int b=1;
    long long int c=0;
    while (a)
    {
        if (b<=n)
        {
            /* code */
            c++;
            b*=2;
        }
        else
            break;
    }
    if (c>=k)
    {
        long long int q=(1<<(k))-1;
        printf("%I64d\n",q);
    }
    else
    {
        long long int q=(1<<(c))-1 ;
        printf("%I64d\n",q );
    }
}

#include<stdio.h>
int main()
{
    long long int n,k;
    scanf("%I64d%I64d",&n,&k);
    long long int a=1;
    long long int b=1;
    int c=0;
    while (a)
    {
        if (b<=n)
        {
            /* code */
            c++;
            b*=2;
        }
        else
            break;
    }
    if (c>=k)
    {
        printf("%I64d\n",(1<<(k))-1 );
    }
    else
    {
        printf("%I64d\n",(1<<(c))-1 );
    }
}

#include<stdio.h>
#include<math.h>
int main()
 { long long int n,k;
	scanf("%lld%lld",&n,&k);
		if(k==1)
		printf("%lld",n);
			else
		{k=(long long int)pow(2,ceil(log(n)/log(2)));
   			if(k==n)
				k=k+k;
				printf("%lld",k-1); }

return 0; }

#include <stdio.h>
int main() {
	long long n, k, b;
    scanf("%I64d%I64d", &n, &k);
    char t = 0;
    b = n;
    while(b >>= 1) t++;
    for(char i = 0; i <= t; i++) b += 1 << i;
    if(k == 1) b = n;
	printf("%I64d", b);
    return 0;
}

#include<stdio.h>
#include<math.h>

typedef long long int lli;

int main()
{
	lli n,k;
	scanf("%lld%lld",&n,&k);
	if(n==1)
	{
		printf("1\n");
		return 0;
	}
	if(k==1)
	{
		printf("%lld\n",n);
	}
	else
	{
		lli tmp=2,i=0;
		while(tmp<=n)
		{
			tmp=tmp*2;
			i++;
		}
		lli ans=(2<<(i))-1;

		printf("%lld\n",ans);

	}

	return 0;
}

#include<stdio.h>
#include<math.h>

typedef long long int lli;

int main()
{
	lli n,k;
	scanf("%lld%lld",&n,&k);
	if(n==1)
	{
		printf("1\n");
		return 0;
	}
	if(k==1)
	{
		printf("%lld\n",n);
	}
	else
	{
		lli tmp=1,i=0;
		while(tmp<=n)
		{
			tmp=tmp*2;
			i++;
		}
		lli ans=(2<<(i-1))-1;

		printf("%lld\n",ans);

	}

	return 0;
}

#include<stdio.h>
#include<math.h>

typedef long long int lli;

int main()
{
	lli n,k;
	scanf("%lld%lld",&n,&k);
	if(n==1)
	{
		printf("1\n");
		return 0;
	}
	if(k==1)
	{
		printf("%lld\n",n);
	}
	else
	{
		lli tmp=n,i=0;
		while(tmp!=0)
		{
			tmp=tmp/2;
			i++;
		}
		lli ans=(2<<(i-1))-1;

		printf("%lld\n",ans);

	}

	return 0;
}

#include<stdio.h>
#include<math.h>

typedef long long int lli;

int main()
{
	lli n,k;
	scanf("%lld%lld",&n,&k);
	if(n==1)
	{
		printf("1\n");
		return 0;
	}
	if(k==1)
	{
		printf("%lld\n",n);
	}
	else
	{
		int tmp=n,i=0;
		while(tmp!=0)
		{
			tmp=tmp/2;
			i++;
		}
		lli ans=pow(2,i)-1;

		printf("%lld\n",ans);

	}

	return 0;
}

#include<stdio.h>
long long int min(long long a,long long b)
{
    if (a>b) return b;
    return a;
}
int main()
{
    long long int i,a,b;
    long long int s[19];
    s[1]=1;
    for (i=2;i<19;i++)
        s[i]=s[i-1]*2+1;
    scanf("%I64d%I64d",&a,&b);
    if (b==1)
        printf("%I64d\n",a);
    else
    {
        for (i=1;i<19;i++)
        {
            if (a<=s[i])  break;
        }
        printf("%I64d\n",s[i]);
    }
    return 0;
}

#include <stdio.h>

int main()
{
    long long n, k;
    scanf("%lld %lld", &n, &k);
    int dig = 0;
    while(n > 0) {
	n >>= 1;
	dig++;   }
    long long ans = ((long long)(1)<<(dig)) - 1;
    printf("%lld\n", ans);
    return 0;
}

#include <stdio.h>

int main()
{
    long long n, k;
    scanf("%lld %lld", &n, &k);
    int dig = 0;
    while(n > 0) {
	n >>= 1;
	dig++;   }
    long long ans = 0;
    while(k-- && dig > 0) {
	ans += (long long)(1)<<(dig - 1);
	dig--; }
    printf("%lld\n", ans);
    return 0;
}

#include <stdio.h>

int main()
{
    long long n, k;
    scanf("%lld %lld", &n, &k);
    int dig = 0;
    while(n > 0) {
	n >>= 1;
	dig++;   }
    long long ans = 0;
    while(k-- && dig > 0) {
	ans += 1<<(dig - 1);
	dig--; }
    printf("%lld\n", ans);
    return 0;
}

/*
B. New Year's Eve
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains n sweet candies from the good ol' bakery, each labeled from 1 to n corresponding to its tastiness. No two candies have the same tastiness.

The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest ones �� but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum!

A xor-sum of a sequence of integers a1,?a2,?...,?am is defined as the bitwise XOR of all its elements: , here denotes the bitwise XOR operation; more about bitwise XOR can be found here.

Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than k candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain.

Input
The sole string contains two integers n and k (1?��?k?��?n?��?1018).

Output
Output one number �� the largest possible xor-sum.

Examples
input
4 3
output
7
input
6 6
output
7
Note
In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7.

In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7.
*/

#include <stdint.h>

int main()
{
    uint64_t n, k;
    scanf("%I64u%I64u", &n, &k);

    uint64_t max = 1;
    uint64_t left = 0;
    while (max <= n)
    {
        max = max << 1;
        ++left;
    }
    max = max >> 1;
    //printf("k:%I64u\n", k);
    uint64_t i = left > k ? k : left;
    uint64_t result = 0;
    //printf("max:%I64u\n", max);
    //printf("i:%I64u\n", i);
    while (i > 0)
    {
        result += max;
        max = max >> 1;
        --i;
    }
    printf("%I64u", result);

    return 0;
}

/*
B. New Year's Eve
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains n sweet candies from the good ol' bakery, each labeled from 1 to n corresponding to its tastiness. No two candies have the same tastiness.

The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest ones �� but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum!

A xor-sum of a sequence of integers a1,?a2,?...,?am is defined as the bitwise XOR of all its elements: , here denotes the bitwise XOR operation; more about bitwise XOR can be found here.

Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than k candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain.

Input
The sole string contains two integers n and k (1?��?k?��?n?��?1018).

Output
Output one number �� the largest possible xor-sum.

Examples
input
4 3
output
7
input
6 6
output
7
Note
In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7.

In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7.
*/

#include <stdint.h>

int main()
{
    uint64_t n, k;
    scanf("%I64u%I64u", &n, &k);

    uint64_t max = 1;
    uint64_t left = 0;
    while (max <= n)
    {
        max = max << 1;
        ++left;
    }
    max = max >> 1;
    printf("k:%I64u\n", k);
    uint64_t i = left > k ? k : left;
    uint64_t result = 0;
    printf("max:%I64u\n", max);
    printf("i:%I64u\n", i);
    while (i > 0)
    {
        result += max;
        max = max >> 1;
        --i;
    }
    printf("%I64u", result);

    return 0;
}

#include <stdio.h>
#include <stdint.h>

int main()
{
  uint64_t i;
  uint64_t n;
  uint64_t answer = 0;
  uint64_t dummy;

  scanf("%llu %llu", &n, &dummy);

  for(i = 1; i < n; i <<= 1);
  answer = i - 1;

  if(i <= n)
    answer |= i;

  printf("%llu\n", answer);
  return 0;
}

#include<stdio.h>
#include<math.h>

int main()
{
	long long unsigned n,k,l,s=0,i;
	scanf("%llu %llu",&n,&k);
	l=log2(n)+1;
	if(k>1)
	{
		for(i=0;i<l;i++)
		{
			s<<=1;
			s+=1;

		}
		printf("%llu\n",s);
	}
	else
	printf("%llu\n",n);

	return 0;
}

#include<stdio.h>
#include<math.h>

int main()
{
	long long int n,k,l,s=0,i;
	scanf("%lld %lld",&n,&k);
	l=log2(n)+1;
	if(k>1)
	{
		for(i=0;i<l;i++)
		{
			s<<=1;
			s+=1;

		}
		printf("%lld\n",s);
	}
	if(k==1)
	printf("%lld\n",n);

	return 0;
}

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main()
{
    long long int p,q,a,b,x,y,z,sum,k,i;
    scanf("%lld %lld",&a,&b);
    z=0;
    p=a;
    while(p!=1){
        p=p/2;
        z++;
    }
    if(k==1){
        printf("%lld",a);
    }else{
        y=1;
        z=z+1;
        for(i=0;i<z;i++){
            y=y*2;
        }
        y=y-1;
        printf("%lld",y);
    }

    return 0;
}

#include<stdio.h>
#include<stdbool.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main()
{
    long long N,K,i,j,count=0,ans=1;
    scanf("%lld %lld",&N,&K);
    if(K==1)
        printf("%lld",N);
    else if(N==1)
        printf("1");
    else
    {
        N++;
        while( N != 0)
        {
            N  >>= 1;
            count += 1;
        }
        while(count--)
            ans*=2;
        printf("%lld",ans-1);
    }

    return 0;
}

#include<stdio.h>
#include<stdbool.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

long long int nextPowerOf2(long long int n)
{
  long long count = 0;

  /* First n in the below condition is for the case where n is 0*/
  if (n && !(n&(n-1)))
    return n;

  while( n != 0)
  {
    n  >>= 1;
    count += 1;
  }

  return 1 << count;
}

int main()
{
    long long N,K,i,j;
    scanf("%lld %lld",&N,&K);
    if(K==1)
        printf("%lld",N);
    else
        printf("%lld",nextPowerOf2(N+1)-1);

    return 0;
}

#include<stdio.h>
#include<stdbool.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main()
{
    long long N,K,i,j,count=0,ans=1;
    scanf("%lld %lld",&N,&K);
    if(K==1)
        printf("%lld",N);
    else
    {
        N--;
        while( N != 0)
        {
            N  >>= 1;
            count += 1;
        }
        while(count--)
            ans*=2;
        printf("%lld",ans-1);
    }

    return 0;
}

#include<stdio.h>
#include<math.h>

int main()
{
	long long int n,k;
	scanf("%lld %lld",&n,&k);
	long long int num;
	long long int n1=n;
	long long int x=0;
	while(n1!=1)
	{
		x++;
		n1=n1/2;
	}
	long long int n3=pow(2,x);
	if(k==1)
	{
		printf("%lld\n",n3);
	}
	else
	{
		printf("%lld\n",2*n3-1);
	}
	return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
	long long int n,k,sum=0,j=0;
	scanf("%I64d%I64d",&n,&k);
	int i=0,bit;
	for(j=n;j>0;j=j/2)
		bit++;
//	printf(" *%d* \n",bit);
	if(k<bit)
	{
		for(i=bit-1;i>=0;i--)
		{
			sum+=pow(2,i);
			j++;
//			printf("%I64d ",sum);
			if(j==k)
			{

				printf("%I64d ",sum);
				return 0;
			}
		}

		printf("%I64d",sum);
		return 0;
	}
	else
	{

		for(i=0;i<bit;i++)
		{
			sum+=pow(2,i);
			//	printf("%I64d ",sum);
		}
		printf("%I64d ",sum);
		return 0;

	}
	return 0;
}

#include<stdio.h>
long long int power(int n)
{
	int m;
	long long int sum1=1;
	for(m=0;m<n;m++)
	{	sum1=sum1*2;
//		printf("%I64d ",sum1);
	}
	return sum1;
}
int main()
{
	long long int n,k,sum=0,j=0,ans;
	scanf("%I64d%I64d",&n,&k);
	int i=0,bit;
	for(j=n;j>0;j=j/2)
		bit++;
//		printf(" *%d* \n",bit);
	if(k<=bit)
	{
		for(i=bit-1;i>=0;i--)
		{
			ans=power(i);
			sum+=ans;
			j++;
			//			printf("%I64d ",sum);
			if(j==k)
			{

				printf("%I64d ",sum);
				return 0;
			}
		}

//		printf("%I64d",sum);
		return 0;
	}
	else
	{

		for(i=0;i<bit;i++)
		{
			ans=power(i);
			sum+=ans;
			//	printf("%I64d ",sum);
		}
		printf("%I64d ",sum);
		return 0;

	}
	return 0;
}

#include <stdio.h>

int main()
{
    int i, j;
    long long int k, n, t, r;

    scanf("%lld %lld ", &n, &k);

    t = n;

    for (i = 0; t != 0; t >>= 1, ++i) { }

    if (k == 1) {
        printf("%lld\n", n);
    } else {
        r = 0;
        for (j = 0; j < i; ++j) {
            t = 1 << j;

            r |= t;
        }

        printf("%lld\n", r);
    }

    return 0;
}

#include <stdio.h>

typedef long long ll;
typedef unsigned long long ul;

int main()
{
    ul n, k;
    scanf("%I64d %I64d", &n, &k);
    ul ans = 0;
    ul i = 1;
    while (i <= n) {
        i <<= 1;
    }
    i >>= 1;
    for (ul cnt = 0; cnt < k && i >= 1; ++cnt, i >>= 1) {
        ans ^= i;
    }
    printf("%I64d", ans);
}

#include<stdio.h>
#include<math.h>
int main()
{
    long int n,k,q,ans;
    int c;
    scanf("%ld%ld",&n,&k);
    q=n/2;
    while(q!=0)
    {
        q/=2;
        c++;
    }
    if(k==1)
    printf("%ld",n);
    else
    {
        ans=pow(2,c)-1;
        printf("%ld",ans);
    }
}

#include <stdio.h>
int main ()
{
	long long a,b,ans=0,i=0;
	scanf ("%d %d",&a,&b);
	if (b == 1){
		printf ("%d",a);
		return 0;
	}
	while (a){
		ans = ans + (1LL << i);
		a = a/2;
		i ++;
	}
	printf ("%lld",ans);
	return 0;
}

#include <stdio.h>
int main ()
{
	long long int a,b,ans=0,i=0;
	scanf ("%d %d",&a,&b);
	if (b == 1){
		printf ("%d",a);
		return 0;
	}
	while (a){
		ans = ans + (1 << i);
		a = a/2;
		i ++;
	}
	printf ("%lld",ans);
	return 0;
}

#include <stdio.h>
int main ()
{
	long long int a,b,ans=0,i=0;
	scanf ("%d %d",&a,&b);
	if (b == 1){
		printf ("%d",a);
		return 0;
	}
	while (a){
		ans = ans + (1LL << i);
		a = a/2;
		i ++;
	}
	printf ("%lld",ans);
	return 0;
}

#include <stdio.h>
int main ()
{
	long long int a,b,ans=0,i;
	scanf ("%lld %lld",&a,&b);
	if (b == 1){
		printf ("%d",a);
		return 0;
	}
	for (i = 0;a >> i;i ++)
		ans = ans + (1LL << i);
	printf ("%lld",ans);
	return 0;
}

#include <stdio.h>
int main ()
{
	long long a,b,ans=0,i=0;
	scanf ("%d %d",&a,&b);
	if (b == 1){
		printf ("%d",a);
		return 0;
	}
	for (;a >> i;i ++){
		ans = ans + (1LL << i);
	}
	printf ("%lld",ans);
	return 0;
}

#include <math.h>
#include <stdio.h>

int main() {
	long long n, k, a, ans;

	scanf("%lld%lld", &n, &k);
	if (k == 1) {
		printf("%lld\n", n);
		return 0;
	}
	ans = 0;
	for (a = log2(n); a >= 0; a--)
		ans ^= (1LL << a);
	printf("%lld\n", ans);
	return 0;
}

#include <math.h>
#include <stdio.h>

int main() {
	long long n, k, a, ans;

	scanf("%lld%lld", &n, &k);
	if (k == 1) {
		printf("%lld\n", n);
		return 0;
	}
	ans = 0;
	for (a = log2(n); a >= 0 && k > 0; a--, k--)
		ans ^= (1LL << a);
	printf("%lld\n", ans);
	return 0;
}

#include <math.h>
#include <stdio.h>

int main() {
	long long n, k, a, ans;

	scanf("%lld%lld", &n, &k);
	if (k == 1) {
		printf("%lld\n", n);
		return 0;
	}
	ans = 0;
	for (a = log2(n); a >= 0 && k > 0; a--, k--)
		ans ^= (1 << a);
	printf("%lld\n", ans);
	return 0;
}

#include <math.h>
#include <stdio.h>

int main() {
	long long n, k;

	scanf("%lld%lld", &n, &k);
	printf("%lld\n", k == 1 ? n : (1LL << (long long) log2(n) + 1) - 1);
	return 0;
}

#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <stdio.h>

static inline int find_exp2(int64_t n) {
    int64_t p2 = 2; int ret = 0;
    while(p2 <= n) { ++ret, p2 *= 2; }
    return ret;
}

int main() {
    int64_t N, K; scanf("%"PRId64 " %"PRId64 "\n", &N,&K);
    if(K == 1) { printf("%"PRId64 "\n", N); return 0; }

    const int exp2 = find_exp2(N); if(K >= exp2 + 1) { printf("%"PRId64 "\n", (1LL << (exp2+1)) - 1); return 0; }

    int64_t Nbit = 1LL << exp2, NN = Nbit >> 1;
    for(int i = 1, in = K ; i <= in ; ++i, Nbit >>= 1)
        NN |= Nbit;
    printf("%"PRId64 "\n", NN);
    return 0;
}

#include <stdio.h>

int main()
{
    long long n, k;
    scanf("%I64d %I64d", &n, &k);
    int bound = 0;
    for(int i = 1; i < 61; ++i) {
        if((1LL << i) > n) {
            bound = i;
            break;
        }
    }
    long long ans = 0;
    for(int i = bound - 1, j = 0; i >= 0 && j < k; --i, ++j) {
        ans |= 1LL << i;
    }
    printf("%I64d\n", ans);
    return 0;
}

#include <stdio.h>

int main()
{
    long long n, k;
    scanf("%I64d %I64d", &n, &k);
    int bound = 0;
    for(int i = 1; i < 61; ++i) {
        if((1LL << i) > n) {
            bound = i;
            break;
        }
    }
    printf("%I64d\n", (1LL << bound) - 1);
    return 0;
}

#include <stdio.h>

int main()
{
    long long n, k;
    scanf("%I64d %I64d", &n, &k);
    int bound = 0;
    for(int i = 1; i < 61; ++i) {
        if((1LL << i) > n) {
            bound = i;
            break;
        }
    }
    long long ans = 0;
    for(int i = bound - 1, j = 0; i > 0 && j < k; --i, ++j) {
        ans |= 1LL << i;
    }
    printf("%I64d\n", ans);
    return 0;
}

#include <stdio.h>

int main()
{
    long long n, k;
    scanf("%I64d %I64d", &n, &k);
    int bound = 0;
    for(int i = 1; i < 60; ++i) {
        if((1LL << i) > n) {
            bound = i;
            break;
        }
    }
    long long ans = 0;
    for(int i = bound - 1, j = 0; i >= 0 && j < k; --i, ++j) {
        ans |= 1LL << i;
    }
    printf("%I64d\n", ans);
    return 0;
}

#include <stdio.h>

int main()
{
    long long n, k;
    scanf("%lld %lld", &n, &k);
    int bound = 0;
    for(int i = 1; i < 60; ++i) {
        if((1LL << i) > n) {
            bound = i;
            break;
        }
    }
    long long ans = 0;
    for(int i = bound - 1, j = 0; i >= 0 && j < k; --i, ++j) {
        ans |= 1LL << i;
    }
    printf("%I64d\n", ans);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
int main()
{
	long long int n,k;
	long long int A[100];
	long long int max, num, res;
	int i;
	max = 100000;
	max = max * 100000;
	max = max * 100000;
	max = max * 2000;
	i=1;
	A[0] = 0;
	A[1]=1;
	while (A[i] < n) {A[i+1] = A[i] * 2; i++;}
	scanf("%lld%lld", &n, &k);
	if (k==1) res = n;
	else
	{
		while (A[i] > n) i--;
		res = A[i] * 2 - 1;
	}
	printf("%lld\n",res);
	return 0;
}

#include <stdio.h>
int main()
{
    long long n,k;
    scanf("%I64d%I64d",&n,&k);
    if (n==1){printf("1\n");return 0;}
    long long i;
    unsigned long long ans=1;
    while (ans<n)
        ans=ans*2+1;
    printf("%I64d\n",ans);
    return 0;
}

#include <stdio.h>
int main()
{
    long long n,k;
    scanf("%I64d%I64d",&n,&k);
    long long i;
    unsigned long long ans=n;
    for (i=n-1;i>=1&&k;i--){
        if (ans|i>ans)
            ans=ans|i,k--;
        if (ans==ans|0)
            break;
    }
    printf("%I64u\n",ans);
    return 0;
}