
class Entry():
    def __init__(self):
        self.M = ''
        self.lf, self.uf = False, False
        self.idx = 0

    def nexts(self, bit, lf=None, uf=None):
        """ Generate next Entry (idx+=1). If you need to set lf or uf, just
        give it as argument."""
        r = Entry()
        r.M = self.M + bit
        r.lf = self.lf if lf==None else lf
        r.uf = self.uf if uf==None else uf
        r.idx = self.idx + 1
        return r

    def get(self, length):
        """ Return the M filled with 1 so that len(M)==length. """
        return '{1:1<{0}}'.format(length, self.M)

    def __repr__(self):
        """ for debug. """
        return 'Entry(M=%s, idx=%s, uf=%s ,lf=%s)'%(
            repr(self.M), self.idx, self.uf, self.lf)


def main(U, L, N):

    # translate U L to binary string.
    ub = bin(U)[2:]
    lb = bin(L)[2:]

    # let len(lb) == len(ub), filled with 0.
    length = len(ub)
    lb = '{1:0>{0}}'.format(length, lb)

    queue = [Entry()]   # start from (M='', idx=0, uf=False, lf=False)
    candidates = []     # all candidates.
    cnt = 0             # while counter, for test efficiency.

    while queue:        # do while the queue is not empty.
        cnt += 1
        now = queue.pop(0)

        # if both uf lf are set, we get a candidate.
        if now.uf and now.lf:
            candidates.append(now.get(length))
            continue
        
        # if length is too large, this path is failed.
        if now.idx >= length: continue
        
        # 4 conditions.
        if   ub[now.idx] + lb[now.idx] == '10':
            queue.append(now.nexts('1', lf=True))
            queue.append(now.nexts('0', uf=True))
            
        elif ub[now.idx] + lb[now.idx] == '01':
            if   now.lf:    queue.append(now.nexts('0'))
            elif now.uf:    queue.append(now.nexts('1'))
            else:           pass    # cut
        
        elif ub[now.idx] + lb[now.idx] == '00':
            if not now.uf:  queue.append(now.nexts('0'))
            else:           queue.append(now.nexts('1', lf=True))
        
        elif ub[now.idx] + lb[now.idx] == '11':
            if not now.lf:  queue.qppend(now.nexts('1'))
            else:
                queue.append(now.nexts('0', uf=True))
                queue.append(now.nexts('1'))
    
    print candidates
    print 'len of candidates =', len(candidates)
    print 'cnt =', cnt
    print '-'*50
    
    ans = max((int(c,2) | N, c) for c in candidates)
    print 'when M = %s(%s) has max.'%(ans[1], int(ans[1],2))
    print 'M | N =', ans[0]
    

if __name__=='__main__':
    main(int(raw_input('U=')), int(raw_input('L=')), int(raw_input('N=')))
	