#include <bits/stdc++.h>
using namespace std;

long long N;
int counter;

void func(long long i,int use){
  if(i > N) return;
  if(use == 0b111) ++counter;

  func(i * 10 + 7, use | 0b001);
  func(i * 10 + 5, use | 0b010);
  func(i * 10 + 3, use | 0b100);


}

int main() {
  cin >> N;
  func(0,0);
  cout << counter << endl;



}

