#include using ll=long long; using std::cin; using std::cout; using std::vector; using std::endl; int main(){ int N; cin>>N; const int max=1e9; assert(10<=N&&N<=max); int ans=0; for(int i=10;i<=100;i++){ if(i%3==0&&i<=N) ans++; } for(int i=0;i<(1<<18);i++){ int memo=0,X=i; for(int j=0;j<9;j++){ memo=memo*10+X%4*3; X/=4; } if(memo<=N&&memo>=100) ans++; } cout<