import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author AlexFetisov
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        long n = in.nextInt();
        long x = in.nextInt();
        long y = in.nextInt();
        long c = in.nextInt();
        if (c == 1) {
            out.println(0);
            return;
        }

        long left = 1, right = 2 * n, middle, res = -1;
        long val = getNumberOfCells(x, y, n, 2);

        while (left <= right) {
            middle = (left + right) / 2;
            long numberOfCells = getNumberOfCells(x, y, n, middle);
            if (numberOfCells < c) {
                left = middle + 1;
            } else {
                res = middle;
                right = middle - 1;
            }
        }
        out.println(res);
    }

    private long getNumberOfCells(long x, long y, long n, long middle) {
        long res = 0;
        res += calc(x, y, middle + 1);
        res += calc(n - x + 1, y, middle + 1);
        res += calc(x, n - y + 1, middle + 1);
        res += calc(n - x + 1, n - y + 1, middle + 1);
        res -= calcX(x, n, middle);
        res -= calcX(y, n, middle);
        --res;
        return res;
    }

    private long calcX(long x, long n, long size) {
        long left = x - size;
        long right = x + size;
        left = Math.max(left, 1);
        right = Math.min(right, n);
        if (left <= right) {
            return right - left + 1;
        }
        return 0;
    }

    private long calc(long x, long y, long size) {
        if (size <= Math.min(x, y)) {
            return (1 + size) * size / 2;
        }
        if (size >= x + y - 1) {
            return x * y;
        }
        if (size > Math.max(x, y)) {
            return x * y - calc(x, y, x + y - 1 - size);
        }
        long min = Math.min(x, y);
        long res = (1 + min) * min / 2;
        long rest = size - min;
        res += rest * min;
        return res;
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer stt;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            return null;
        }
    }

    public String nextString() {
        while (stt == null || !stt.hasMoreTokens()) {
            stt = new StringTokenizer(nextLine());
        }
        return stt.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

}


import java.io.*;
import java.util.*;

