#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define nl "\n"
#define OO 0x3f3f3f3f
using namespace std;
void ta2to2a()
{
    ios_base::sync_with_stdio(false), cout.tie(nullptr), cin.tie(nullptr);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int n;
ll shichiGoSan(ll num, bool three, bool five, bool seven)
{
    ll ans = 0;
    if (num > n)
    {
        return 0;
    }
    else if (num <= n && three && five && seven)
    {
        return 1;
    }
    ans += shichiGoSan(num * 10 + 3, true, five, seven) + shichiGoSan(num * 10 + 5, three, true, seven) + shichiGoSan(num * 10 + 7, three, five, true);
    return ans;
}
void solve()
{
    cin >> n;
    cout << shichiGoSan(0, false, false, false);
}
int main()
{
    ta2to2a();
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}