#include<iostream>

using namespace std;

int N,ans;

void dfs(long long x, bool flag3,bool flag5,bool flag7)
{if(x > N){ return;}
 if(flag3 && flag5 && flag7) {ans++;}
 
 dfs(10*x + 3, true, flag5, flag7);
 dfs(10*x + 5, flag3, true, flag7);
 dfs(10*x + 7, flag3, flag5, true);
}
int main(void)
{cin >> N;
 ans = 0;
 
 dfs(0,0,0,0);
 
 cout << ans << endl;}
 