#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int m[] = {0, 3, 5, 7};
int main()
{
    ll n;
    scanf("%lld", &n);
    int cnt = 0;
    for (int i = 0;; i++)
    {
        ll cur = 0;
        bool b[4] = {0};
        char buf[20];
        int l = 0, x = i;
        do
            buf[l++] = x & 3, x >>= 2;
        while (x);
        for (int j = l - 1; j >= 0; j--)
            cur = cur * 10 + m[buf[j]], b[buf[j]] = true;
        if (cur > n)
            break;
        if (!b[0] && b[1] && b[2] && b[3])
            cnt++;
    }
    printf("%d", cnt);
    return 0;
}