#include #include #include #include #include #include #include long long int to(int d){ long long int res = 0; for(long long int mv = 3; d > 0; mv *= 10, d /= 4) res += (d % 4) * mv; return res; } int main(void){ std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(16); int n; std::cin >> n; int ok = 0, ng = (1 << 20) + 1; while(ng - ok > 1){ const int mid = (ng + ok) >> 1; const long long int v = to(mid); if(v <= n) ok = mid; else ng = mid; } int res = ok - 3; for(int x = 12; x <= 100 and x <= n; x += 3){ if( (x % 10) % 3 != 0 ) ++res; } std::cout << res << '\n'; return 0; }