#include<iostream>

using namespace std;
int cnt = 0;
int n;
void check(long x, int a, int b, int c){
  if(x > n)return;
  if(a&b&c)cnt++;
  check(x*10+3,1,b,c);
  check(x*10+5,a,1,c);
  check(x*10+7,a,b,1);
}

int main(){
  cin >> n;
  check(0,0,0,0);
  cout << cnt << endl;
  return 0;
}
