#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n;

int dfs(ll a) {
    if (n<a)
        return 0;
    int f3,f5,f7;
    f3=f5=f7=0;
    ll t=a;
    while (t) {
        int b=t%10;
        if (t==3)
            f3=1;
        else if (t==5)
            f5=1;
        else if (t==7)
            f7=1;
        t/=10;
    }
    int f=f3&&f5&&f7;
    return c+dfs(a*10+3)+dfs(a*10+5)*dfs(a*10+7);
}

int main() {
    cin>>n;
    cout<<dfs(0)<<endl;
    return 0;
}