#include<cstdint>
//#include<stdexcept> //GCC5 しか積んでないのでAtCoderは何をやってもダメ
#include<limits> //GCC5 しか積んでないのでAtCoderは何をやってもダメ
class konmai_number{
  std::uint32_t val;
 public:
  explicit constexpr konmai_number(std::uint32_t n)noexcept:val{n}{}
  constexpr konmai_number(const konmai_number&) = default;
  static constexpr bool is_konmai_number(std::uint64_t n)noexcept{
    bool three = false, five = false, seven = false;
    while(n != 0){
      switch(n%10){
      case 3:
        three = true;
        break;
      case 5:
        five = true;
        break;
      case 7:
        seven = true;
        break;
      default:return false;
      }
      n /= 10;
    }
    return three && five && seven;
  }
  constexpr bool is_valid()const noexcept{
    std::uint32_t v = val;
    while((v&0b11) != 0)v >>= 2;
    return v == 0;
  }
  static constexpr konmai_number encode(std::uint64_t n){
    if(n == 0)
      return konmai_number{0};
    std::uint32_t val = 0;
    while(n != 0){
      const std::uint32_t x = n%10;
      switch(x){
      case 3:case 5:case 7:{
        val = val >> 2 | ((x-1)/2) << 30;
        n /= 10;
      }break;
      default:return konmai_number(std::numeric_limits<std::uint32_t>::max());//throw std::logic_error("n is not 753 number"); //GCC5 しか積んでないのでAtCoderは何をやってもダメ
      }
    }
    while((val&0b11) == 0)
      val >>= 2;
    return konmai_number{val};
  }
  constexpr std::uint64_t decode()const{
    std::uint64_t ret = 0;
    std::uint32_t val = this->val;
    constexpr std::uint32_t mask = 0b11000000'00000000'00000000'00000000;
    for(std::size_t i = 0; i < sizeof(val)*8/2; ++i){
      const std::uint8_t top4 = (val&mask) >> 30;
      ret = ret*10 + top4*2 + (top4 != 0 ? 1 : 0);
      val <<= 2;
    }
    return ret;
  }
  constexpr std::uint32_t get()const{return val;}
  constexpr bool operator==(konmai_number rhs)const noexcept{return val == rhs.val;}
  constexpr bool operator!=(konmai_number rhs)const noexcept{return !(*this == rhs);}
};

//#include<limits> //GCC5 しか積んでないのでAtCoderは何をやってもダメ
#include<iterator>
struct konmai_generator{
  class iterator{
    konmai_number n;
   public:
    using value_type = konmai_number;
    using difference_type = std::ptrdiff_t;
    using reference = value_type&;
    using pointer = value_type*;
    using iterator_category = std::forward_iterator_tag;
    explicit constexpr iterator()noexcept:n{std::numeric_limits<std::uint32_t>::max()}{}
    explicit constexpr iterator(konmai_number k)noexcept:n{k}{}
    constexpr const value_type& operator*()const noexcept{return n;}
    constexpr iterator& operator++()noexcept{
      auto x = n.get();
      while(x != std::numeric_limits<std::uint32_t>::max()){
        const konmai_number kn{++x};
        if(kn.is_valid() && konmai_number::is_konmai_number(kn.decode())){
          n = kn;
          break;
        }
      }
      return *this;
    }
    constexpr bool operator!=(const iterator& rhs)const noexcept{return n != rhs.n;}
  };
 private:
  iterator b{konmai_number::encode(357)};
  iterator e;
  static constexpr iterator calc_end(std::uint64_t x)noexcept{
    if(x < 357u)
      return iterator{konmai_number::encode(357)};
    auto y = x;
    std::uint64_t t = 10;
    while(x != 0){
      switch(x%10){
      case 0:case 1:case 2:x-=10;[[fallthrough]];
      case 7:case 8:case 9:y = y/t*t+7*(t/10)+y%(t/10);break;
      case 3:case 4:       y = y/t*t+3*(t/10)+y%(t/10);break;
      case 5:case 6:       y = y/t*t+5*(t/10)+y%(t/10);break;
      }
      x /= 10;
      t *= 10;
    }
    return ++iterator{konmai_number::encode(y)};
  }
 public:
  constexpr konmai_generator()noexcept:e{}{}
  constexpr konmai_generator(std::uint64_t x)noexcept:e{calc_end(x)}{}
  iterator begin()const noexcept{return b;}
  iterator end()const noexcept{return e;}
};

#include<iostream>
template<typename T>
T input(std::istream& is = std::cin){T t; is >> t; return t;}
int main(){
  const auto range = konmai_generator{input<std::uint64_t>()};
  std::cout << std::distance(range.begin(), range.end()) << std::endl;
}


Measured memory_bytes: 256