#include <bits/stdc++.h>
int main()
{
  int N;std::cin >> N;
  int ans = 0;
  auto rep = [&](auto&& self,bool fst,int n, bool tw, bool th, bool fi)->void{
  	if(n <= N and tw and th and fi){ans++;}
    if(n > N){return;}
    if(not fst){self(self,false,10*n,tw,th,fi);}
    self(self,false,10*n+7,true,th,fi);
    self(self,false,10*n+5,tw,true,fi);
    self(self,false,10*n+3,tw,th,true);
  };
  std::cout << ans << std::endl;
  return 0;
}