Problem: Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tabs with indices from l to r (inclusive) for her studies, and she wants to close all the tabs that don't belong to this segment as fast as possible.

Each second Luba can either try moving the cursor to the left or to the right (if the cursor is currently at the tab i, then she can move it to the tab max(i - 1, a) or to the tab min(i + 1, b)) or try closing all the tabs to the left or to the right of the cursor (if the cursor is currently at the tab i, she can close all the tabs with indices from segment [a, i - 1] or from segment [i + 1, b]). In the aforementioned expressions a and b denote the minimum and maximum index of an unclosed tab, respectively. For example, if there were 7 tabs initially and tabs 1, 2 and 7 are closed, then a = 3, b = 6.

What is the minimum number of seconds Luba has to spend in order to leave only the tabs with initial indices from l to r inclusive opened?

Input

The only line of input contains four integer numbers n, pos, l, r (1 ≤ n ≤ 100, 1 ≤ pos ≤ n, 1 ≤ l ≤ r ≤ n) — the number of the tabs, the cursor position and the segment which Luba needs to leave opened.

Output

Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment [l, r].

Examples

Input

6 3 2 4


Output

5


Input

6 3 1 3


Output

1


Input

5 2 1 5


Output

0

Note

In the first test Luba can do the following operations: shift the mouse cursor to the tab 2, close all the tabs to the left of it, shift the mouse cursor to the tab 3, then to the tab 4, and then close all the tabs to the right of it.

In the second test she only needs to close all the tabs to the right of the current position of the cursor.

In the third test Luba doesn't need to do anything.

Solution (in JAVA):

Solution:

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

import java.util.InputMismatchException;

public class Edu36_B {
public static void main(String[] args){
 InputReader in=new InputReader(System.in);
 PrintWriter pw=new PrintWriter(System.out);
 int n=in.readInt();
 int p=in.readInt();
 int l=in.readInt();
 int r=in.readInt();
 
 
int count=0;

if(r==n && l==1) {
	count=0;
}
else {
if(p<l) {
	if(r==n) {
		count = (l-p) +1;
	}
	else {
	count += (l-p) + (r-l) + 2;
	}
}
else if(p>r) {
	if(l==1) {
		count = (p-r) +1;
	}
	else {
	count = (p-r) + (r-l) + 2;
	}
}
else if(p==l) {
	count = (r-l) + 2 ;
	
	if(l==1) {
		count--;
	}
	
	if(r==n) {
		count=1;
	}
}
else if(p==r) {
count = (r-l) + 2 ;
	
	if(l==1) {
		count=1;
	}
	
	if(r==n) {
		count--;
	}
}
else {
	
	if(l==1) {
		count= (r-p) +1;
	}
	else if(r==n) {
		count = (p-l) + 1;
	}
	else {
	count = Math.min(p-l, r-p);
	count += (r-l) + 2;
	}
}
}
pw.println(count);
pw.close();
}
static long fib(long n)
{
long F[][] = new long[][]{{1,1},{1,0}};
if (n == 0)
    return 0;
power(F, n-1);
 
   return F[0][0];
}
  
 /* Helper function that multiplies 2 matrices F and M of size 2*2, and
 puts the multiplication result back to F[][] */
static void multiply(long F[][], long M[][])
{
long x =  F[0][0]*M[0][0] + F[0][1]*M[1][0];
long y =  F[0][0]*M[0][1] + F[0][1]*M[1][1];
long z =  F[1][0]*M[0][0] + F[1][1]*M[1][0];
long w =  F[1][0]*M[0][1] + F[1][1]*M[1][1];
  
F[0][0] = x%1000000007;
F[0][1] = y%1000000007;
F[1][0] = z%1000000007;
F[1][1] = w%1000000007;
}


static void power(long F[][], long n)
{
long i;
long M[][] = new long[][]{{1,1},{1,0}};
 
// n - 1 times multiply the matrix to {{1,0},{0,1}}
for (i = 2; i <= n; i++)
    multiply(F, M);
}
static long modulo(long a,long b,long c) {
	long x=1;
	long y=a;
	while(b > 0){
		if(b%2 == 1){
			x=(x*y)%c;
		}
		y = (y*y)%c; // squaring the base
		b /= 2;
	}
	return  x%c;
}
static long gcd(long x, long y)
{
	if(x==0)
		return y;
	if(y==0)
		return x;
	long r=0, a, b;
	a = (x > y) ? x : y; // a is greater number
	b = (x < y) ? x : y; // b is smaller number
	r = b;
	while(a % b != 0)
	{
		r = a % b;
		a = b;
		b = r;
	}
	return r;
}
static class Pair implements Comparable<Pair>{
	int x,y;
	Pair(int xx,int yy){
		x=xx;y=yy;
	}
	@Override
	public int compareTo(Pair o) {
		if(Integer.compare(o.y, this.y)==0){
			return Integer.compare(this.x, o.x);
		}
		else{
			return Integer.compare(this.y, o.y);
		}
	}
}
static  class InputReader
{
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;
 
    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 int readInt()
    {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read();
        }
        int 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 String readString()
    {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do
        {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }
    public String readLine() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isEndOfLine(c));
        return res.toString();
    }
    
 
    public double readDouble() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        double res = 0;
        while (!isSpaceChar(c) && c != '.') {
            if (c == 'e' || c == 'E')
                return res * Math.pow(10, readInt());
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        }
        if (c == '.') {
            c = read();
            double m = 1;
            while (!isSpaceChar(c)) {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, readInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                m /= 10;
                res += (c - '0') * m;
                c = read();
            }
        }
        return res * sgn;
    }
    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 boolean isSpaceChar(int c)
    {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }
 
    public String next()
    {
        return readString();
    }
 
    public interface SpaceCharFilter
    {
        public boolean isSpaceChar(int ch);
    }
    public boolean isEndOfLine(int c) {
        return c == '\n' || c == '\r' || c == -1;
    }
}
}