#include<bits/stdc++.h>
using namespace std;
int64_t n,ans;
void DFS(int64_t x,bool a,bool b,bool c)
{
    if(x>n)return;
    if(a==1&&b==1&&c==1)ans++;
    DFS(x*10+3,1,b,c);
    DFS(x*10+5,a,1,c);
    DFS(x*10+7,a,b,1);
}

int main()
{
    cin>>n;
    DFS(0,0,0,0);
    cout<<ans<<endl;
}
