#include<bits/stdc++.h>
using namespace std;
int n,cnt;
void search(long number,int three,int five,int seven){
    if(number<=n){
        if(three&&five&&seven)cnt++;
        search(number*10+3,1,five,seven);
        search(number*10+5,three,1,seven);
        search(number*10+7,three,five,1);
    }
}
int main(){
    cin>>n;
    search(0,0,0,0);
    cout<<cnt<<endl;
}