#include <bits/stdc++.h>
using namespace std;
long long n;
long long solve(long long lucky = 0, long long idx = 0) {
  if (lucky >= n)
    if (lucky == n)
      return idx;
    else
      return -1;
  return max(solve(lucky * 10 + 4, idx * 2 + 1),
             solve(lucky * 10 + 7, idx * 2 + 2));
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(NULL);
  cin.tie(NULL);
  cin >> n;
  cout << solve();
}
