#include <iostream>
using namespace std;
typedef long long ll;

ll N,ans;

void dfs(ll value,ll a, ll b, ll c){
    if(N < value)return;
    if(a>0 && b >0 && c>0)ans++;
    dfs(10*value+3,a+1,b,c);
    dfs(10*value+5,a,b+1,c);    
    dfs(10*value+7,a,b,c+1);
    return;
}

int main(void){
    cin >> N;
    dfs(0,0,0,0);
    cout << ans << endl;
}