public class BBi implements Runnable {
	public static void main(String[] args) {
		new Thread(new BBi()).run();
	}

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer in;
	PrintWriter out = new PrintWriter(System.out);

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}

		return in.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	int n, x, y;

	public long count(long z) {
		long total = 0;

		long[][] c = new long[][] { { x, y }, { y, n - x + 1 },
				{ n - x + 1, n - y + 1 }, { n - y + 1, x } };

		for (int i = 0; i < c.length; i++) {
			long inside = z;

			for (int j = 0; j < c[i].length; j++) {
				if (z > c[i][j]) {
					total += Math.min(z - c[i][j], c[i][1 - j]) * c[i][j];
					inside -= (z - c[i][j]);
				}
			}

			if (z > c[i][0] && z > c[i][1]) {
				total -= Math.min(z - c[i][0], c[i][1])
						* Math.min(z - c[i][1], c[i][0]);
			}

			if (inside > 0)
				total += inside * (inside + 1) / 2;
		}

		for (int i = 0; i < c.length; i++) {
			total -= Math.min(z, c[i][0]);
		}

		return total + 1;
	}

	public long solve(int n, int x, int y, long c) throws IOException {
		this.n = n;
		this.x = x;
		this.y = y;

		long l = 0;
		long r = 2L * n + 2;
		while (r - l > 1) {
			long z = (l + r) / 2;

			if (c <= count(z)) {
				r = z;
			} else {
				l = z;
			}
		}

		return r - 1;
	}

	public void run() {
		try {
			out.println(solve(nextInt(), nextInt(), nextInt(), nextLong()));
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}


import java.io.*;
import java.lang.reflect.*;
import java.util.*;

public class B {

	final int MOD = (int)1e9 + 7;
	final double eps = 1e-12;
	final int INF = (int)1e9;

	public B () {
		long N = sc.nextInt();
		long X = sc.nextInt() - 1;
		long Y = sc.nextInt() - 1;
		long C = sc.nextInt();

		long [] A1 = new long [] { X, Y };
		long [] A2 = new long [] { X, Y };
		long [] B1 = new long [] { X, Y };
		long [] B2 = new long [] { X, Y };
		long [] C1 = new long [] { X, Y };
		long [] C2 = new long [] { X, Y };
		long [] D1 = new long [] { X, Y };
		long [] D2 = new long [] { X, Y };

		long cnt = 1, T = 0;

		while (cnt < C) {
			if (A1[0] > 0) --A1[0]; else --A1[1];
			if (A2[0] > 0) --A2[0]; else ++A2[1];

			if (B1[1] > 0) --B1[1]; else --B1[0];
			if (B2[1] > 0) --B2[1]; else ++B2[0];

			if (C1[0] < N-1) ++C1[0]; else --C1[1];
			if (C2[0] < N-1) ++C2[0]; else ++C2[1];

			if (D1[1] < N-1) ++D1[1]; else --D1[0];
			if (D2[1] < N-1) ++D2[1]; else ++D2[0];

			long [] Z = { B1[0] - A1[0],
						  C1[0] - B2[0],
						  C2[0] - D2[0],
						  D1[0] - A2[0] };

			for (long z : Z)
				if (z >= 0)
					cnt += (z+1);

			if (Arrays.equals(A1, A2)) --cnt;
			if (Arrays.equals(B1, B2)) --cnt;
			if (Arrays.equals(C1, C2)) --cnt;
			if (Arrays.equals(D1, D2)) --cnt;

			++T;
		}

		exit(T);
	}

	////////////////////////////////////////////////////////////////////////////////////

	static MyScanner sc;

	static class MyScanner {
		public String next() {
			newLine();
			return line[index++];
		}

		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			line = null;
			return readLine();
		}

		public String [] nextStrings() {
			line = null;
			return readLine().split(" ");
		}

		public char [] nextChars() {
			return next().toCharArray();
		}

		public Integer [] nextInts() {
			String [] L = nextStrings();
			Integer [] res = new Integer [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Integer.parseInt(L[i]);
			return res;
		}

		public Long [] nextLongs() {
			String [] L = nextStrings();
			Long [] res = new Long [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Long.parseLong(L[i]);
			return res;
		}

		public Double [] nextDoubles() {
			String [] L = nextStrings();
			Double [] res = new Double [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Double.parseDouble(L[i]);
			return res;
		}

		//////////////////////////////////////////////

		private boolean eol() {
			return index == line.length;
		}

		private String readLine() {
			try {
				return r.readLine();
			} catch (Exception e) {
				throw new Error(e);
			}
		}
		private final BufferedReader r;

		MyScanner () {
			this(new BufferedReader(new InputStreamReader(System.in)));
		}

		MyScanner(BufferedReader r) {
			try {
				this.r = r;
				while (!r.ready())
					Thread.sleep(1);
				start();
			} catch (Exception e) {
				throw new Error(e);
			}
		}

		private String [] line;
		private int index;

		private void newLine() {
			if (line == null || eol()) {
				line = readLine().split(" ");
				index = 0;
			}
		}
	}

	static void print (Object o, Object... a) {
		pw.println(build(o, a));
	}

	static void exit (Object o, Object... a) {
		print(o, a);
		exit();
	}

	static void exit () {
		pw.close();
		System.out.flush();
		System.err.println("------------------");
		System.err.println("Time: " + ((millis() - t) / 1000.0));
		System.exit(0);
	}

	void NO() {
		throw new Error("NO!");
	}

	////////////////////////////////////////////////////////////////////////////////////

	static String build(Object... a) {
		StringBuilder b = new StringBuilder();
		for (Object o : a)
			append(b, o);
		return b.toString().trim();
	}

	static void append(StringBuilder b, Object o) {
		if (o.getClass().isArray()) {
			int L = Array.getLength(o);
			for (int i = 0; i < L; ++i)
				append(b, Array.get(o, i));
		} else if (o instanceof Iterable<?>) {
			for (Object p : (Iterable<?>)o)
				append(b, p);
		} else
			b.append(" ").append(o);
	}

	////////////////////////////////////////////////////////////////////////////////////

	public static void main(String[] args) {
		sc = new MyScanner ();
		new B();
		exit();
	}

	static void start() {
		t = millis();
	}

	static PrintWriter pw = new PrintWriter(System.out);

	static long t;

	static long millis() {
		return System.currentTimeMillis();
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

public class ProblemB {

    public static void main(String[] args) throws IOException {
        BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        String[] line = s.readLine().split(" ");
        long n = Long.valueOf(line[0]);
        long y = Long.valueOf(line[1]);
        long x = Long.valueOf(line[2]);
        long c = Long.valueOf(line[3]);

        long min = 0;
        long max = n*2L+20;
        for (int cnt = 0 ; cnt < 300 ; cnt++) {
            long med = (min+max) / 2L;
            long ct = isok(med, n, x, y, c);
            if (ct >= c) {
                max = med;
            } else {
                min = med+1;
            }
        }

        long lst = max;
        for (long d = -2 ; d <= 2 ; d++) {
            if (max+d >= 0 && isok(max+d, n, x, y, c) >= c) {
                lst = Math.min(lst, max+d);
            }
        }

        out.println(lst);
        out.flush();
    }

    private static long isok(long time, long n, long x, long y, long c) {
        long total = time * 2 * (time + 1) + 1;
        long top = y - time;
        if (top <= 0) {
            long dy = Math.abs(top)+1;
            total -= dy*dy;
            long over = dy - x;
            if (over >= 1) {
                total += (1L + over) * over / 2;
            }
            over = dy - ((n + 1) - x);
            if (over >= 1) {
                total += (1L + over) * over / 2;
            }
        }

        long bottom = y + time;
        if (bottom > n) {
            long dy = Math.abs(bottom-n);
            total -= dy*dy;
            long over = dy - x;
            if (over >= 1) {
                total += (1L + over) * over / 2;
            }
            over = dy - ((n + 1) - x);
            if (over >= 1) {
                total += (1L + over) * over / 2;
            }
        }

        long left = x - time;
        if (left <= 0) {
            long dy = Math.abs(left)+1;
            total -= dy*dy;
        }

        long right = x + time;
        if (right > n) {
            long dy = Math.abs(right-n);
            total -= dy*dy;
        }
        return total;
    }

    public static void debug(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Solver {

    StringTokenizer st;
    BufferedReader in;
    PrintWriter out;

    public static void main(String[] args) throws NumberFormatException,
            IOException {
        Solver solver = new Solver();
        solver.open();
        solver.solve();
        solver.close();
    }

    public void open() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }

    public String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            String line = in.readLine();
            if (line == null)
                return null;
            st = new StringTokenizer(line);
        }
        return st.nextToken();
    }

    public int nextInt() throws NumberFormatException, IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws NumberFormatException, IOException {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextToken());
    }

    int n;

    class Otr {
        int x1, y1, x2, y2;
        int dx, dy;

        public Otr(int x, int y, int dx, int dy) {
            super();
            this.x1 = x;
            this.y1 = y;
            this.x2 = x;
            this.y2 = y;
            this.dx = dx;
            this.dy = dy;
        }

        int getAns() {
            if (x1 == x2 && y1 == y2) {
                int nx1 = x1 + dx;
                int ny2 = y2 + dy;

                if ((nx1 <= 0 || nx1 > n) && (ny2 <= 0 || ny2 > n)) {
                    return 0;
                }
            }

            x1 += dx;
            if (x1 <= 0) {
                x1 = 1;
                y1 += dy;
            }
            if (x1 > n) {
                x1 = n;
                y1 += dy;
            }

            y2 += dy;
            if (y2 <= 0) {
                y2 = 1;
                x2 += dx;
            }
            if (y2 > n) {
                y2 = n;
                x2 += dx;
            }

            return Math.abs(x1 - x2) + 1;
        }

        @Override
        public String toString() {
            return "(" + x1 + "," + y1 + ")->(" + x2 + "," + y2 + ")";
        }
    }

    int[] dxs = { -1, -1, 1, 1 };
    int[] dys = { -1, 1, -1, 1 };

    public void solve() throws NumberFormatException, IOException {
        n = nextInt();
        int x = nextInt();
        int y = nextInt();
        long c = nextLong();
        long now = 1;

        Otr[] otr = new Otr[4];
        for (int i = 0; i < 4; i++) {
            otr[i] = new Otr(x, y, dxs[i], dys[i]);
        }

        int result = 0;

        while (now < c) {
            for (int i = 0; i < 4; i++) {
                now += otr[i].getAns();
            }

            for (int i = 0; i < 3; i++) {
                for (int j = i + 1; j < 4; j++) {
                    Otr o1 = otr[i];
                    Otr o2 = otr[j];

                    if (o1.x1!=o1.x2 || o1.y1!=o1.y2){
                        if (o2.x1!=o2.x2 || o2.y1!=o2.y2){
                            if (o1.x1 == o2.x1 && o1.y1 == o2.y1) {
                                now--;
                            }
                            if (o1.x1 == o2.x2 && o1.y1 == o2.y2) {
                                now--;
                            }
                            if (o1.x2 == o2.x1 && o1.y2 == o2.y1) {
                                now--;
                            }
                            if (o1.x2 == o2.x2 && o1.y2 == o2.y2) {
                                now--;
                            }
                        }else{
                            if (o1.x1 == o2.x1 && o1.y1 == o2.y1) {
                                now--;
                            }
                            if (o1.x2 == o2.x1 && o1.y2 == o2.y1) {
                                now--;
                            }
                        }
                    }else{
                        if (o2.x1!=o2.x2 || o2.y1!=o2.y2){
                            if (o1.x2 == o2.x1 && o1.y2 == o2.y1) {
                                now--;
                            }
                            if (o1.x2 == o2.x2 && o1.y2 == o2.y2) {
                                now--;
                            }
                        }else{
                            if (o1.x1 == o2.x1 && o1.y1 == o2.y1) {
                                now--;
                            }
                        }
                    }

                }
            }

            result++;
        }

        out.println(result);
    }

    public void close() {
        out.flush();
        out.close();
    }
}


import java.io.*;
import java.util.*;
import java.math.*;

public class P255D {

  @SuppressWarnings("unchecked")
  public void run() throws Exception {
    long n = nextLong();
    long x = nextLong();
    long y = nextLong();
    long c = nextLong();

    if ((n == 1) || (c == 1)) {
      println(0);
      return;
    }

    x = Math.min(x, n - x + 1);
    y = Math.min(y, n - y + 1);
    long t = 0;
    long s = 1;

    while (s < c) {
      t++;

      s += (t * 4) + ((t >= x + y) ? (t - x - y + 1) : 0)
           - ((t >= x) ? (t - x) * 2 + 1 : 0)
           - ((t >= y) ? (t - y) * 2 + 1 : 0)
           + ((t >= x + n - y + 1) ? (t - x - n + y) : 0)
           + ((t >= n - x + 1 + y) ? (t - n + x - y) : 0)
           - ((t >= n - x + 1) ? (t - n + x - 1) * 2 + 1 : 0)
           - ((t >= n - y + 1) ? (t - n + y - 1) * 2 + 1 : 0);
    }

    println(t);
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P255D().run();
    br.close();
    pw.close();
  }

  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(""); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }
}


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.PrintStream;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Nipuna Samarasekara
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		FastPrinter out = new FastPrinter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    /////////////////////////////////////////////////////////////
 long n,x,y,c;
    public void solve(int testNumber, FastScanner in, FastPrinter out) {
     n=in.nextLong();
 x=in.nextLong();
y=in.nextLong();
c=in.nextLong();
  long td=-1,tup=2*(n-1);
     while(Math.abs(td-tup)>1){
      long mid=(td+tup)/2;
       if(chk(mid))tup=mid;
         else td=mid;
     }
        out.println(tup);

    }

    private boolean chk(long t) {
     long ct=-3;
        long d=x,w=y;
        if(w>d){
            long tt=w;
            w=d;d=tt;
        }

        if(t>=d+w-2) ct+=d*w;
        else if(t<w&&t<d) {
          //  long k=w;
            ct+=(t+1)*(t+2)/2;
        }
        else if(t>=w&&t<d) {
           // long k=w;
            ct+=w*(w+1)/2;
            long k=t-(w-1);
            ct+=k*w;
        }
        else if(t>=w&&t>=d) {
            // long k=w;

            ct+=w*d;
            long k=w-2-(t-d);
            ct-=k*(k+1)/2;
        }
        ////
        w=x;d=n+1-y;
        if(w>d){
            long tt=w;
            w=d;d=tt;
        }

        if(t>=d+w-2) ct+=d*w;
        else if(t<w&&t<d) {
            //  long k=w;
            ct+=(t+1)*(t+2)/2;
        }
        else if(t>=w&&t<d) {
            // long k=w;
            ct+=w*(w+1)/2;
            long k=t-(w-1);
            ct+=k*w;
        }
        else if(t>=w&&t>=d) {
            // long k=w;

            ct+=w*d;
            long k=w-2-(t-d);
            ct-=k*(k+1)/2;
        }

        w=n+1-x;d=y;
        if(w>d){
            long tt=w;
            w=d;d=tt;
        }

        if(t>=d+w-2) ct+=d*w;
        else if(t<w&&t<d) {
            //  long k=w;
            ct+=(t+1)*(t+2)/2;
        }
        else if(t>=w&&t<d) {
            // long k=w;
            ct+=w*(w+1)/2;
            long k=t-(w-1);
            ct+=k*w;
        }
        else if(t>=w&&t>=d) {
            // long k=w;

            ct+=w*d;
            long k=w-2-(t-d);
            ct-=k*(k+1)/2;
        }
        w=n+1-x;d=n+1-y;
        if(w>d){
            long tt=w;
            w=d;d=tt;
        }

        if(t>=d+w-2) ct+=d*w;
        else if(t<w&&t<d) {
            //  long k=w;
            ct+=(t+1)*(t+2)/2;
        }
        else if(t>=w&&t<d) {
            // long k=w;
            ct+=w*(w+1)/2;
            long k=t-(w-1);
            ct+=k*w;
        }
        else if(t>=w&&t>=d) {
            // long k=w;

            ct+=w*d;
            long k=w-2-(t-d);
            ct-=k*(k+1)/2;
        }
        ct-=Math.min(t,x-1);
        ct-=Math.min(t,y-1);
        ct-=Math.min(t,n-x);
        ct-=Math.min(t,n-y);
       // System.out.println(t+" "+ct);
        if(ct>=c)return true;
        else
        return false;
    }

}

class FastScanner extends BufferedReader {

    public FastScanner(InputStream is) {
        super(new InputStreamReader(is));
    }

    public int read() {
        try {
            int ret = super.read();
//            if (isEOF && ret < 0) {
//                throw new InputMismatchException();
//            }
//            isEOF = ret == -1;
            return ret;
        } catch (IOException e) {
            throw new InputMismatchException();
        }
    }

    public String next() {
        StringBuilder sb = new StringBuilder();
        int c = read();
        while (isWhiteSpace(c)) {
            c = read();
        }
        if (c < 0) {
            return null;
        }
        while (c >= 0 && !isWhiteSpace(c)) {
            sb.appendCodePoint(c);
            c = read();
        }
        return sb.toString();
    }

    static boolean isWhiteSpace(int c) {
        return c >= 0 && c <= 32;
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }

    }

class FastPrinter extends PrintWriter {

    public FastPrinter(OutputStream out) {
        super(out);
    }

    public FastPrinter(Writer out) {
        super(out);
    }

}


import java.io.*;
import java.util.*;

public class B {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	long f(int x, int y, int sz) {
		if (x > y) {
			int tmp = x;
			x = y;
			y = tmp;
		}
		if (sz <= x)
			return (long) sz * (sz + 1) / 2;
		if (sz >= x + y - 1)
			return (long) x * y;
		long val = x * (x + 1) / 2;
		if (sz <= y)
			return val + (long) (sz - x) * x;

		long rest = x + y - 1 - sz;
		return (long) x * y - (long) rest * (rest + 1) / 2;
	}

	long count(int x, int y, int n, int time) {
		long DL = f(x + 1, y + 1, time + 1);
		long DR = f(n - x, y + 1, time + 1);
		long UL = f(x + 1, n - y, time + 1);
		long UR = f(n - x, n - y, time + 1);
//		if (time == 1)
//			System.err.println(DL + " " + DR + " " + UL + " " + UR);
		long L = Math.min(x + 1, time + 1);
		long R = Math.min(n - x, time + 1);
		long U = Math.min(n - y, time + 1);
		long D = Math.min(y + 1, time + 1);
//		if (time == 1)
//			System.err.println(L + " " + R + " " + U + " " + D);
		return DL + DR + UL + UR - L - R - U - D + 1;
	}

	void solve() throws IOException {
		int n = nextInt();
		int x = nextInt() - 1;
		int y = nextInt() - 1;
		long need = nextLong();

		if (need == 1) {
			out.println(0);
			return;
		}

		int low = 0;
		int high = Math.max(x, n - 1 - x) + Math.max(y, n - 1 - y);

//		for (int i = 0; i <= 100; i++)
//			System.err.println(count(x, y, n, i));

		while (low < high - 1) {
			int mid = (int) (((long) low + high) / 2);
			if (count(x, y, n, mid) >= need)
				high = mid;
			else
				low = mid;
		}

		out.println(high);

	}

	B() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new B();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}


// practice with rainboy
import java.io.*;
import java.util.*;

public class CF256B extends PrintWriter {
	CF256B() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF256B o = new CF256B(); o.main(); o.flush();
	}

	long count(int n, int x, int y, int r) {
		long a = 2L * r * r + 2 * r + 1;
		int w;
		if ((w = 1 - (x - r)) > 0)
			a -= (long) w * w;
		if ((w = 1 - (y - r)) > 0)
			a -= (long) w * w;
		if ((w = (x + r) - n) > 0)
			a -= (long) w * w;
		if ((w = (y + r) - n) > 0)
			a -= (long) w * w;
		if ((w = r - 1 - (x - 1) - (y - 1)) > 0)
			a += (long) w * (w + 1) / 2;
		if ((w = r - 1 - (x - 1) - (n - y)) > 0)
			a += (long) w * (w + 1) / 2;
		if ((w = r - 1 - (n - x) - (y - 1)) > 0)
			a += (long) w * (w + 1) / 2;
		if ((w = r - 1 - (n - x) - (n - y)) > 0)
			a += (long) w * (w + 1) / 2;
		return a;
	}
	void main() {
		int n = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int c = sc.nextInt();
		int lower = -1, upper = c;
		while (upper - lower > 1) {
			int r = (lower + upper) / 2;
			if (count(n, x, y, r) >= c)
				upper = r;
			else
				lower = r;
		}
		println(upper);
	}
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Proj implements Runnable {

	BufferedReader in;
	PrintWriter out;
	StringTokenizer str;

	public void solve() throws IOException {
		long l = nextLong();
		long r = nextLong();
                int g = 0;
		long x = l ^ r;
		long i = 1;
		while (x >= i) {
			i = i * 2;
		}
		if (x >= i) {
			out.println(x);
		} else
			out.println(i - 1);
	}

	public String nextToken() throws IOException {
		while (str == null || !str.hasMoreTokens()) {
			str = new StringTokenizer(in.readLine());
		}
		return str.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (IOException e) {
		}
	}

	public static void main(String[] args) {
		new Thread(new Proj()).start();
	}
}


/**
 * Created with IntelliJ IDEA.
 * User: brzezinsky
 * Date: 12/16/12
 * Time: 7:44 PM
 * To change this template use File | Settings | File Templates.
 */

import java.io.*;
import java.util.*;
import java.util.StringTokenizer;

public class E extends Thread {
    public E(String inputFileName, String outputFileName) {
        try {
            if (inputFileName != null) {
                this.input = new BufferedReader(new FileReader(inputFileName));
            } else {
                this.input = new BufferedReader(new InputStreamReader(System.in));
            }
            if (outputFileName != null) {
                this.output = new PrintWriter(outputFileName);
            } else {
                this.output = new PrintWriter(System.out);
            }
            this.setPriority(Thread.MAX_PRIORITY);
        } catch (Throwable e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
            System.exit(666);
        }
    }

    private void solve() throws Throwable {
        long l = nextLong(), r = nextLong();
        output.println(Math.max(Long.highestOneBit(l ^ r) * 2 - 1, 0L));
    }

    public void run() {
        try {
            solve();
        } catch (Throwable e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
            System.exit(666);
        } finally {
            output.close();
        }
    }

    public static void main(String... args) {
        new E(null, null).start();
    }

    private int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    private double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    private long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    private String next() throws IOException {
        while (tokens == null || !tokens.hasMoreTokens()) {
            tokens = new StringTokenizer(input.readLine());
        }
        return tokens.nextToken();
    }

    private StringTokenizer tokens;
    private BufferedReader input;
    private PrintWriter output;
}


import java.awt.Point;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;
import static java.lang.Math.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Character.*;
import static java.lang.String.*;
@SuppressWarnings("unused")

public class round169D {
    static PrintWriter out = new PrintWriter(System.out);
    static BufferedReader br = new BufferedReader(new InputStreamReader(
            System.in));
    static StringTokenizer st = new StringTokenizer("");
    static int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    static String next() throws Exception {
        while (true) {
            if (st.hasMoreTokens()) {
                return st.nextToken();
            }
            String s = br.readLine();
            if (s == null) {
                return null;
            }
            st = new StringTokenizer(s);
        }
    }
    public static void main(String[] args)throws Exception {
        long l = parseLong(next());
        long r = parseLong(next());
        long [] min = new long [61];
        for(int i = 1 ; i <= 60 ; ++i){//(2^i)-1 is obtained by min[i]^min[i]+1
            min[i] = (long) pow(2, i - 1) - 1;
        }
        for(int i = 60 ; i >= 0 ; --i){//try to get 2^i-1 as answer.
            if(min[i] >= r)
                continue;
            if(min[i] >= l && min[i] + 1 <= r){
                out.println((1L << i) - 1);
                out.flush();
                return;
            }
            if(min[i] < l){
                long one_jump = (long) pow(2, i);
                long  jumps = (long) ceil((l - min[i]) / (one_jump * 1.0));
                long cur = min[i] + (jumps * one_jump);
                if(cur >= l && cur + 1 <= r){
                    out.println((1L << i) - 1);
                    out.flush();
                    return;
                }
            }
        }
        out.println(0);
        out.flush();
    }
}


import java.util.Scanner;

public class D {
    static long max;

    public static long[] getOneRange(long min, long max,int bit) {
        long st=(min&(((1l<<63)-1)&~((1l<<(bit+1))-1)))|(1l<<bit);
        long end=st|((1l<<(bit+1))-1);
        long interSt=Math.max(st,min);
        long interEnd=Math.min(end, max);
        if(interSt>interEnd) return null;
        return new long[]{interSt,interEnd};
    }

    public static long[] getZeroRange(long min, long max,int bit) {
        long st=min&(((1l<<63)-1)&~((1l<<(bit+1))-1));
        long end=st|((1l<<bit)-1);
        long interSt=Math.max(st,min);
        long interEnd=Math.min(end, max);
        if(interSt>interEnd) return null;
        return new long[]{interSt,interEnd};
    }

    public static void solve(int bitPosition, long min1, long max1, long min2,
            long max2, long curNum) {
        if (bitPosition == -1) {
            max = Math.max(max, curNum);
            return;
        }
        long[] firZeroRange = getZeroRange(min1, max1,bitPosition);
        long[] secZeroRange = getZeroRange(min2, max2,bitPosition);
        long[] firOneRange = getOneRange(min1, max1,bitPosition);
        long[] secOneRange = getOneRange(min2, max2,bitPosition);
        if ((firOneRange != null && secZeroRange != null)
                || (firZeroRange != null && secOneRange != null)) {
            long newNum = curNum | (1l << bitPosition);
            if (firOneRange != null && secZeroRange != null&&
                    (firOneRange[1]-firOneRange[0]+1)==1l<<bitPosition&&
                    (secZeroRange[1]-secZeroRange[0]+1)==1l<<bitPosition) {
                solve(bitPosition - 1, firOneRange[0], firOneRange[1],
                        secZeroRange[0], secZeroRange[1], newNum);
                return;
            }
            if (firZeroRange != null && secOneRange != null&&
                    (firZeroRange[1]-firZeroRange[0]+1)==1l<<bitPosition&&
                    (secOneRange[1]-secOneRange[0]+1)==1l<<bitPosition) {
                solve(bitPosition - 1, firZeroRange[0], firZeroRange[1],
                        secOneRange[0], secOneRange[1], newNum);
                return;
            }
            if (firOneRange != null && secZeroRange != null) {
                solve(bitPosition - 1, firOneRange[0], firOneRange[1],
                        secZeroRange[0], secZeroRange[1], newNum);
            }
            if (firZeroRange != null && secOneRange != null) {
                solve(bitPosition - 1, firZeroRange[0], firZeroRange[1],
                        secOneRange[0], secOneRange[1], newNum);
            }
        } else {
            solve(bitPosition - 1, min1, max1, min2, max2, curNum);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long l = sc.nextLong();
        long r = sc.nextLong();
        max = 0;
        solve(62, l, r, l, r, 0);
        System.out.println(max);
    }
}


import java.util.*;
import java.io.*;
public class a {
public static void main(String[] args) throws IOException
{

    //Scanner input = new Scanner(new File("input.txt"));
    //PrintWriter out = new PrintWriter(new File("output.txt"));
    PrintWriter out = new PrintWriter(System.out);
    input.init(System.in);
    long a = input.nextLong(), b = input.nextLong();
    if(a==b)
    {
        out.println(0);
        out.close();
        return;
    }
    long res = 0;
    for(int i = 0; i<63; i++)
    {
        if(a%(1l<<i) >= b%(1l<<i))
            res += (1l<<i);
        else if(b/((1l<<i)) > a/((1l<<i)))
            res += (1l<<i);
    }
    out.println(res);
    out.close();
}
public static long gcd(long a, long b)
{
if(b == 0) return a;
return gcd(b, a%b);
}
public static class input {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
}
static class IT
{
    int[] left,right, val, a, b;
    IT(int n)
    {
        left = new int[3*n];
        right = new int[3*n];
        val = new int[3*n];
        a = new int[3*n];
        b = new int[3*n];
        init(0,0, n);
    }
    int init(int at, int l, int r)
    {
        a[at] = l;
        b[at] = r;
        if(l==r)
            left[at] = right [at] = -1;
        else
        {
            int mid = (l+r)/2;
            left[at] = init(2*at+1,l,mid);
            right[at] = init(2*at+2,mid+1,r);
        }
        return at++;
    }
    //return the sum over [x,y]
    int get(int x, int y)
    {
        return go(x,y, 0);
    }
    int go(int x,int y, int at)
    {
        if(at==-1) return 0;
        if(x <= a[at] && y>= b[at]) return val[at];
        if(y<a[at] || x>b[at]) return 0;
        return go(x, y, left[at]) + go(x, y, right[at]);
    }
    //add v to elements x through y
    void add(int x, int y, int v)
    {
        go3(x, y, v, 0);
    }
    void go3(int x, int y, int v, int at)
    {
        if(at==-1) return;
        if(y < a[at] || x > b[at]) return;
        val[at] += (Math.min(b[at], y) - Math.max(a[at], x) + 1)*v;
        go3(x, y, v, left[at]);
        go3(x, y, v, right[at]);
    }
}
}


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Zakhar Voit
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        out.println(solve(in.nextLong(), in.nextLong()));
        /*for (long l = 1; l < 500; l++) {
            for (long r = l; r < 500; r++) {
                if (badSolve(l, r) != solve(l, r)) {
                    out.println(l + " " + r);
                    return;
                }
            }
        }
        out.println("OK");*/
    }

    long solve(long l, long r) {
        if (l == r)
            return 0;
        long ans = l ^ (l + 1);

        for (int i = 0; i < 62; i++) {
            l |= (1l << i);
            if (l + 1 <= r)
                ans = (1l << (i + 2l)) - 1;
        }

        return ans;
    }
}

