#include <iostream>
using namespace std;
int n;
int ans;

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

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