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.lang.*;
import java.util.*;

public class Codeforces {
	
	static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(System.out);
	
	static int MOD = 1000000007, prime[];
	static long gcd, x, y;
	static boolean isPrime[];
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), pos = sc.nextInt(), l = sc.nextInt(), r = sc.nextInt();
		int min = 0;
		if(l > 1 && r < n) {
			if(pos < l)
				min = (l - pos) + (r - l);
			else if(pos > r)
				min = (pos - r) + (r - l);
			else {
				double mid = (l + r) / 2.0;
				if(pos < mid)
					min = (pos - l) + (r - l);
				else if(pos > mid)
					min = (r - pos) + (r - l);
				else
					min = (pos - l) + (r - l);
			}
			min += 2;
		}
		else if(l == 1 && r < n) {
			min = Math.abs(r - pos);
			min++;
		}
		else if(l > 1 && r == n) {
			min = Math.abs(pos - l);
			min++;
		}
		System.out.println(min);
		sc.close();
	}
	
	static long min_3(long a, long b, long c) {
		if(a < b && a < c)
			return a;
		if(b < c)
			return b;
		return c;
	}
	
	static long max_3(long x, long y, long z) {
		if(x >= y && x >= z)
			return x;
		if(y >= x && y >= z)
			return y;
		return z;
	}
	
	static long power(long x, long y, long m) {
	    if (y == 0)
	        return 1;
	    long p = power(x, y/2, m) % m;
	    p = (p * p) % m;
	    return (y%2 == 0) ? p : (x * p) % m;
	}
	
	public static void prime_sieve(int N) {
        isPrime = new boolean[N+1];
        Arrays.fill(isPrime, true);
        isPrime[0] = isPrime[1] = false;
        for(int i = 2; i*i <= N; i++) {
            if(isPrime[i]==true) {
            	for(int j = 2*i; j <= N; j += i) {
            		isPrime[j] = false;
            		prime[j] = i;
				}
            }
        }
    }
	
	public static long factorial(long num) {
		long result = 1;
		for(int i = 1; i <= num; i++)
			result = result * (long)i;
		return result;
	}
	
	public static void ExtendedEuclidian(long a, long b) {
		if(b == 0) {
	        gcd = a;
	        x = 1;
	        y = 0;
	    }
	    else {
	        ExtendedEuclidian(b, a%b);
	        int temp = (int) x;
	        x = y;
	        y = temp - (a/b)*y;
	    }
	}
	
	public static long GCD(long n, long m) {
		if(m != 0)
			return GCD(m, n % m);
		else
			return n;
	}
	
	static class CustomComp implements Comparator<Object> {
		@Override
        public int compare(Object o1, Object o2) {
			return 1;
        }
	}
	
	static class Graph {
		
	    private int V;
	    private LinkedList<Integer> adj[];
	    boolean visited[];
	    
	    Graph(int v) {
	        V = v + 1;
	        visited = new boolean[V];
	        adj = new LinkedList[V];
	        for(int i = 0; i < V; ++i)
	            adj[i] = new LinkedList<Integer>();
	    }
	 
	    void addEdge(int v, int w) {
	        adj[v].add(w);
	        adj[w].add(v);
	    }
	    
	    // prints BFS traversal from a given source s
	    void BFS(int s) {
	        LinkedList<Integer> queue = new LinkedList<Integer>();
	        visited[s] = true;
	        queue.add(s);
	        while (queue.size() != 0) {
	            s = queue.poll();
	            System.out.print(s+" ");
	            Iterator<Integer> i = adj[s].listIterator();
	            while (i.hasNext()) {
	                int n = i.next();
	                if (!visited[n]) {
	                    visited[n] = true;
	                    queue.add(n);
	                }
	            }
	        }
	    }
	    
	    void DFS(int v, boolean visited[]) {
	        visited[v] = true;
	        System.out.print(v+" ");
	        Iterator<Integer> i = adj[v].listIterator();
	        while (i.hasNext()) {
	            int n = i.next();
	            if (!visited[n])
	                DFS(n, visited);
	        }
	    }
	    
	    boolean isCyclicUndirectedUtil(int v, boolean visited[], int parent) {
	        // Mark the current node as visited
	        visited[v] = true;
	        Integer i;
	 
	        // Recur for all the vertices adjacent to this vertex
	        Iterator<Integer> it = adj[v].iterator();
	        while (it.hasNext()) {
	            i = it.next();
	 
	            // If an adjacent is not visited, then recur for that
	            // adjacent
	            if (!visited[i]) {
	                if (isCyclicUndirectedUtil(i, visited, v))
	                    return true;
	            }
	 
	            // If an adjacent is visited and not parent of current
	            // vertex, then there is a cycle.
	            else if (i != parent)
	                return true;
	        }
	        return false;
	    }
	 
	    // Returns true if the graph contains a cycle, else false.
	    boolean isCyclicUndirected() {
	        // Mark all the vertices as not visited and not part of
	        // recursion stack
	        boolean visited[] = new boolean[V];
	 
	        // Call the recursive helper function to detect cycle in
	        // different DFS trees
	        for (int u = 1; u <= V; u++)
	            if (!visited[u]) // Don't recur for u if already visited
	                if (isCyclicUndirectedUtil(u, visited, -1))
	                    return true;
	 
	        return false;
	    }
	    
	    boolean isCyclicDirectedUtil(int v, boolean visited[], boolean recStack[]) {
	    	if(visited[v] == false) {
	            // Mark the current node as visited and part of recursion stack
	            visited[v] = true;
	            recStack[v] = true;
	     
	            // Recur for all the vertices adjacent to this vertex
	            Iterator<Integer> i = adj[v].listIterator();
	            while(i.hasNext()) {
	            	int n = i.next();
	                if (!visited[n] && isCyclicDirectedUtil(n, visited, recStack))
	                    return true;
	                else if (recStack[n])
	                    return true;
	            }
	        }
	        recStack[v] = false;  // remove the vertex from recursion stack
	        return false;
	    }
	    
	    boolean isCyclicDirected() {
	    	boolean visited[] = new boolean[V];
	    	boolean recStack[] = new boolean[V];
	    	for(int i = 1; i <= V; i++)
	            if (isCyclicDirectedUtil(i, visited, recStack))
	                return true;
	    	return false;
	    }
	    
	    void topologicalSortUtil(int v, boolean visited[], Stack stack) {
			// Mark the current node as visited.
			visited[v] = true;
			
			// Recur for all the vertices adjacent to this vertex
			Iterator<Integer> it = adj[v].iterator();
			while (it.hasNext()) {
				int i = it.next();
				if (!visited[i])
					topologicalSortUtil(i, visited, stack);
			}
			
			// Push current vertex to stack which stores result
			stack.push(new Integer(v));
		}
			
		// The function to do Topological Sort. It uses recursive topologicalSortUtil()
		void topologicalSort() {
			Stack stack = new Stack();
			
			// Mark all the vertices as not visited
			boolean visited[] = new boolean[V];
			
			// Call the recursive helper function to store Topological Sort starting from all
			// vertices one by one
			for (int i = 1; i <= V; i++)
			if (visited[i] == false)
				topologicalSortUtil(i, visited, stack);
			
			// Print contents of stack
			while (stack.empty()==false)
				System.out.print(stack.pop() + " ");
		}
	}
}