#include<iostream>

using namespace std;

int N;
int ans = 0;

void dfs(long long int x,int a, int b, int c) {
    if( x > N ) return ;
    if( a == 1 && b == 1 && c == 1) ans++;
    dfs(10 * x + 7, 1, b, c);
    dfs(10 * x + 5, a, 1, c);
    dfs(10 * x + 3, a, b, 1);
}

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