class Scanner {
    BufferedReader in;
    StringTokenizer tok;

    public Scanner(InputStream in) {
        this.in = new BufferedReader(new InputStreamReader(in));
        tok = new StringTokenizer("");
    }

    public String nextToken() {
        if (!tok.hasMoreTokens()) {
            try {
                String newLine = in.readLine();
                if (newLine == null)
                    throw new InputMismatchException();
                tok = new StringTokenizer(newLine);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            return nextToken();
        }

        return tok.nextToken();
    }

    public long nextLong() {
        return Long.parseLong(nextToken());
    }

    }


import java.io.*;
import java.util.*;

public class D {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	String toStr(long a) {
		String s = Long.toBinaryString(a);
		while (s.length() < 64)
			s = "0" + s;
		return s;
	}

	void solve() throws IOException {
		long a = nextLong();
		long b = nextLong();

		String sa = toStr(a);
		String sb = toStr(b);

		int i = 0;
		while (i < 64 && sa.charAt(i) == sb.charAt(i))
			i++;

		int left = 64 - i;
		out.println((1L << left) - 1);
	}

	D() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new D();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}


import java.util.Scanner;

public class D {
	public static void main(String [] args){
		Scanner in = new Scanner(System.in);
		long a = in.nextLong();
		long b = in.nextLong();
		String sa = Long.toBinaryString(a);
		String sb = Long.toBinaryString(b);
		long ans = 0;
		if(sb.length()-sa.length()>0){
			for(int i = 0 ; i < sb.length() ; i++){
				ans += 1l<<i;
			}
			System.out.println(ans);
		}
		else{
			int num = -1 ;
			for(int i = 62 ; i >= 0 ; i--){
				if((b & 1l << i) != 0 && ((~a) & (1l << i)) != 0){
					num = i;
					break;
				}
			}
			ans = 0;
			if(num!=-1) for(int i = 0 ; i <= num ; i ++){
				ans += 1l<<i;
			}
			System.out.println(ans);
	}
	}

}


import java.util.Scanner;

public class Main3 {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        long l = s.nextLong();
        long r = s.nextLong();

