#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define Dev 1000000007
// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;
int main()
{
long long int n=0;
long long int ch_num = 0;
char ch[11] = {0};
rep(i, 11) ch[i] = -1;
cin >> n;
int counter = 0;
while (n >= ch_num)
{
int foo[3] = {0};
ch[0]++;
rep(i, 10)
{
if (ch[i] > 2)
{
ch[i] = 0;
ch[i + 1]++;
}
}
ch_num = 0;
rep(i, 11)
{
if (ch[i] == 0)
{
ch_num += 3 * pow(10, i);
foo[0] += 1;
}
if (ch[i] == 1)
{
ch_num += 5 * pow(10, i);
foo[1] += 1;
}
if (ch[i] == 2)
{
ch_num += 7 * pow(10, i);
foo[2] += 1;
}
}
if (foo[0] > 0 && foo[1] > 0 && foo[2] > 0 &&n>=ch_num) //3,5,7があるか
counter++;
}
cout << counter << endl;
return 0;
}