#include #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; ll mod_pow(ll x, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } int main() { int N, ans = 0; cin >> N; for (int i = 10; i < 100; i++) { if (i > N) { cout << ans << "\n"; return 0; } if (i % 3 == 0) ans++; } for (int i = 16; i < 1048576; i++) { ll x = 0, y = 1, z = i; while (z > 0) { x += y * 3 * (z % 4); y *= 10; z /= 4; } //cout << x << "\n"; if (x > N) { cout << ans << "\n"; return 0; } ans++; } }