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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;

#define rep(i, a, b) for (int i = a; i < b; i++)

bool check7(int a, int base){
    while(a > 0){
        if (a % base == 7)
            return true;
        a /= base;
    }
    return false;
}

void solve()
{
    int n;
    cin >> n;

    unordered_set<int> svns;
    rep(i, 1, n+1){
        if (check7(i, 10)) svns.insert(i);
        else if (check7(i, 8)) svns.insert(i);
    }

    cout << n - svns.size() << endl;
}

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(0); 
    cin.tie(0);
    // int t;
    // cin >> t;
    // while(t--)
        solve();
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define fastrun ios_base::sync_with_stdio;cin.tie(nullptr);cin.tie(nullptr);
typedef long long int ll;
#define t int t;cin>>t;while(t--)
#define For(n) for(int i=0;i<n;i++)
#define INT(a) int a;scanf("%d",&a);
#define LLI(a) ll a;scanf("%lld",&a);
#define DOUBLE(a) double a;scanf("%f",&a);
bool great(pair<int,int>a,pair<int,int>b){
	return (a.first<b.first);
}
int search(vector<int> v,int size,int a){
	int l =0,r=size-1;
	int result = size;
	while(l<=r){
		int mid = (l+r)/2;
		if(v[mid]>a){
			result = mid;
			r=mid-1;
		}
		else{
			l = mid+1;
		}
	}
	return result;
}
template<class c>
c gcd (c a,c b){
	if(b==0)
		return a;
	gcd(b,a%b);
}
bool check(ll a,ll b,ll c,ll d){
	return ((a+b==c+d)||(a-b==c-d)||(abs(a-c)+abs(b-d)<=3));
}
int solve(ll a,ll b,ll c,ll d){
	if(a>c){
		swap(a,c);
		swap(b,d);
	}if(a==c&&b==d)
		return 0;
	else if(check(a,b,c,d))
		return 1;
	else if((a+b)%2==(c+d)%2)
		return 2;
	for(int i=-2;i<=2;i++){
		for(int j=-2;j<=2;j++){
			ll p = c+i;ll q = d+j;
			if(check(a,b,p,q))
				return 2;
		}
	}if((check(a,b,c+3,d)||check(a,b,c-3,d)||check(a,b,c,d+3)||check(a,b,c+3,d)))
		return 2;
	return 3;
}
int main(){
	fastrun
	LLI(a)LLI(b)LLI(c)LLI(d)
	printf("%d\n",solve(a,b,c,d));
} 