
#include <iostream>
#include <iomanip>
#include<cmath>
using namespace std;

int main()
{




    /* double r;
     double pi = 3.141592653;

     cin >> r;
     cout << fixed << setprecision(9) << (pi * r * r);
     */



     // long long x;
     // long long  y;
     // int a , b;
     // cin >> x >> y;
     // a = x % 10;
     // b = y % 10;
     // cout << a + b;



     /* long long x, y, n;
      cin >> n >> x >> y;
      cout << n * (y - x) << endl;
      */

      /*long long x, y;
      cin >> x >> y;
      cout << x / y;
      */

      /* cout << fixed << setprecision(6);
       double n, r;
       double pi = 3.141592;

       cin >> n >> r;
       cout << fixed << setprecision(6) << (pi * r * r) - (n * n);
       */

       /*double x, y;
        cin >> x >> y;
        long long ans = ceil(x / y);
        cout << ans;
        */
        /*long long n;
        cin >> n;
        cout << 0 << " " << 0;
        */

        /*double a, b;
        cin >> a >> b;
        cout << "floor " << a << " / " << b << " = " << floor(a / b) << endl;
        cout << "ceil " << a << " / " << b << " = " << ceil(a / b) << endl;
        cout << "round " << a << " / " << b << " = " << round(a / b) << endl;
        */

        /* long long n, sum;
         cin >> n;
         sum = (n * (n + 1)) / 2;
         cout << sum; */

         /* double a, b, c, x;
          cin >> a >> b >> c;
          x = ((2 * a) + (3 * b)) * (5 * c);
          cout << fixed << setprecision(6) << x;
          */


          /* long long n;
           cin >> n;
           cout << (n/2)+1;
           */


           /* double r;
            double pi = 3.141592;

            cin >> r;


            cout << fixed << setprecision(4) << (pi * r * r) + (0.5 * 2 * r * 1.732050 * r) - ((pi * r * r) / 6);
            */


            /* long long n;
             cin >> n;



             cout << (n/50)+((n%50)/20)+((n%50)%20);

             */

             /* long long n;
              cin >> n;

              cout << (n*(n+1)/2)-(n-1);
          */


          /*string x, y;
          cin >> x >> y;
          cout << y << endl;
          cout << x << endl;
          */

          /*long long n;
            cin >> n;

            cout << n % 10;
            */



            /*int n;
            cin >> n;
            cout << (n * 4) + 12;
            */


            /*long long n, m, x;
            cin >> n >> m;
            x = (n / m)*m;
            cout << x;
            */


            /*int n;
            cin >> n;
            cout << n - 1;
            */


            /*double a, b, d, x;
            double pi = 3.141592;
            cin >> a >> b;
            d = sqrt(a / pi) * 2;
            x = sqrt(2) * d;
            cout << fixed << setprecision(6) << 0.25 * x * b;
            */



            /*long long a, b, t;
            cin >> a >> b >> t;
            cout << (t / a) * b;
            */


            /*long long n, a, b, c, d, e;
            cin >> n;
            a = n / 5;
            b = (n % 5) / 4;
            c = ((n % 5) % 4) / 3;
            d = (((n % 5) % 4) % 3) / 2;
            e = ((((n % 5) % 4) % 3) % 2) / 1;
            cout << a + b + c + d + e;
            */

            /*string x;
            cin >> x;
            cout << "Hello" << " " << x;
            */

            /*long long x, y, z, c;

            cin >> x >> y >> z;
            c = (x * x) + (y * z);
            cout << c;
            */

            /*int x, y, temp;
            cin >> x >> y;
            temp = x;
            x = y;
            y = temp;

            cout << x << " " << y;
            */

            /*int x, y;
            cin >> x >> y;
            if (x > y || x == y) {
                cout << "Yes";
            }
            else {
                cout << "No";
            }
            */


            /*int a, b;
            cin >> a >> b;
            if(a%b==0 || b%a==0){
                cout << "Multiples";
            }
            else {
                cout << "No Multiples";
            }
            */


            /*long long a, b, c;
            cin >> a >> b >> c;
            long long minn = a;
            if (b < minn)
                minn = b;

            if (c < minn)
                minn = c;

            cout << minn << " ";

            long long maxx = a;
            if (b > maxx)
                maxx = b;

            if (c > maxx)
                maxx = c;

            cout << maxx;
            */

            /*string m, n, x, y;
            cin >> m >> n;
            cin >> x >> y;

            if (n == y) {
                cout << "ARE Brothers";
            }

            else {
                cout << "NOT";
            }
            */


            /*char t;
            cin >> t;
            if (t >= '0' && t <= '9') {
                cout << "IS DIGIT";

            }
            else {
                cout << "ALPHA" << endl;

                if (t >= 'A' && t <= 'Z') {
                    cout << "IS CAPITAL";
                }
                else{
                    cout << "IS SMALL";
                }


            }
            */

            /*char c;
            cin >> c;
            if (c >= 'A' && c <= 'Z') {
                cout << char(c + 32) ;

            }
            else if (c >= 'a' && c <= 'z') {
                cout << char(c - 32);
            }
            */

            /*
            long long a, b;
            char s;
            cin >> a >> s >> b;
            if (s == '+') {
                cout << a + b;
            }
            else if (s == '-') {
                cout << a - b;
            }
            else if (s == '*') {
                cout << a * b;
            }
            else if (s == '/') {
                cout << a / b;
            }
            */

            /*int a;
            cin >> a;
            if (a > 999 && a <= 9999) {
                if ((a / 1000) % 2 == 0) {
                    cout << "EVEN";
                }
                else {
                    cout << "ODD";
                }
            }
            */

            /*double a, b;
            cin >> a >> b;
            if (a == 0 && b == 0) {
                cout << "Origem";
            }
            else if (a != 0 && b == 0) {
                cout << "Eixo X";
            }
            else if (a == 0 && b != 0) {
                cout << "Eixo Y";
            }
            else if (a > 0 && b > 0) {
                cout << "Q1";
            }

            else if (a < 0 && b > 0) {
                cout << "Q2";
            }
            else if (a < 0 && b < 0) {
                cout << "Q3";
            }
            else if (a > 0 && b < 0) {
                cout << "Q4";
            }
            */

            /*int y, m, d, r;
            cin >> d;
            y = d / 365;
            m = (d % 365) / 30;
            r = (d % 365) % 30;
            cout << y << " " << "years" << endl;
            cout << m << " " << "months" << endl;
            cout << r << " " << "days" << endl;
            */

            /*double a;
            cin >> a;
            if (a >= 0 && a <= 25) {
                cout << "Interval" << " " << "[0,25]";
            }
            else if (a > 25 && a <= 50) {
                cout << "Interval" << " " << "(25,50]";
            }
            else if (a > 50 && a <= 75) {
                cout << "Interval" << " " << "(50,75]";
            }
            else if (a > 75 && a <= 100) {
                cout << "Interval" << " " << "(75,100]";
            }
            else {
                cout << "Out of Intervals";
            }
            */

            /*long long a, b, c;
            cin >> a >> b >> c;

            if (a >= b && a >= c) {
                if (b > c) {
                    cout << c << endl << b << endl << a << endl;
                }
                else {
                    cout << b << endl << c << endl << a << endl;
                }
            }

            else if (b >= a && b >= c) {
                if (a > c) {
                    cout << c << endl << a << endl << b << endl;
                }
                else {
                    cout << a << endl << c << endl << b << endl;
                }
            }

                else if (c >= b && c >= a) {
                if (b > a) {
                    cout << a << endl << b << endl << c << endl;
                }
                else {
                    cout << b << endl << a << endl << c << endl;
                }
            }
            cout << endl << a << endl << b << endl << c << endl;
            */

            /*double x;
            int y;
            cin >> x;
            y = int(x);
            if (x == y) {
                cout << "int" << " " << x;
            }

            else if (x != y) {
                cout << "float" << " " << y << " " << x - y;
            }
            */

            /*int a, b;
            char c;
            cin >> a >> c >> b;
            if (c == '>') {
                if (a > b) {
                    cout << "Right" << endl;
                }
                else {
                    cout << "Wrong" << endl;
                }

            }

            if (c == '<') {
                if (a < b) {
                    cout << "Right" << endl;
                }
                else {
                    cout << "Wrong" << endl;
                }

            }


            if (c == '=') {
                if (a == b) {
                    cout << "Right" << endl;
                }
                else {
                    cout << "Wrong" << endl;
                }

            }
            */

            /*int a, b, c;
            char s, r;
            cin >> a >> s >> b >> r >> c ;
            if (s == '+') {
                if (a + b == c) {
                    cout << "Yes" << endl;
                }
                else {
                    cout << a + b;
                }

            }

            else if (s == '-') {
                if (a - b == c) {
                    cout << "Yes" << endl;
                }
                else {
                    cout << a - b;
                }

            }

            else if (s == '*') {
                if (a * b == c) {
                    cout << "Yes" << endl;
                }
                else {
                    cout << a * b;
                }

            }
            */


            /* long long l1, r1, l2, r2;
            cin >> l1 >> r1 >> l2 >> r2;
            if (l1 <= l2 && r1 >= l2) {
                if (r1 <= r2) {
                    cout << l2 << " " << r1;
                }
                else if (r2 <= r1) {
                    cout << l2 << " " << r2;
                }

            }

            else if (l1 >= l2 && l1 <= r2) {
                if (r1 >= r2) {
                    cout << l1 << " " << r2;
                }
                else if (l2 <= r2) {
                    cout << l1 << " " << r1;
                }

            }

            else {
                cout << -1;
            }
            */


            /* int x, y, z, l;
             cin >> x >> y >> z >> l;
             x = x % 100;
             y = y % 100;
             z = z % 100;
             l = l % 100;
             long long mul = x * y * z * l;
             int n = mul % 100;
             if (n < 10) {
                 cout << 0 << n;
             }
             else {
                 cout << n;
             }
         */

         /*double a, b;
         cin >> a >> b;
         double x = sqrt((a * a) + (b * b));
         double pi = 3.14159;
         double y = (0.25 * (x * x) * pi) * 0.5;
         cout << fixed << setprecision(4) << y;
         */

         /*int w;
         cin >> w;
         if (w > 2 && w % 2 == 0) {
             cout << "YES" << endl;
         }

         else {
             cout << "No" << endl;
         }
         */

       /* double n, k, a;
         cin >> n >> k >> a;

         double x;
         x = (n * k) / a;

         if (x <= 2147483647 && x >= -2147483648) {
             if (x == (int)(x)) {
                 cout << "int" << endl;
             }
             else if (x != (int)(x)) {
                 cout << "double" << endl;
             }

         }


         else if (x > 2147483647 || x < -2147483648) {


             if (x == (long long)(x)){

                 cout << "long long" << endl;
             }
             else if (x != (long long)(x)){
                 cout << "double" << endl;
             }

         }
     */


         /*int x, y;
         cin >> x >> y;
         if (x <= y + 5) {
             cout << "Yes" << endl;
         }
         else {
             cout << "No" << endl;
         }
         */


         /*int n;
         cin >> n;
         if (n >= 95) {
             cout << "A";
         }
         else if (n >= 85 && n < 95) {
             cout << "A-";
         }
         else if (n >= 80 && n < 85) {
             cout << "B";
         }

         else if (n >= 75 && n < 80) {
             cout << "B-";
         }
         else if (n >= 70 && n < 75) {
             cout << "C";
         }
         else if (n >= 65 && n < 70) {
             cout << "C-";
         }
         else if (n >= 60 && n < 65) {
             cout << "D";
         }
         else if (n >= 45 && n < 60) {
             cout << "D-";
         }
         else if (n < 45) {
             cout << "F";
         }
         */


         /*int x, y, z;
         cin >> x >> y >> z;
         cout << z << " " << x << " " << y;
         */


         /*ng long x, y;
         cin >> x >> y;
         if(y > 0)
         {


             cout << x % y;

         }
         else {
             cout << -1;
         }
         */

         /*long long n;
         cin >> n;
         cout << (n)-(n / 7);
         */

         double n, z, a, b;
         cin >> n >> z >> a >> b;
         if (a <= n && b <= n) {
             if (a != b) {
                 cout << (abs(a) - abs(b - z));

             }
         }


  /* int n;
    cin >> n;
    if (n == 10){
        cout << 0;
}

    else {
        cout << (n / 25) + ((n % 25) / 10) + (((n % 25) % 10) / 5) + ((((n % 25) % 10) % 5) / 1);
    }
    */
    
/*long long a, b, c, d;
cin >> a >> b >> c >> d;
if (b*log(a) > d*log(c)) {
    cout << "YES" << endl;
}
else {
    cout << "NO" << endl;
}
*/


























    return 0;
}

