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.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
 
public class Main
{
    
    static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;

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

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

		public int ni() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nl() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

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

		public String rs() {
			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 nextLine() {
			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 boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

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

	}

	



    public static void main(String[] args)
    {
        
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);
        int n = sc.ni();
        int p = sc.ni();
        int l = sc.ni(); 
        int r = sc.ni();
        int c = 0;
           c =  Math.min(Math.abs(p-l),Math.abs(p-r))+(r-l);
           if(l == 1 &&r!= n)
           w.println(Math.abs(p-r)+1);
           else if(l != 1 &&r== n)
           w.println(Math.abs(p-l)+1);
           else if(l == 1 &&r== n)
           w.println(0);
           else
        w.println(c+2);
        
       
       
        
       
        
        
        
           
        
       
           
         
          
        /*
        int x = sc.ni();
        int y = sc.ni();
        String [][]arr = new String[x+2][y+2];
        for(int i=1;i<=x;i++)
        {
            for(int j=1;j<=y;j++)
            {
                arr[i][j] = sc.rs();
            }
        }
        int c = 0;
        for(int i=1;i<=x;i++)
        {
            for(int j=1;j<=y;j++)
            {
                if(arr[i][j].equals("S"))
                {
                    if(arr[i-1][j].equals("W") ||arr[i+1][j].equals("W")||arr[i][j-1].equals("W")||arr[i][j+1].equals("W"))
                    c++;
                }
            }
        }
        if(c != 0)
        w.println("No");
        else
        {
            for(int i=1;i<=x;i++)
        {
            for(int j=1;j<=y;j++)
            {
                if(arr[i][j].equals("S"))
                {
                    if(arr[i-1][j].equals("."))
                    arr[i-1][j].replace(".","D");
                    
                    if(arr[i+1][j].equals("."))
                    arr[i+1][j].replace(".","D");
                    
                    if(arr[i][j+1].equals("."))
                    arr[i][j+1].replace(".","D");
                    
                    if(arr[i][j-1].equals("."))
                    arr[i][j-1].replace(".","D");
                    
                    
                }
            }
        }
        w.println("Yes");
        
        for(int i=1;i<=x;i++)
        {
            for(int j=1;j<=y;j++)
            {
                w.print(arr[i][j]);
                
            }
            w.println();
        }
        }
        
        */
        
        
        /*
        118B
        int x = sc.ni();
        int res = x*2;
        String [][]arr = new String[res+ 1][res+1];
        
        for(int i=0;i<=x*2;i++)
        {
            for(int j=x-i;j<=x+i;j++)
            {
                if(j <= x)
                    arr[i][j] = ips(i+j-x);
                    else
                     arr[i][j] = ips(2*x -i - j);
                
            }
            
        }
        for(int i=0;i<=x*2;i++)
        {
            for(int j=0;j<=x*2;j++)
            {
                w.print(arr[i][j] + " ");
                
            }
            w.println();
        }
    */
       
        
        
        
          
       
       
      
       
        
        
        
           
        
       
           
           
        
        
        
    
        w.close();
        

        
    } 
    /*
    static boolean is(int p,int x,int y)
    {
        int flag = 0;
        
            for(int j=2;j<=p;j++)
            {
                if(x % j == 0)
                {
                    flag = 1;
                    break;
                }
                else 
                continue;
                
            }
            
        if(flag == 1)
        return false;
        else
        return true;
        
    }
    */
    static int binarysearch(int []arr,int p,int n)
    {
        
        int st = 0;
        int end = n-1;
        int mid = (st + end)/2;
        int temp = 0;
        while(st <= end)
        { 
            mid = (st + end)/2;
        
            if(p >= arr[mid])
            {
                st = mid+1;
                
            }
            else if(p < arr[mid])
            {
                end = mid-1;
                
            }
            temp = st;
            
            
        }
        
        return temp;
    }
    
   
    static class Student
    {
        int start;
        int end;
        int index;
        Student(int start,int end,int index)
        {
            this.start = start;
            this.end = end;
            this.index = index;
            
        }
        
    }
    static int lis(int arr[],int n)
    {
          int lis[] = new int[n];
          int i,j,max = 0;
 
          /* Initialize LIS values for all indexes */
           for ( i = 0; i < n; i++ )
              lis[i] = 1;
 
           /* Compute optimized LIS values in bottom up manner */
           for ( i = 1; i < n; i++ )
              for ( j = 0; j < i; j++ ) 
                         if ( arr[i] > arr[j] && lis[i] <= lis[j])
                    lis[i]++;
 
           /* Pick maximum of all LIS values */
           for ( i = 0; i < n; i++ )
              if ( max < lis[i] )
                 max = lis[i];
 
            return max;
    }
    
    
    public static int ip(String s){
		return Integer.parseInt(s);
	}
	 public static String ips(int s){
		return Integer.toString(s);
	}
	
    
					 
}