#include <iostream>
using namespace std;
int n;
int num = 0;

void func(long long x, int a, int b, int c){
  if(x > n){
    return;
  }
  
  if(a && b && c){
    num += 1;
  }

  func(10 * x + 3, 1, b, c);
	func(10 * x + 5, a, 1, c);
	func(10 * x + 7, a, b, 1);

}

int main() {
  cin >> n;
  func(0, 0, 0, 0);
  cout << num << endl;
}