#include <iostream>
using namespace std;

int cnt = 0;
int n;
void dfs (long long a, int use) {
    if (a > n) return;
    if (use == 0b111) cnt++;
    dfs(a*10 + 7, use | 0b100);
    dfs(a*10 + 5, use | 0b010);
    dfs(a*10 + 3, use | 0b001);
}

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