#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define FORL(i,m,n) for(ll i=(m); i < (n); i += 1)
#define REPL(i,n) FORL(i,0,(n))

const ll INF = 1LL << 60;

struct UnionFind{
    vector<int> par,siz;

    UnionFind(int n) : par(n,-1),siz(n,1) {}

    int root(int x){
        if(par[x] == -1) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y){
        return root(x) == root(y);
    }

    bool unite(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return false;

        if(siz[x] < siz[y]) swap(x,y);

        par[y] = x;
        siz[x] += siz[y];
        return true;
    }
};

using Edge = pair<int, pair<int,int>>;

ll combination(ll n,ll k){
    if(n == 0) return 0;
    if(k == 0) return 1;
    ll x=1,y=1;
    REPL(i,k){
        x *= n;
        n--;
    }
    REPL(i,k-1){
        y *= k-i;
    }

    return x/y;
}

int combination(int n,int k){
    if(n == 0) return 0;
    if(k == 0) return 1;
    int x=1,y=1;
    REP(i,k){
        x *= n;
        n--;
    }
    REP(i,k-1){
        y *= k-i;
    }

    return x/y;
}

ll min(ll a, ll b){
    if(a > b){
        return b;
    }else if(a < b){
        return a;
    }else{
        return a;
    }
}

ll max(ll a, ll b){
    if(a > b){
        return a;
    }else if(a < b){
        return b;
    }else{
        return a;
    }
}

int fac(int n){
    if(n == 1) return 1;
    else return n * fac(n-1);
} 

int main(void){
    ll n;
    cin >> n;

    if(n == 1){
        cout << 1 << endl;
        return 0;
    }

    ll a=INF,b=INF,c=INF;

    for(ll i=1,j=0; i<n; i*=2,j+=1){
        ll tmp_a = n / i;
        ll tmp_b = j;
        ll tmp_c = n % i;
        if(a+b+c > tmp_a+tmp_b+tmp_c){
            a = tmp_a;
            b = tmp_b;
            c = tmp_c;
        }
    }

    cout << a+b+c << endl;
}
#include<bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#endif

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<bool> vb;
typedef vector<vb> vvb;


#define rep(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repi(i, a, b) for (int i = (int)a; i >= (int)b; i--)
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a.size())
#define umin(a, x) a = min(a, x)
#define umax(a, x) a = max(a, x)

ll nxt() {
	ll x; cin >> x; return x;
}

void setIO(string s) {
	#ifndef LOCAL
	ios_base::sync_with_stdio(0); cin.tie(0); 
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
	#endif
}

set<pll> generate_box(int a, int b) {
	set<pll> ans;

	rep(i, -3, 4) {
		rep(j, -3, 4) {
			if (abs(i) + abs(j) <= 3) {
				int c = a - i, d = b - j;
				ans.insert({c, d});
			}
		}
	}
	return ans;
}

int ans = 0;


int reach_1(int a, int b, int c, int d) {
	//this is for 1
	auto x = generate_box(a, b);
	for (auto it = x.begin(); it != x.end(); it++) {
		if ((*it).fi == c && (*it).se == d) {
			ans = 1;
			return 1;
		}
	}
	if (a + b == c + d || a - b == c - d) {
		ans = 1; return 1;
	}

	return 0;
}

void solve() {
	int a, b, c, d; cin >> a >> b >> c >> d;

	//0
	if (a == c && b == d) {
		ans = 0;
		return;
	}

	//1
	if (reach_1(a, b, c, d)) return;

	//this for 2
	if (((a + b) % 2) % 2 == ((c + d) % 2) % 2) {
		ans = 2;
		return;
	}
	auto x = generate_box(a, b);
	auto y = generate_box(c, d);
	for (auto it = x.begin(); it != x.end(); it++) {
		int A = (*it).fi, B = (*it).se;
		if (reach_1(A, B, c, d)) {
			ans = 2;
			return;
		}
	}
	for (auto it = y.begin(); it != y.end(); it++) {
		int A = (*it).fi, B = (*it).se;
		if (reach_1(a, b, A, B)) {
			ans = 2;
			return;
		}
	}

	//3
	ans = 3;
	return;
}	

	
int32_t main(){
	// setIO("trapped");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cout << fixed << setprecision(10);

	int T = 1;
	// cin >> T;

	for (int tc = 1; tc <= T; tc++) {
		// cout << "Case #" << tc << ": ";
		solve();
	}

	cout << ans << endl;
}