        String a = Long.toBinaryString(l);
        String b = Long.toBinaryString(r);
        while(a.length() < b.length()) a = "0" + a;
        while(b.length() < a.length()) b = "0" + b;

        String ans = "";

        int ix = -1;
        for (int i = 0; i < a.length(); i++) {

            if(a.charAt(i) != b.charAt(i)){
                break;
            }
            ans += a.charAt(i);
            ix++;
        }
//      System.out.println(a);
//      System.out.println(b);
        for (int i = ix + 1; i < a.length(); i++) {
            int c1 = a.charAt(i) - '0';
            int c2 = b.charAt(i) - '0';
            if(c1 == 0 && c2 == 0) ans += "1";
            else if(c1 == 1 && c2 == 1) ans += "0";
            else ans += (char)(c1 + '0');
        }
        long a1 = Long.parseLong(ans, 2);
        long a2 = Long.parseLong(b,2);
//      System.out.println(ans);
//      System.out.println(b);
//      System.out.println();
        long xor = a1 ^ a2;
        System.out.println(xor);
    }

}


import java.util.Scanner;

public class d_169 {
public static void main(String[] args) {
	Scanner  sc = new Scanner(System.in);
	long x=sc.nextLong();
	long y=sc.nextLong();
	String s=Long.toBinaryString(x);
	String p=Long.toBinaryString(y);
	int id=p.length()-s.length();
	for (int i =1; i <=id; i++) {
		s="0"+s;
	}
	if(x==y){
		System.out.println(0);
		return;
	}
	for (int i = 0; i <p.length(); i++) {
		if(s.charAt(i)!=p.charAt(i)){
			System.out.println((long)Math.pow(2, s.length()-i)-1);
			return;
	}
}
}
}


import java.io.*;
import java.lang.reflect.*;

public class D {

	final int MOD = (int)1e9 + 7;
	final double eps = 1e-12;
	final int INF = (int)1e9;

