#include <iostream>
#include <cmath>
using namespace std;

int main(void)
{
  int n;
  int level;
  int comb;
  int full_comb;
  int biggest_digit;
  int i;
  
  cin >> n;
  
  level = (int)log(10, n);
  
  for(i = 3; i < level; i++){
    comb += pow(3, i) - pow(2, i) * 3 + 3;
  }
  
  biggest_digit = n / pow(10, level);
  full_comb = pow(3, level) - pow(2, level) * 3 + 3;
  
  if(biggest_digit >= 7){
  	comb += full_comb;
  }else if(biggest_digit >= 5){
    comb += full_comb / 3 * 2;
  }else if(biggest_digit >= 3){
    comb += full_comb / 3
  }
  
  cout << comb << endl;
  
  return 0;
}