#include <bits/stdc++.h>
using namespace std;
bool isLucky(int num) {
  while (num) {
    if (num % 10 != 4 && num % 10 != 7) {
      return false;
    }
    num /= 10;
  }
  return true;
}
int numDig(int num) {
  int c = 0;
  while (num) {
    c++;
    num /= 10;
  }
  return c;
}
int fourtimes(int num) {
  int r = 0;
  while (num--) {
    r = r * 10 + 4;
  }
  return r;
}
int main() {
  int n;
  cin >> n;
  int c = pow(2, numDig(n)) - 1;
  for (int i = fourtimes(numDig(n)) + 1; i <= n; i++) {
    if (isLucky(i)) {
      c++;
    }
  }
  cout << c;
  return 0;
}
