#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  if (n <= 3) {
    cout << "0";
    return 0;
  }
  if (n >= 4 && n < 7) {
    cout << "1";
    return 0;
  } else if (n >= 7 && n <= 9) {
    cout << "2";
    return 0;
  }
  long long int k = 0;
  long long int z, count = 0;
  z = n;
  while (z > 0) {
    z = z / 10;
    k++;
  }
  count = pow(2, k) - 2;
  long long int a, b, c, d, e, r;
  a = 44 * pow(10, k - 2);
  b = 48 * pow(10, k - 2);
  c = 74 * pow(10, k - 2);
  d = 78 * pow(10, k - 2);
  while (a <= b && a <= n) {
    int flag = 0;
    e = a;
    while (e > 0) {
      r = e % 10;
      if (r != 4 && r != 7) {
        flag = 1;
        break;
      }
      e = e / 10;
    }
    if (flag == 0) {
      count++;
    }
    a++;
  }
  while (c <= d && c <= n) {
    int flag = 0;
    e = c;
    while (e > 0) {
      r = e % 10;
      if (r != 4 && r != 7) {
        flag = 1;
        break;
      }
      e = e / 10;
    }
    if (flag == 0) {
      count++;
    }
    c++;
  }
  cout << count;
}
