#include"stdc++.h"
using namespace std;

#define LL long long
#define VLL vector<long long>
	string strnum = "0123456789";
	string alpS = "abcdefghijklmnopqrstuvwxyz";
	string alpL = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	int sizealp = (int)(alpS.size());
	int mod = 1e9 + 7;
#define SORT(x) sort(x.begin(),x.end())
#define REVE(x) reverse(x.begin(),x.end())
#define rep(i,n) for(int i=0;i<n;i++)
#define COUT(x) cout<<x<<endl
	double pai = 3.1415926535;
	string atc = "atcoder";
	typedef pair<long long, long long> data_t;

	int yuukuriddo(int a, int b) {
		if (b > a) {
			swap(a, b);
		}
		int tmp = a % b;
		if (tmp == 0) {
			return b;
		}
		else {
			yuukuriddo(tmp, b);
		}
	}

int main() {
	LL N;
	cin >> N;
	string s = to_string(N);
	if (s.size() < 3) {
		COUT(0);
		return 0;
	}
	int count = 0;
	int tmp = 0;
	vector<int> ternery(s.size());
	for (int i = 1; i <= pow(3,(int)(s.size())); i++) {
		tmp = 0;
		ternery[0] = i % 3;
		for (int j = 1; j < s.size(); j++) {
			ternery[j] = (i*(int)pow(3, j)) % 3;
		}
		int flag1[3] = { 0,0,0 };
		for (int j = 0; j < s.size(); j++) {
			if (ternery[j] == 0)
				ternery[j] = 3;

			else if (ternery[j] == 1)
				ternery[j] = 5;
			else
				ternery[j] = 7;
		}
		for (int j = 0; j < s.size(); j++) {
			tmp += ternery[j] * (int)pow(10, j);
		}
	}
}