#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  int i, sum = 0, c = 0, x, num, j;
  for (i = n; i > 0; i = i / 10) {
    c++;
    x = i;
  }
  for (i = 1; i < c; i++) sum = sum + pow(2, i);
  if (x > 4 && x < 8) sum = sum + pow(2, c) / 2;
  if (x == 8 || x == 9) sum = sum + pow(2, c);
  if (x < 5) {
    num = 4;
    for (i = 1; i < c; i++) num = num * 10 + 4;
    for (i = num; i <= n; i++) {
      int mri = 0;
      for (j = i; j > 0; j = j / 10) {
        if (j % 10 == 7 || j % 10 == 4)
          continue;
        else
          mri++;
      }
      if (mri == 0) sum++;
    }
  }
  if (x == 7) {
    num = 7;
    for (i = 1; i < c; i++) num = num * 10 + 4;
    for (i = num; i <= n; i++) {
      int mri = 0;
      for (j = i; j > 0; j = j / 10) {
        if (j % 10 == 7 || j % 10 == 4)
          continue;
        else
          mri++;
      }
      if (mri == 0) sum++;
    }
  }
  printf("%d", sum);
  return 0;
}