	public D () {
		long L = sc.nextLong();
		long R = sc.nextLong();

		for (int i = 60; i >= 0; --i) {
			long b = (1L << i);
			long A = (L & b), B = (R & b);
			if (A != B)
				exit(2*b-1);
		}
		exit(0);
	}

	////////////////////////////////////////////////////////////////////////////////////

	/* Dear hacker, don't bother reading below this line, unless you want to help me debug my I/O routines :-) */

	static MyScanner sc = new MyScanner();

	static class MyScanner {
		public String next() {
			newLine();
			return line[index++];
		}

		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			line = null;
			return readLine();
		}

		public String [] nextStrings() {
			line = null;
			return readLine().split(" ");
		}

		public char [] nextChars() {
			return next().toCharArray();
		}

		public Integer [] nextInts() {
			String [] L = nextStrings();
			Integer [] res = new Integer [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Integer.parseInt(L[i]);
			return res;
		}

		public Long [] nextLongs() {
			String [] L = nextStrings();
			Long [] res = new Long [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Long.parseLong(L[i]);
			return res;
		}

		public Double [] nextDoubles() {
			String [] L = nextStrings();
			Double [] res = new Double [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Double.parseDouble(L[i]);
			return res;
		}

		public String [] next (int N) {
			String [] res = new String [N];
			for (int i = 0; i < N; ++i)
				res[i] = sc.next();
			return res;
		}

		public Integer [] nextInt (int N) {
			Integer [] res = new Integer [N];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextInt();
			return res;
		}

		public Long [] nextLong (int N) {
			Long [] res = new Long [N];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextLong();
			return res;
		}

		public Double [] nextDouble (int N) {
			Double [] res = new Double [N];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextDouble();
			return res;
		}

		public String [][] nextStrings (int N) {
			String [][] res = new String [N][];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextStrings();
			return res;
		}

		public Integer [][] nextInts (int N) {
			Integer [][] res = new Integer [N][];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextInts();
			return res;
		}

		public Long [][] nextLongs (int N) {
			Long [][] res = new Long [N][];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextLongs();
			return res;
		}

		public Double [][] nextDoubles (int N) {
			Double [][] res = new Double [N][];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextDoubles();
			return res;
		}

		//////////////////////////////////////////////

		private boolean eol() {
			return index == line.length;
		}

		private String readLine() {
			try {
				return r.readLine();
			} catch (Exception e) {
				throw new Error(e);
			}
		}
		private final BufferedReader r;

		MyScanner () {
			this(new BufferedReader(new InputStreamReader(System.in)));
		}

		MyScanner(BufferedReader r) {
			try {
				this.r = r;
				while (!r.ready())
					Thread.sleep(1);
				start();
			} catch (Exception e) {
				throw new Error(e);
			}
		}

		private String [] line;
		private int index;

		private void newLine() {
			if (line == null || eol()) {
				line = readLine().split(" ");
				index = 0;
			}
		}
	}

	static void print(Object o, Object... a) {
		printDelim(" ", o, a);
	}

	static void cprint(Object o, Object... a) {
		printDelim("", o, a);
	}

	static void printDelim (String delim, Object o, Object... a) {
		pw.println(build(delim, o, a));
	}

	static void exit (Object o, Object... a) {
		print(o, a);
		exit();
	}

	static void exit () {
		pw.close();
		System.out.flush();
		System.err.println("------------------");
		System.err.println("Time: " + ((millis() - t) / 1000.0));
		System.exit(0);
	}

	void NO() {
		throw new Error("NO!");
	}

	////////////////////////////////////////////////////////////////////////////////////

	static String build(String delim, Object o, Object... a) {
		StringBuilder b = new StringBuilder();
		append(b, o, delim);
		for (Object p : a)
			append(b, p, delim);
		return b.toString().trim();
	}

	static void append(StringBuilder b, Object o, String delim) {
		if (o.getClass().isArray()) {
			int L = Array.getLength(o);
			for (int i = 0; i < L; ++i)
				append(b, Array.get(o, i), delim);
		} else if (o instanceof Iterable<?>) {
			for (Object p : (Iterable<?>)o)
				append(b, p, delim);
		} else
			b.append(delim).append(o);
	}

	////////////////////////////////////////////////////////////////////////////////////

	public static void main(String[] args) {
		new D();
		exit();
	}

	static void start() {
		t = millis();
	}

	static PrintWriter pw = new PrintWriter(System.out);

	static long t;

	static long millis() {
		return System.currentTimeMillis();
	}
}


import java.io.*;
import java.util.*;

public class D {
    public static void main(String[] args) throws IOException {
        new D().solve();
    }

    void solve() throws IOException {
        Scanner sc = new Scanner(System.in);
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] sp;

        long L = sc.nextLong();
        long R = sc.nextLong();
        if (L == R) {
            System.out.println(0);
        } else {
            System.out.println(Long.highestOneBit(R ^ L) * 2 - 1);
        }
    }
}

//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//


// @author Sanzhar
import java.io.*;
import java.util.*;
import java.awt.Point;

public class Template {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st;

    String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(in.readLine());
            } catch (Exception e) {
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    public void run() throws Exception {
        //in = new BufferedReader(new FileReader("input.txt"));
        //out = new PrintWriter(new FileWriter("output.txt"));
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.flush();
        out.close();
        in.close();
    }

    public void solve() throws Exception {
        long l = nextLong();
        long r = nextLong();
        long[] x = new long[100];
        int kx = 0;
        while (r > 0) {
            x[kx++] = r % 2;
            r /= 2;
        }
        long[] y = new long[100];
        int ky = 0;
        while (l > 0) {
            y[ky++] = l % 2;
            l /= 2;
        }
        long[] ans = new long[100];
        boolean ok = false;
        for (int k = kx - 1; k >= 0; k--) {
            if (ok) {
                ans[k] = 1;
                continue;
            }
            if (x[k] > y[k]) {
                ans[k] = 1;
                ok = true;
            }
        }
        long a = 0;
        long p2 = 1;
        for (int i = 0; i < kx; i++) {
            a += p2 * ans[i];
            p2 *= 2;
        }
        out.println(a);
    }

    public static void main(String[] args) throws Exception {
        new Template().run();
    }
}


import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {

  public void solve(int testNumber, InputReader in, PrintWriter out) {
    long l = in.readLong(), r = in.readLong();
    int pow = 62;
    long mask = 1L << pow;
    while (((r | l) & mask) == 0){
      pow--;
      mask = 1L << pow;
    }
    while (true) {
      if (((r ^ l) & mask) == mask || pow < 0) {
        break;
      }
      mask >>= 1;
      l = l & ~(1L << pow);
      r = r & ~(1L << pow);
      pow--;
    }
    pow++;
    out.print((1L << pow) - 1);
  }
}

class InputReader {

  private InputStream stream;
  private byte[] buf = new byte[1024];
  private int curChar;
  private int numChars;

  public InputReader(InputStream stream) {
    this.stream = stream;
  }

  public int read() {
    if (numChars == -1)
      throw new InputMismatchException();
    if (curChar >= numChars) {
      curChar = 0;
      try {
        numChars = stream.read(buf);
      } catch (IOException e) {
        throw new InputMismatchException();
      }
      if (numChars <= 0)
        return -1;
    }
    return buf[curChar++];
  }

  public long readLong() {
    int c = read();
    while (isSpaceChar(c))
      c = read();
    int sgn = 1;
    if (c == '-') {
      sgn = -1;
      c = read();
    }
    long res = 0;
    do {
      if (c < '0' || c > '9')
        throw new InputMismatchException();
      res *= 10;
      res += c - '0';
      c = read();
    } while (!isSpaceChar(c));
    return res * sgn;
  }

  public static boolean isSpaceChar(int c) {
    return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
  }

  }


import java.util.Scanner;

public class D {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        long l = s.nextLong();
        long r = s.nextLong();
        long a = l ^ r;
        long b = a;
        while (b != 0) {
            a = b;
            b = (b-1) & b;
        }
        if (a != 0) {
            a = (a << 1) - 1;
        }
        System.out.println(a);
    }

}


import java.util.*;

public class Dj {

	public static long run(long l, long r) {
		if(l == r) {
			return 0;
		}

		long[] sq2 = new long[62];
		sq2[0] = 1;
		for(int i = 1; i < 62; i++) sq2[i] = sq2[i-1]*2;

		//System.out.println(sq2[61]);

		for(int i = sq2.length - 1; i >= 0; i--) {
			//log("L = " + l + " R = " + r + " 2^" + i + "=" + sq2[i]);
			if(l >= sq2[i] && r >= sq2[i]) {
				l -= sq2[i];
				r -= sq2[i];
			} else if(l < sq2[i] && sq2[i] <= r) {
				break;
			}
		}
		for(int i = sq2.length - 1; i >= 0; i--) {
			//log("L = " + l + " R = " + r + " 2^" + i + "=" + sq2[i]);
			if(l < sq2[i] && sq2[i] <= r) {
				return sq2[i+1]-1;
			}
		}
		return -1;
	}

