#define debug 0
#define test 0
#define CPLUS 1
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#if CPLUS
#include <iostream>
#include <stack>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <iterator>
#include <queue>
#include <map>
#include <unordered_map>
#include <functional>
#include <iomanip>
using namespace std;
#endif

int check(int i)
{
	int flag[11] = { 0 };
	while (i) {
		if (i % 10 == 3 || i % 10 == 5 || i % 10 == 7)
			flag[i % 10] = 1;
		else
			return 0;
		i /= 10;
	}
	if (flag[3] && flag[5] && flag[7])
		return 1;
	else
		return 0;
}

int main(void)
{
#if debug
	freopen("in.txt", "r", stdin);
#endif
	int t;
	scanf("%d", &t);
	int ans = 0;
	for (int i = 355; i <= t; i+=2) {
		if (check(i))
			ans++;
	}
	printf("%d\n", ans);
	return 0;
}