#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 7;
const int bigN = 1e9 + 5;
int mod = 1e9;
int arr[N], temp[N];
;
int arr1[N];
int arr2[501][501];
void init() {
  cin.tie(0);
  cin.sync_with_stdio(0);
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long n;
void Merge(int *arr, int start1, int end1, int start2, int end2) {
  int ind = start1, startIndex = start1;
  while (start1 <= end1 and start2 <= end2) {
    if (arr[start1] < arr[start2]) {
      temp[ind++] = arr[start1++];
    } else
      temp[ind++] = arr[start2++];
  }
  while (start1 <= end1) temp[ind++] = arr[start1++];
  while (start2 <= end2) temp[ind++] = arr[start2++];
  memcpy(arr + startIndex, temp + startIndex,
         sizeof(arr[0]) * (ind - startIndex));
}
void mergeSort(int *arr, int start, int end) {
  if (start >= end) return;
  int mid = start + (end - start) / 2;
  mergeSort(arr, start, mid);
  mergeSort(arr, mid + 1, end);
  Merge(arr, start, mid, mid + 1, end);
}
long long backtrack(long long luck, long long idx) {
  if (luck > 1e9)
    return -1;
  else if (luck == n)
    return idx;
  return max(backtrack(luck * 10 + 4, idx * 2 + 1),
             backtrack(luck * 10 + 7, idx * 2 + 2));
}
int main() {
  init();
  cin >> n;
  cout << backtrack(0, 0);
  return 0;
}
