#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int n;
int ans;

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



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