#include <bits/stdc++.h>
int func(int n, int N);
int judge(int N);
int main(void) {
  int N;
  scanf("%d", &N);
  printf("%d\n", func(0, N));
  return 0;
}
int func(int n, int N) {
  int ret;
  if (n > N) {
    return 0;
  }
  if (judge(n) == 1) {
    ret = 1;
  } else {
    ret = 0;
  }
  ret += func(n * 10 + 3, N) + func(n * 10 + 5, N) + func(n * 10 + 7, N);
  return ret;
}
int judge(int N) {
  int l;
  int i, j, k;
  int s[20] = {};
  int state = 1;
  int state_3 = 0;
  int state_5 = 0;
  int state_7 = 0;
  for (i = 0; i < 20; i++) {
    if (N >= pow(10, i) && N < pow(10, i + 1)) {
      l = i + 1;
      break;
    }
  }
  for (i = 0; i < l; i++) {
    s[i] = N % 10 + '0';
    N /= 10;
  }
  for (i = 0; i < l; i++) {
    if (s[i] != '3' && s[i] != '5' && s[i] != '7') {
      state = 0;
    }
  }
  if (state == 1) {
    for (i = 0; i < l; i++) {
      if (s[i] == '3') {
        state_3 = 1;
      }
    }
    for (i = 0; i < l; i++) {
      if (s[i] == '5') {
        state_5 = 1;
      }
    }
    for (i = 0; i < l; i++) {
      if (s[i] == '7') {
        state_7 = 1;
      }
    }
  }
  if (state == 1 && state_3 == 1 && state_5 == 1 && state_7 == 1) {
    return 1;
  } else {
    return 0;
  }
}
