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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
typedef long double ldb;
const int maxn = 1 << 21;
const int N = int(1e5);
const long long mod = int(1e9) + 7;
const long long inf = 1e18;
const double PI = 3.1415926536;
inline int Set(int n, int pos) { return n = n | 1 << pos; }
inline bool check(int n, int pos) { return n & 1 << pos; }
inline int Reset(int n, int pos) { return n = n & ~(1 << pos); }
inline int lastbit(int n) { return n & (-n); }
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return (a * b) / gcd(a, b); }
inline long long power(long long a, long long b) {
  long long ans = 1;
  a = a % mod;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    b >>= 1;
    a = (a * a) % mod;
  }
  return ans;
}
inline long long invmod(long long a) {
  long long ans = power(a, mod - 2);
  return ans;
}
inline long long Egcd(long long a, long long b, long long *x, long long *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  long long x1, y1;
  long long gcd = Egcd(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
inline int bs(int arr[], int l, int r, int item) {
  if (l == r) {
    if (arr[l] == item)
      return r;
    else
      return -1;
  }
  if (item <= arr[(l + r) / 2])
    return bs(arr, l, (l + r) / 2, item);
  else
    return bs(arr, (l + r) / 2 + 1, r, item);
}
inline void fastin(int &x) {
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return;
}
int leap[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int nleap[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, p, l, r;
  cin >> n >> p >> l >> r;
  int t = 0;
  if (p < l) {
    t++;
    t += (l - p);
    if (r != n) t += (r - l);
    if (n > r) t++;
  } else if (r < p) {
    t++;
    t += (p - r);
    if (1 != l) t += (r - l);
    if (1 < l) t++;
  } else {
    if (l == 1 && r == n)
      t = 0;
    else if (l == 1 && r != n) {
      t += (r - p);
      t++;
    } else if (l != 1 && r == n) {
      t += (p - l);
      t++;
    } else {
      if (r - p <= p - l) {
        t += (r - p);
        t++;
        t += (r - l);
        t++;
      } else {
        t += (p - l);
        t++;
        t += (r - l);
        t++;
      }
    }
  }
  cout << t << endl;
  return 0;
}