#include<bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}

signed main(){
    int A,B,C,D;
    cin>>A>>B>>C>>D;


    int x=abs(A-C);
    int y=abs(B-D);
    if(x==0||y==0){
        cout<<0<<endl;
        return 0;
    }
    cout<<x+y-1-gcd(x,y)+1<<endl;
    return 0;
}
