#include <deque>
#include <iostream>
#include <string>
#include <vector>
#include <list>

class NyaGadgetPositionalNotation
{
public:
	NyaGadgetPositionalNotation(int cardinal)
	{
		cardinal_ = cardinal;
		digit_collection_.push_back(0);
	}
	std::string GetN(int digits = 0)
	{	// 位取り記数法で文字列を取得
		std::string positional_nation;

		for (const auto& e: digit_collection_)
			positional_nation += symbols_[e];

		if (digits == 0 || digits == positional_nation.size())
			return positional_nation;

		if (digits < positional_nation.size())
		{
			positional_nation = positional_nation.substr(0, digits);
		}
		else
		{
			std::string zero(digits - positional_nation.size() ,'0');
			positional_nation = zero + positional_nation;
		}

		return positional_nation;
	}
	void Inc()
	{	// 返り値なしのインクリメント
		bool carry = true;
		int index = digit_collection_.size() - 1;
		while (0 <= index && carry)
		{
			if (digit_collection_[index] != cardinal_ - 1)
			{
				digit_collection_[index]++;
				carry = false;
			}
			else
			{	// 桁上り
				digit_collection_[index] = 0;
				if (index == 0)
				{
					digit_collection_.push_front(0);
					index++;
				}
				carry = true;
			}
			index--;
		}
	}
	NyaGadgetPositionalNotation operator ++()
	{	// 前置インクリメント
		bool carry = true;
		int index = digit_collection_.size() - 1;
		while (0 <= index && carry)
		{
			if (digit_collection_[index] != cardinal_ - 1)
			{
				digit_collection_[index]++;
				carry = false;
			}
			else
			{	// 桁上り
				digit_collection_[index] = 0;
				if (index == 0)
				{
					digit_collection_.push_front(0);
					index++;
				}
				carry = true;
			}
			index--;
		}
		return *this;
	}
	NyaGadgetPositionalNotation operator ++(int)
	{  // 後置インクリメント
		NyaGadgetPositionalNotation pn = *this;

		bool carry = true;
		int index = digit_collection_.size() - 1;
		while (0 <= index && carry)
		{
			if (digit_collection_[index] != cardinal_ - 1)
			{
				digit_collection_[index]++;
				carry = false;
			}
			else
			{	// 桁上り
				digit_collection_[index] = 0;
				if (index == 0)
				{
					digit_collection_.push_front(0);
					index++;
				}
				carry = true;
			}
			index--;
		}

		return pn;
	}
private:
	int cardinal_;		// 基数
	std::string symbols_[36] = 
	{
		"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
		"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
		"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
		"U", "V", "W", "X", "Y", "Z",
	};
	std::deque<int> digit_collection_;	
};

using namespace std;

void Trancelate4to1357(string str3, string& str1357)
{
	str1357.clear();
	for (const auto& e : str3)
	{
		if (e == '0')
			str1357 += "1";
		else if (e == '1')
			str1357 += "3";
		else if (e == '2')
			str1357 += "5";
		else
			str1357 += "7";
	}
}

long Find357(list<string>& collection)
{
	long n = 0;
	for (const auto& e : collection)
	{
		if (e.find("1") != string::npos)
			continue;
		if(e.find("3") != string::npos && e.find("5") != string::npos && e.find("7") != string::npos)
			n++;
	}
	return n;
}

int main()
{
	long n;  cin >> n;
	list<string> str1357_collection;

	string str1357;
	NyaGadgetPositionalNotation pn(4);
	while (1)
	{
		pn.Inc();
		Trancelate4to1357(pn.GetN(), str1357);

		if (n < stol(str1357))
			break;

		if (356 < stol(str1357))
			str1357_collection.insert(str1357_collection.begin(), str1357);
	}

	cout << Find357(str1357_collection);
}

Measured memory_bytes: 23808