	public static void log(String str) {
		System.out.println(str);
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long l = sc.nextLong();
		long r = sc.nextLong();

		System.out.println(run(l, r));
		//System.out.println(run(9999999999998l, 9999999999999l));

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class LittleGirlAndXor {
    static long L, R;
    static Long[][][][][] dp = new Long[64][2][2][2][2];
    public static long go(int index, int low1, int high1, int low2, int high2) {
        if (index == -1) {
            return 0;
        }
        if (dp[index][low1][high1][low2][high2] != null)
            return dp[index][low1][high1][low2][high2];
        int bit1 = (L & (1L << index)) == 0 ? 0 : 1;
        int bit2 = (R & (1L << index)) == 0 ? 0 : 1;
        long res = 0;
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 2; j++) {
                int nl1 = low1, nh1 = high1, nl2 = low2, nh2 = high2;
                boolean can = true;
                if (low1 == 0) {
                    if (i == bit1) {
                        nl1 = 0;
                    } else if (i < bit1) {
                        can = false;
                    } else if (i > bit1) {
                        nl1 = 1;
                    }
                }
                if (high1 == 0) {
                    if (i == bit2) {
                        nh1 = 0;
                    } else if (i < bit2) {
                        nh1 = 1;
                    } else if (i > bit2) {
                        can = false;
                    }
                }
                if (low2 == 0) {
                    if (j == bit1) {
                        nl2 = 0;
                    } else if (j < bit1) {
                        can = false;
                    } else if (j > bit1) {
                        nl2 = 1;
                    }
                }
                if (high2 == 0) {
                    if (j == bit2) {
                        nh2 = 0;
                    } else if (j < bit2) {
                        nh2 = 1;
                    } else if (j > bit2) {
                        can = false;
                    }
                }
                if (can){
                    long xor = i^j;
                    res = Math.max(res, (xor<<index)+go(index - 1, nl1, nh1, nl2, nh2));
                }
            }
        }
        return dp[index][low1][high1][low2][high2] = res;
    }
    public static void main(String[] args) {
        InputReader r = new InputReader(System.in);
        L = r.nextLong();
        R = r.nextLong();
        System.out.println(go(63,0,0,0,0));
    }
    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                return null;
            }
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.text.*;

public class cf276d {

    static BufferedReader br;
    static Scanner sc;
    static PrintWriter out;

    public static void initA() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            //br = new BufferedReader(new FileReader("input.txt"));
            sc = new Scanner(System.in);
            //out = new PrintWriter("output.txt");
            out = new PrintWriter(System.out);
        } catch (Exception e) {
        }
    }

    public static void initB() {
        try {

            br = new BufferedReader(new FileReader("input.txt"));
            sc = new Scanner(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");

        } catch (Exception e) {
        }
    }

    public static String getString() {
        try {
            return br.readLine();
        } catch (Exception e) {
        }
        return "";
    }

    public static Integer getInt() {
        try {
            return Integer.parseInt(br.readLine());
        } catch (Exception e) {
        }
        return 0;
    }

    public static Integer[] getIntArr() {
        try {
            StringTokenizer temp = new StringTokenizer(br.readLine());
            int n = temp.countTokens();
            Integer temp2[] = new Integer[n];
            for (int i = 0; i < n; i++) {
                temp2[i] = Integer.parseInt(temp.nextToken());
            }
            return temp2;
        } catch (Exception e) {
        }
        return null;
    }

    public static Long[] getLongArr() {
        try {
            StringTokenizer temp = new StringTokenizer(br.readLine());
            int n = temp.countTokens();
            Long temp2[] = new Long[n];
            for (int i = 0; i < n; i++) {
                temp2[i] = Long.parseLong(temp.nextToken());
            }
            return temp2;
        } catch (Exception e) {
        }
        return null;
    }

    public static String[] getStringArr() {
        try {
            StringTokenizer temp = new StringTokenizer(br.readLine());
            int n = temp.countTokens();
            String temp2[] = new String[n];
            for (int i = 0; i < n; i++) {
                temp2[i] = (temp.nextToken());
            }
            return temp2;
        } catch (Exception e) {
        }
        return null;
    }

    public static int getMax(Integer[] ar) {
        int t = ar[0];
        for (int i = 0; i < ar.length; i++) {
            if (ar[i] > t) {
                t = ar[i];
            }
        }
        return t;
    }

    public static void print(Object a) {
        out.println(a);
    }

    public static int nextInt() {
        return sc.nextInt();
    }

    public static double nextDouble() {
        return sc.nextDouble();
    }

    public static void main(String[] ar) {
        initA();
        solve();
        out.flush();
    }
    public static void print2(Object o){System.out.println(o);}

    public static void solve() {
        Long xx[] = getLongArr();
        long l = xx[0];
        long r = xx[1];
        BigInteger a = BigInteger.valueOf(l);
        BigInteger b = BigInteger.valueOf(r);

        if(l==r){
            print(0);return;
        }

        String a2 = a.toString(2);
        String b2 = b.toString(2);

        int selisihpjg = Math.abs(a2.length() - b2.length());

        while (selisihpjg-- > 0) {
            a2 = "0" + a2;
            //print2("wewe");
        }

        //print2(a2);
        //print2(b2);
        String out = "";

        for (int i = 0; i < b2.length(); i++) {
            //print2("i="+i);
            if (a2.charAt(i) != b2.charAt(i)) {

                for (int ii = i; ii < b2.length(); ii++) {
                    out += "1";
                }
                //print2(out);
                print2(new BigInteger(out, 2));
                return;
            }
        }

    }
}


import java.util.*;
import java.io.*;
import java.math.*;
import java.awt.geom.*;

import static java.lang.Math.*;

public class Solution implements Runnable {

    boolean hasBit(long n, int pos) {
        return (n & (1L << pos)) != 0;
    }

    public void solve() throws Exception {
        long l = sc.nextLong(), r = sc.nextLong();
        int bit = 62;
        while (bit >= 0 && (hasBit(l, bit) == hasBit(r, bit))) {
            bit--;
        }
        out.println((1L << (bit + 1)) - 1);
    }

    static Throwable uncaught;

    BufferedReader in;
    FastScanner sc;
    PrintWriter out;

    @Override
    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            sc = new FastScanner(in);
            solve();
        } catch (Throwable uncaught) {
            Solution.uncaught = uncaught;
        } finally {
            out.close();
        }
    }

    public static void main(String[] args) throws Throwable {
        Thread thread = new Thread (null, new Solution(), "", (1 << 26));
        thread.start();
        thread.join();
        if (Solution.uncaught != null) {
            throw Solution.uncaught;
        }
    }

}

class FastScanner {

    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }

}


import java.util.*;
import static java.lang.System.*;

public class D276 {
    Scanner sc = new Scanner(in);

    public void run() {
        long l=sc.nextLong(),r=sc.nextLong();

        long tes=l^r;

        int d=0;
        while(tes!=0){
            tes/=2;
            d++;
        }
        ln((1L<<d)-1);
    }

    public static void main(String[] _) {
        new D276().run();
    }

    public static void pr(Object o) {
        out.print(o);
    }
    public static void ln(Object o) {
        out.println(o);
    }
    public static void ln() {
        out.println();
    }
}


//package codeforces;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Scanner;

public class CodeForces {

    //private static MyScanner sc;
    private static MyPrinter out;

    public static void solve() throws IOException {
        Scanner sc = new Scanner(System.in);
        long l = sc.nextLong();
        long r = sc.nextLong();
        String ls = Long.toBinaryString(l);
        String rs = Long.toBinaryString(r);
        while (ls.length() < rs.length()) {
            ls = "0" + ls;
        }
        String res = "";
        boolean ok = false;
        for (int i = 0; i < ls.length(); i++) {
            if (ok) {
                res += "1";
            } else {
                if (ls.charAt(i) != rs.charAt(i)) {
                    res += "1";
                    ok = true;
                }
            }
        }
        long all = 0;
        for (int i = 0; i < res.length(); i++) {
            all += (long) Math.pow((long) 2, (long) res.length() - 1 - i);
        }
        System.out.println(all);
    }

    public static void main(String[] args) throws IOException {
        //sc = new MyScanner(System.in);
        out = new MyPrinter(System.out);
        solve();
        out.close();
    }
}

class MyScanner {

    private StreamTokenizer st;

    public MyScanner(InputStream is) {
        st = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));
    }

    public MyScanner(File f) throws FileNotFoundException {
        st = new StreamTokenizer(new BufferedReader(new FileReader(f)));
    }

    public int nextInt() throws IOException {
        st.nextToken();
        return ((int) st.nval);
    }

    public double nextDouble() throws IOException {
        st.nextToken();
        return (st.nval);
    }

    public String nextString() throws IOException {
        st.nextToken();
        if (st.ttype == StreamTokenizer.TT_WORD) {
            return (st.sval);
        } else {
            return ("not found");
        }
    }
}

class MyPrinter {

    private BufferedWriter out;

    public MyPrinter(OutputStream os) {
        out = new BufferedWriter(new PrintWriter(os));
    }

    public MyPrinter(File f) throws IOException {
        out = new BufferedWriter(new FileWriter(f));
    }

    public void println(int i) throws IOException {
        out.write(Integer.toString(i));
        out.newLine();
    }

