#include <bits/stdc++.h>
#define IO                       \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define mem(a, x) memset(a, x, sizeof(a))
#define per(x, a, b) for (int x = a; x <= b; x++)
#define rep(x, a, b) for (int x = a; x >= b; x--)

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-8;

LL n;
LL nm[4] = {0, 7, 5, 3};
int main() {
#ifdef LOCAL_IM0QIANQIAN
    freopen("test.in", "r", stdin);
//    freopen("test.out", "w", stdout);
#else
    IO;
#endif // LOCAL_IM0QIANQIAN

    while (cin >> n) {
        LL ans = 0;
        for (int i = 0; i < 4; i++) {
            for (int j = (i ? 1 : 0); j < 4; j++) {
                for (int k = (i || j ? 1 : 0); k < 4; k++) {
                    for (int a = (i || j || k ? 1 : 0); a < 4; a++) {
                        for (int b = (i || j || k || a ? 1 : 0); b < 4; b++) {
                            for (int c = (i || j || k || a || b ? 1 : 0); c < 4;
                                 c++) {
                                for (int d =
                                         (i || j || k || a || b || c ? 1 : 0);
                                     d < 4; d++) {
                                    for (int e =
                                             (i || j || k || a || b || c || d
                                                  ? 1
                                                  : 0);
                                         e < 4; e++) {
                                        for (int f = (i || j || k || a || b ||
                                                              c || d || e
                                                          ? 1
                                                          : 0);
                                             f < 4; f++) {
                                            LL num = 0;
                                            num = nm[i];
                                            num = num * 10 + nm[j];
                                            num = num * 10 + nm[k];
                                            num = num * 10 + nm[a];
                                            num = num * 10 + nm[b];
                                            num = num * 10 + nm[c];
                                            num = num * 10 + nm[d];
                                            num = num * 10 + nm[e];
                                            num = num * 10 + nm[f];
                                            int ff[10] = {0};
                                            ff[nm[i]]++;

                                            ff[nm[j]]++;
                                            ff[nm[k]]++;
                                            ff[nm[a]]++;
                                            ff[nm[b]]++;
                                            ff[nm[c]]++;
                                            ff[nm[d]]++;
                                            ff[nm[e]]++;
                                            ff[nm[f]]++;
                                            if (ff[3] == 0 || ff[5] == 0 ||
                                                ff[7] == 0)
                                                continue;
                                            if (num <= n) {
                                                // cout << num << endl;
                                                ++ans;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256