import java.util.*

fun exp(d: Int): Long {
    var ans: Long = 1
    for (i in 1..d-1) {
        ans *= 2
    }
    return ans
}


fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    var a = cin.nextLong()
    var b = cin.nextLong()
    var at: Long = a
    var bt: Long = b
    var ad: Int = 0
    var bd: Int = 0
    while (b > 0) {
        at = a
        bt = b
        ad = 0
        bd = 0
        while (bt > 0) {
            if (at > 0) {
                ad += 1
            }
            at = (at shr 1)
            bt = (bt shr 1)
            bd += 1
        }
        if (ad != bd) {
            break
        }
        val top = exp(ad)
        a = a - top
        b = b - top
    }
    if (b == 0.toLong()) {
        println(1)
    } else {
        val e = exp(bd)
        var non_top = b - e
        var non_top_d: Int = 0
        while (non_top > 0) {
            non_top = (non_top shr 1)
            non_top_d += 1
        }
        val temp = exp(non_top_d+1) - 1
        val under = e - a
        if (temp + under > e - 1) {
            println(e*2 - a)
        } else {
            println(e + temp - a + 1 + under)
        }
    }
}