    public void println(double d) throws IOException {
        out.write(Double.toString(d));
        out.newLine();
    }

    public void println(long l) throws IOException {
        out.write(Long.toString(l));
        out.newLine();
    }

    public void println(String s) throws IOException {
        out.write(s);
        out.newLine();
    }

    public void println(char c) throws IOException {
        out.write(Character.toString(c));
        out.newLine();
    }

    public void print(int i) throws IOException {
        out.write(Integer.toString(i));
    }

    public void print(double d) throws IOException {
        out.write(Double.toString(d));
    }

    public void print(long l) throws IOException {
        out.write(Long.toString(l));
    }

    public void print(String s) throws IOException {
        out.write(s);
    }

    public void print(char c) throws IOException {
        out.write(Character.toString(c));
    }

    public void close() throws IOException {
        out.flush();
        out.close();
    }
}


import java.util.*;
import java.io.*;

public class Main {

	BufferedReader in;
	StringTokenizer str = null;

	private String next() throws Exception{
		if (str == null || !str.hasMoreElements())
			str = new StringTokenizer(in.readLine());
		return str.nextToken();
	}

	private int nextInt() throws Exception{
		return Integer.parseInt(next());
	}

	private long nextLong() throws Exception{
		return Long.parseLong(next());
	}

	private double nextDouble() throws Exception{
		return Double.parseDouble(next());
	}

	public void run() throws Exception{
		in =  new BufferedReader(new InputStreamReader(System.in));
		long l = nextLong();
		long r = nextLong();

		int bit = 63;
		while(bit >= 0 && (hasBit(l, bit) == hasBit(r, bit))) {
			bit--;
		}
		System.out.println((1L<<bit+1)-1);
	}

	private boolean hasBit(long x, int i){
		return (x & (1L<<i)) > 0;
	}

	public static void main(String[] args) throws Exception{
		new Main().run();
	}
}


/* Codeforces Template */

import java.io.*;
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {

	static long initTime;
	static final Random rnd = new Random(7777L);
	static boolean writeLog = false;

	public static void main(String[] args) throws IOException {
		initTime = System.currentTimeMillis();
		try {
			writeLog = "true".equals(System.getProperty("LOCAL_RUN_7777"));
		} catch (SecurityException e) {}
		new Thread(null, new Runnable() {
			public void run() {
				try {
					try {
						if (new File("input.txt").exists())
							System.setIn(new FileInputStream("input.txt"));
					} catch (SecurityException e) {}
					long prevTime = System.currentTimeMillis();
					new Main().run();
					log("Total time: " + (System.currentTimeMillis() - prevTime) + " ms");
					log("Memory status: " + memoryStatus());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1L << 24).start();
	}

	void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
		in.close();
	}

	/***************************************************************
	 * Solution
	 **************************************************************/

	void solve() throws IOException  {

		long leftBorder = nextLong();
		long rightBorder = nextLong();

		long[][][][][] dp = new long [64][2][2][2][2];
		for (long[][][][] a : dp) for (long[][][] b : a) for (long[][] c : b) for (long[] d : c) fill(d, -1L);

		dp[63][0][0][0][0] = 0L;

		for (int lastBit = 63; lastBit > 0; lastBit--) {

			int curBit = lastBit - 1;

			int leftBit = (int) ((leftBorder >> curBit) & 1L);
			int rightBit = (int) ((rightBorder >> curBit) & 1L);

			for (int agl = 0; agl < 2; agl++) {

				for (int alr = 0; alr < 2; alr++) {

					for (int bgl = 0; bgl < 2; bgl++) {

						for (int blr = 0; blr < 2; blr++) {

							long prvXor = dp[lastBit][agl][alr][bgl][blr];
							if (prvXor < 0L) continue;

							for (int ab = 0; ab < 2; ab++) {

								int nagl = left(agl, leftBit, ab);
								int nalr = right(alr, rightBit, ab);
								if (nagl < 0 || nalr < 0) continue;

								for (int bb = 0; bb < 2; bb++) {

									int nbgl = left(bgl, leftBit, bb);
									int nblr = right(blr, rightBit, bb);
									if (nbgl < 0 || nblr < 0) continue;

									long setBit = ab ^ bb;
									dp[curBit][nagl][nalr][nbgl][nblr] = max(dp[curBit][nagl][nalr][nbgl][nblr], prvXor | (setBit << curBit));

								}

							}

						}

					}

				}

			}

		}

		long answer = -1L;

		for (int agl = 0; agl < 2; agl++) {

			for (int alr = 0; alr < 2; alr++) {

				for (int bgl = 0; bgl < 2; bgl++) {

					for (int blr = 0; blr < 2; blr++) {

						answer = max(answer, dp[0][agl][alr][bgl][blr]);

					}
				}
			}
		}

//		System.err.println(Long.toBinaryString(leftBorder));
//		System.err.println(Long.toBinaryString(rightBorder));
//		System.err.println(Long.toBinaryString(answer));

		out.println(answer);
	}

	int left(int gl, int leftBit, int b) {

		if (gl == 0) {

			if (b < leftBit) return -1;
			if (b == leftBit) return 0;
			if (b > leftBit) return 1;

		}

		return 1;
	}

	int right(int lr, int rightBit, int b) {

		if (lr == 0) {
			if (b < rightBit) return 1;
			if (b == rightBit) return 0;
			if (b > rightBit) return -1;
		}

		return 1;
	}

	/***************************************************************
	 * Input
	 **************************************************************/
	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	int[] nextIntArray(int size) throws IOException {
		int[] ret = new int [size];
		for (int i = 0; i < size; i++)
			ret[i] = nextInt();
		return ret;
	}

	long[] nextLongArray(int size) throws IOException {
		long[] ret = new long [size];
		for (int i = 0; i < size; i++)
			ret[i] = nextLong();
		return ret;
	}

	double[] nextDoubleArray(int size) throws IOException {
		double[] ret = new double [size];
		for (int i = 0; i < size; i++)
			ret[i] = nextDouble();
		return ret;
	}

	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}

	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}

	/***************************************************************
	 * Output
	 **************************************************************/
	void printRepeat(String s, int count) {
		for (int i = 0; i < count; i++)
			out.print(s);
	}

	void printArray(int[] array) {
		if (array == null || array.length == 0)
			return;
		for (int i = 0; i < array.length; i++) {
			if (i > 0) out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}

	void printArray(long[] array) {
		if (array == null || array.length == 0)
			return;
		for (int i = 0; i < array.length; i++) {
			if (i > 0) out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}

	void printArray(double[] array) {
		if (array == null || array.length == 0)
			return;
		for (int i = 0; i < array.length; i++) {
			if (i > 0) out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}

	void printArray(double[] array, String spec) {
		if (array == null || array.length == 0)
			return;
		for (int i = 0; i < array.length; i++) {
			if (i > 0) out.print(' ');
			out.printf(Locale.US, spec, array[i]);
		}
		out.println();
	}

	void printArray(Object[] array) {
		if (array == null || array.length == 0)
			return;
		boolean blank = false;
		for (Object x : array) {
			if (blank) out.print(' '); else blank = true;
			out.print(x);
		}
		out.println();
	}

	@SuppressWarnings("rawtypes")
	void printCollection(Collection collection) {
		if (collection == null || collection.isEmpty())
			return;
		boolean blank = false;
		for (Object x : collection) {
			if (blank) out.print(' '); else blank = true;
			out.print(x);
		}
		out.println();
	}

	/***************************************************************
	 * Utility
	 **************************************************************/
	static String memoryStatus() {
		return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() >> 20) + "/" + (Runtime.getRuntime().totalMemory() >> 20) + " MB";
	}

	static void checkMemory() {
		System.err.println(memoryStatus());
	}

	static long prevTimeStamp = Long.MIN_VALUE;

	static void updateTimer() {
		prevTimeStamp = System.currentTimeMillis();
	}

	static long elapsedTime() {
		return (System.currentTimeMillis() - prevTimeStamp);
	}

	static void checkTimer() {
		System.err.println(elapsedTime() + " ms");
	}

	static void chk(boolean f) {
		if (!f) throw new RuntimeException("Assert failed");
	}

	static void chk(boolean f, String format, Object ... args) {
		if (!f) throw new RuntimeException(String.format(format, args));
	}

	static void log(String format, Object ... args) {
		if (writeLog) System.err.println(String.format(Locale.US, format, args));
	}
}


import java.awt.Point;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;
import static java.lang.Math.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Character.*;
import static java.lang.String.*;
@SuppressWarnings("unused")

public class round169D {
    static PrintWriter out = new PrintWriter(System.out);
    static BufferedReader br = new BufferedReader(new InputStreamReader(
            System.in));
    static StringTokenizer st = new StringTokenizer("");
    static int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    static String next() throws Exception {
        while (true) {
            if (st.hasMoreTokens()) {
                return st.nextToken();
            }
            String s = br.readLine();
            if (s == null) {
                return null;
            }
            st = new StringTokenizer(s);
        }
    }
    public static void main(String[] args)throws Exception {
        long l = parseLong(next());
        long r = parseLong(next());
        long [] min = new long [61];
        for(int i = 1 ; i <= 60 ; ++i){//(2^i)-1 is obtained by min[i]^min[i]+1
            min[i] = (long) pow(2, i - 1) - 1;
        }
        for(int i = 60 ; i >= 0 ; --i){//try to get 2^i-1 as answer.
            if(min[i] >= r)
                continue;
            if(min[i] >= l && min[i] + 1 <= r){
                out.println((long) pow(2, i) - 1);
                out.flush();
                return;
            }
            if(min[i] < l){
                long one_jump = (long) pow(2, i);
                long  jumps = (long) ceil((l - min[i]) / (one_jump * 1.0));
                long cur = min[i] + (jumps * one_jump);
                if(cur >= l && cur + 1 <= r){
                    out.println((long) pow(2, i) - 1);
                    out.flush();
                    return;
                }
            }
        }
        out.println(0);
        out.flush();
    }
}


import	java.util.*;
public	class	Main{
	public	static	void	main(String[]args){
		for(Scanner	cin=new	Scanner(System.in);cin.hasNextLong();System.out.println(Math.max(0,(Long.highestOneBit(cin.nextLong()^cin.nextLong())<<1)-1)));
	}
}


//package round169;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class D2 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		long L = nl(), R = nl();
		out.println(Math.max(0, Long.highestOneBit(L^R)*2-1));
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new D2().run(); }

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author ocelopilli
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskD {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        long LL = in.nextLong();
        long RR = in.nextLong();

        long L = LL;
        long R = RR;
        long ans = 0L;
        long X = Long.highestOneBit( R );
        while ( X > 0L && (L & X) == (R & X) ) X >>= 1;
        while ( X > 0L )
        {
            long a = L & X;
            long b = R & X;
            if ( (a ^ b) == X ) ans |= X;
            else
            {
                if ( b == 0L )
                {
                    if ( (R | X) <= RR )
                    {
                        R |= X;
                        ans |= X;
                    }
                    else if ( (L | X) <= RR )
                    {
                        L |= X;
                        ans |= X;
                    }
                }
                else
                {
                    if ( (L ^ X) >= LL )
                    {
                        L ^= X;
                        ans |= X;
                    }
                    else if ( (R ^ X) >= LL )
                    {
                        R ^= X;
                        ans |= X;
                    }
                }
            }
            X >>= 1;
        }
        out.println( ans );
    }
}

