#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;

typedef pair <int, int> pii;

int main()
{

	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	//cout << LONG_MAX << endl;
	//long long n, A[1000000000];
	//ll n, m, q;
	string s, t;
	ll n, k;
	ll x[2005];
	ll y[2005];
	int w;
	cin >> w;
	int i[10] = {};
	for (i[1] = 0; i[1] <= 700000000; i[1] += 200000000)
	{
		for (i[2] = 0; i[2] <= 70000000; i[2] += 20000000)
		{
			for (i[3] = 0; i[3] <= 7000000; i[3] += 2000000)
			{
				for (i[4] = 0; i[4] <= 700000; i[4] += 200000)
				{
					for (i[5] = 0; i[5] <= 70000; i[5] += 20000)
					{
						for (i[6] = 0; i[6] <= 7000; i[6] += 2000)
						{
							for (i[7] = 300; i[7] <= 700; i[7] += 200)
							{
								for (i[8] = 30; i[8] <= 70; i[8] += 20)
								{
									for (i[9] = 3; i[9] <= 7; i[9] += 2)
									{
										b = 0;
										c = 0;
										d = 0;
										e = 0;
										for (int y = 1; y < 10; y++)
										{
											//cout<< i[y] / int(pow(10,9 - y)) <<endl;
											if (i[y] / int(pow(10, 9 - y)) == 3)
											{
												b++;
											}
											else if (i[y] / int(pow(10, 9 - y)) == 5)
											{
												c++;
											}
											else if (i[y] / int(pow(10, 9 - y)) == 7)
											{
												d++;
											}
											if (c >= 1 || d >= 1 || b >= 1)
											{
												if (i[y] / int(pow(10, 9 - y)) == 0)
												{
													e = 1;
													break;
												}
											}
										}
										if (e==1)
										{
											continue;
										}
										if (c >= 1 && d >= 1 && b >= 1)
										{
											if (accumulate(i + 1, i + 10, 0) <= w)
											{
												a++;
												//cout << int(accumulate(i + 1, i + 10, 0)) << endl;
											}
										}
									}
								}
							}
							if (i[6] == 0)i[6] = 1000;
						}
						if (i[5] == 0)i[5] = 10000;
					}
					if (i[4] == 0)i[4] = 100000;
				}
				if (i[3] == 0)i[3] = 1000000;
			}
			if (i[2] == 0)i[2] = 10000000;
		}
		if (i[1] == 0)i[1] = 100000000;
	}

	cout << a << endl;
	//cout <<  << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え


Measured memory_bytes: 384