#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
const double PI = acos(-1), EPS = 1e-7;
const int OO = 0x3f3f3f3f, N = 1e7 + 5, mod = 1e9 + 7;
long long gcd(long long x, long long y) { return (!y) ? x : gcd(y, x % y); }
long long lcm(long long x, long long y) { return ((x / gcd(x, y)) * y); }
bool palindrom(string s) {
  string r = s;
  reverse(r.begin(), r.end());
  if (r == s) return 1;
  return 0;
}
long long nCr(long long n, long long r) {
  long long ans = 1;
  long long div = 1;
  for (long long i = r + 1; i <= n; i++) {
    ans = ans * i;
    ans /= div;
    div++;
  }
  return ans;
}
long long NpR(long long n, long long r) {
  long long ans = 1;
  for (long long i = (n - r) + 1; i <= n; i++) {
    ans *= i;
    ans %= mod;
  }
  return ans;
}
int copare(double a, double b) {
  if (fabs(a - b) <= 10e-7)
    return 0;
  else
    return a < b ? -1 : 1;
}
int n;
int fun(long long liky, int index = 0) {
  if (n < liky)
    return -1;
  else if (n == liky)
    return index;
  return max(fun(liky * 10 + 4, index * 2 + 1),
             fun(liky * 10 + 7, index * 2 + 2));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  cout << fun(0);
}
