// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 10;

#define ll long long

int cs[100000] = {0, 732,732,732,1334,1334,1936,1936,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,3140,3140,3805,3805,4470,4470,4470,4470,4470,4470,4470,4470,4470,4470,4470,4470,4470,4470,4470,4470,5135,5135,5737,5737,6402,6402,6402,6402,6402,6402,6402,6402,6402,6402,6402,6402,6402,6402,6402,6402,7067,7067,7732,7732,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8936,8936,9601,9601,10266,10266,10266,10266,10266,10266,10266,10266,10266,10266,10266,10266,10266,10266,10266,10266,10931,10931,11596,11596,12325,12325,12325,12325,12325,12325,12325,12325,12325,12325,12325,12325,12325,12325,12325,12325,12990,12990,13719,13719,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,15049,15049,15714,15714,16443,16443,16443,16443,16443,16443,16443,16443,16443,16443,16443,16443,16443,16443,16443,16443,17108,17108,17710,17710,18375,18375,18375,18375,18375,18375,18375,18375,18375,18375,18375,18375,18375,18375,18375,18375,19104,19104,19769,19769,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,21099,21099,21828,21828,22493,22493,22493,22493,22493,22493,22493,22493,22493,22493,22493,22493,22493,22493,22493,22493,23222,23222,23887,23887,24552,24552,24552,24552,24552,24552,24552,24552,24552,24552,24552,24552,24552,24552,24552,24552,25217,25217,25882,25882,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484};



int main()

{

	int n;

	cin >> n;

	int q = 0;

	while(q <= n)

		q += 1000000;

	q -= 1000000;

	int ans = cs[(q / 1000000)];

	//q -= 1000000;

	for(int i = q + 1; i <= n; i ++)

	{

		int t1 = 0, t2 = 0, t3 = 0, t4 = 0;

		int temp = i;

		while(temp)

		{

			if(temp % 10 == 3)

				t1 ++;

			if(temp % 10 == 5)

				t2 ++;

			if(temp % 10 == 7)

				t3 ++;

			t4 ++;

			temp /= 10;

		}

		if(t1 != 0 && t2 != 0 && t3 != 0 && t1 + t2 + t3 == t4)

			ans ++;

	}

	cout << ans;







	return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

int t;

int ans = 0;

void dfs(unsigned n,bool k3,bool k5,bool k7){

	if(n>t)return; 

	if(k3&&k5&&k7){

		ans++;	

	}

	dfs(n*10+3,true,k5,k7);

	dfs(n*10+5,k3,true,k7);

	dfs(n*10+7,k3,k5,true);

}



int main(){

	scanf("%d", &t);

	dfs(0,false,false,false);

	

//	dfs(3,true,false,false);

//	dfs(5,false,true,false);

//	dfs(7,false,false,true);

	

	

	printf("%d\n",ans);

	return 0;

}

// Fastest known solution for this problem: