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

int N,cnt;

void solve(long long now,int check){
    if(now > N) return;
    if(check == 0b111) cnt++;
    solve(now*10+3,check | 0b001);
    solve(now*10+5,check | 0b010);
    solve(now*10+7,check | 0b100);
}

int main(){
    cin>>N;
    cnt = 0;
    solve(0,0b000);
    cout<<cnt<<endl;

    return 0;
}