#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX
typedef pair<int, int> P;
long long ans=0;
int dfs(long long n,long long x, long long s3, long long s5, long long s7){
    if(n<x){
        return;
    }
    else{
        if (s3&&s5&&s7) ans+=1;
        dfs(n,x*10+3,1,s5,s7);
        dfs(n,x*10+5,s3,1,s7);
        dfs(n,x*10+7,s3,s5,1);
    }
}
int main(){
   long long n;
   dfs(n,0,0,0,0);
   cout<<ans<<endl;
}