class InputReader {
    BufferedReader br;
    StringTokenizer st;

    public InputReader(InputStream in)
    {
        br = new BufferedReader(new InputStreamReader(in));
        st = null;
    }

    public String next()
    {
        while (st==null || !st.hasMoreTokens())
        {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }

    public long nextLong()
    {
        return Long.parseLong(next());
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author George Marcus
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        long left = in.nextLong();
        long right = in.nextLong();

        long ans = go(left, right);
        out.println(ans);
    }

    private long go(long A, long B) {
        int bA = -1;
        for(int i = 62; i >= 0; i--)
            if((A & (1L << i)) > 0) {
                bA = i;
                break;
            }
        int bB = -1;
        for(int i = 62; i >= 0; i--)
            if((B & (1L << i)) > 0) {
                bB = i;
                break;
            }

        if(bB == -1)
            return 0;
        if(bA < bB)
            return allOne(bB);
        else
            return go(A ^ (1L << bA), B ^ (1L << bB));
    }

    private long allOne(int bits) {
        long ret = 0;
        for(int i = 0; i <= bits; i++)
            ret |= (1L << i);
        return ret;
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public long nextLong() {
        return Long.parseLong(nextString());
    }

    public String nextString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    private boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    }


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {

	public static void main(String [] args ) {
		try{
			String str;
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			BufferedOutputStream bos = new BufferedOutputStream(System.out);
			String eol = System.getProperty("line.separator");
			byte [] eolb = eol.getBytes();
			byte[] spaceb= " ".getBytes();

			str  = br.readLine();
			int blank = str.indexOf( " ");
			long l = Long.parseLong(str.substring(0,blank));
			long r = Long.parseLong(str.substring(blank+1));
			String one = "";
			String two = "";
			while(l>0) {
				if((l%2)==0) {
					one = "0".concat(one);
				} else {
					one = "1".concat(one);
				}
				l/=2;
			}
			while(r>0) {
				if((r%2)==0) {
					two = "0".concat(two);
				} else {
					two = "1".concat(two);
				}
				r/=2;
			}
			while(one.length()<60) {
				one = "0".concat(one);
			}
			while(two.length()<60) {
				two = "0".concat(two);
			}
			int iter = 0;
			String xor = "";
			boolean big = false;
			boolean small = false;
			while(one.charAt(iter) == two.charAt(iter)) {
				xor = xor.concat("0");
				iter++;
				if(iter==60) {
					break;
				}
			}
			for(int i = iter ; i < 60 ; i++) {
				xor = xor.concat("1");
			}
			bos.write(new BigInteger(xor,2).toString().getBytes());
			bos.write(eolb);
			bos.flush();
		}  catch(IOException ioe) {
			ioe.printStackTrace();
		}
	}
}


import java.io.*;
import java.util.*;

public class CFDiv1 {
	FastScanner in;
	PrintWriter out;

	boolean canBe(int from, long curVal, long l, long r) {
		if (curVal > r)
			return false;
		for (int i = 0; i <= from; i++)
			curVal += 1L << i;
		if (curVal >= l)
			return true;
		return false;
	}

	long stupid(long l, long r) {
		long ans = 0;
		for (long i = l; i <= r; i++)
			for (long j = l; j <= r; j++)
				ans = Math.max(ans, i ^ j);
		return ans;
	}

	long solve2(long l, long r) {
		long min = 0;
		long max = 0;
		for (int i = 62; i >= 0; i--) {
			boolean max0 = canBe(i - 1, max, l, r);
			boolean max1 = canBe(i - 1, max | (1L << i), l, r);
			boolean min0 = canBe(i - 1, min, l, r);
			boolean min1 = canBe(i - 1, min | (1L << i), l, r);
			if (max0 && min1 && max > min) {
				min = min | (1L << i);
			} else {
				if (max1 && min0) {
					max |= (1L << i);
				} else {
					if (max1 && min1) {
						max |= (1L << i);
						min |= 1L << i;
					} else {

					}
				}
			}
		}
		return min ^ max;
	}

	void solve() {
		out.println(solve2(in.nextLong(), in.nextLong()));
//		System.err.println(solve2(4, 9));
//		Random rnd = new Random(312);
//		for (int test = 0; test < 10000; test++) {
//			System.err.println(test);
//			int l = rnd.nextInt(100);
//			int r = rnd.nextInt(100) + l;
//			long v1 = stupid(l, r);
//			long v2 = solve2(l, r);
//			if (v1 != v2) {
//				System.err.println(v1 + " " + v2);
//				System.err.println(l + " " + r);
//				throw new AssertionError();
//			}
//		}
	}

	void run() {
		try {
			in = new FastScanner(new File("test.in"));
			out = new PrintWriter(new File("test.out"));

			solve();

			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

	public static void main(String[] args) {
		new CFDiv1().runIO();
	}
}


/**
 * Created with IntelliJ IDEA.
 * User: brzezinsky
 * Date: 12/16/12
 * Time: 7:44 PM
 * To change this template use File | Settings | File Templates.
 */

import java.io.*;
import java.util.*;
import java.util.StringTokenizer;

public class E extends Thread {
    public E(String inputFileName, String outputFileName) {
        try {
            if (inputFileName != null) {
                this.input = new BufferedReader(new FileReader(inputFileName));
            } else {
                this.input = new BufferedReader(new InputStreamReader(System.in));
            }
            if (outputFileName != null) {
                this.output = new PrintWriter(outputFileName);
            } else {
                this.output = new PrintWriter(System.out);
            }
            this.setPriority(Thread.MAX_PRIORITY);
        } catch (Throwable e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
            System.exit(666);
        }
    }

    private void solve() throws Throwable {
        long l = nextLong(), r = nextLong();
        int []bitL = new int[63];
        int []bitR = new int[63];
        int szL = doit(l, bitL);
        int szR = doit(r, bitR);
        int ret = szR;
        while (ret >= 0 && bitL[ret] == bitR[ret]) --ret;
        if (ret < 0) {
            output.println(0);
        } else {
            output.println((1L << (ret + 1)) - 1);
        }
    }

    static final int doit(long q, int []a) {
        int sz = 0;
        while (q != 0L) {
            a[sz++] = (int)(q &1L);
            q >>= 1;
        }
        return sz;
    }

    public void run() {
        try {
            solve();
        } catch (Throwable e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
            System.exit(666);
        } finally {
            output.close();
        }
    }

    public static void main(String... args) {
        new E(null, null).start();
    }

    private int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    private double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    private long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    private String next() throws IOException {
        while (tokens == null || !tokens.hasMoreTokens()) {
            tokens = new StringTokenizer(input.readLine());
        }
        return tokens.nextToken();
    }

    private StringTokenizer tokens;
    private BufferedReader input;
    private PrintWriter output;
}