#include <bits/stdc++.h>
int main() {
  long long int n;
  int i, j, k, ans = 0, check[10] = {0};
  char num[20], e[20] = "777";
  scanf("%lld", &n);
  for (i = 3; i <= 9; i++) {
    for (j = 0; j < i; j++) {
      num[j] = '3';
    }
    while (strcmp(num, e) != 0) {
      for (j = 0; j < i; j++) {
        int a = num[j] - '0';
        check[a]++;
      }
      if (check[3] > 0 && check[5] > 0 && check[7]) {
        if (atoi(num) <= n) {
          ans++;
        }
      }
      check[3] = 0;
      check[5] = 0;
      check[7] = 0;
      k = 0;
      for (j = 0; k == 0; j++) {
        if (num[j] == '7') {
          num[j] = '3';
          k = 0;
        } else if (num[j] == '5') {
          num[j] = '7';
          k = 1;
        } else if (num[j] == '3') {
          num[j] = '5';
          k = 1;
        }
      }
    }
    e[i] = '7';
  }
  printf("%d\n", ans);
  return 0;
}
