#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll test_case;
	test_case=1;
    //cin>>test_case;
    while(test_case--)
    {
    	ll n;
    	cin>>n;
    	ll s=0;
    	ll i=111;
    	i=i*9;
    	while(i<n)
    	{
    		s+=n-i;
    		i/=9;
    		i=i*10+1;
    		i=i*10+1;
    		i=i*10+1;
    		i*=9;
		}
		cout<<s<<endl;
    }
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

bool is_ok_10(int x)
{
  while (0 < x) {
    if (x % 10 == 7) {
      return false;
    }
    x = x / 10;
  }
  return true;
}

bool is_ok_7(int x)
{
  while (0 < x) {
    if (x % 8 == 7) {
      return false;
    }
    x = x / 8;
  }
  return true;
}

int main()
{
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if(is_ok_7(i) && is_ok_10(i)) {
      cnt++;
    }
  }
  cout << cnt << '\n';
  return 0;
}
