#include <bits/stdc++.h>
int getKeta(int);
int get357(int, int);
char* toString(int);
bool hasAllNum(char*);
int comp(char* str1, char* str2);
char chr[] = {'3', '5', '7'};
int main() {
  int input = 0;
  int output = 0;
  scanf("%d", &input);
  if (input < 357) {
    printf("%d", output);
    return 0;
  }
  int keta = getKeta(input);
  char* str = toString(input);
  int max = (int)pow(3.0f, keta);
  char* str357 = new char[keta + 1];
  char* str3579 = new char[keta * 1024 * 1024];
  str3579[1023] = '\0';
  str357[keta] = '\0';
  for (int i = 0; i < max; i++) {
    for (int j = keta - 1; j >= 0; j--) {
      str357[keta - j - 1] = chr[(i / (int)pow(3.0f, j)) % 3];
    }
    if (hasAllNum(str357) == true && comp(str, str357) > 0) {
      output++;
    }
    bool ret = hasAllNum(str3579);
  }
  for (int i = keta - 1; i > 0; i--) {
    output += get357(i, 3);
  }
  printf("%d", output);
  return 0;
}
int getKeta(int input) {
  int ret = 0;
  while (input > 0) {
    ret++;
    input /= 10;
  }
  return ret;
}
int get357(int keta, int saitei) {
  if (keta < 1 || keta < saitei) return 0;
  if (saitei == 0) return (int)pow(3.0f, keta);
  if (keta == 1 && saitei == 1) return 1;
  int ret = 0;
  ret += get357(keta - 1, saitei - 1) * saitei;
  ret += get357(keta - 1, saitei) * (3 - saitei);
  return ret;
}
char* toString(int input) {
  int keta = getKeta(input);
  char* p = (char*)malloc(keta + 1);
  for (int i = keta - 1; i >= 0; i--) {
    p[i] = '0' + input % 10;
    input /= 10;
  }
  p[keta] = '\0';
  return p;
}
bool hasAllNum(char* str) {
  int flag3 = false;
  int flag5 = false;
  int flag7 = false;
  int index = 0;
  while (str[index] != '\0') {
    if (str[index] == '3')
      flag3 = true;
    else if (str[index] == '5')
      flag5 = true;
    else
      flag7 = true;
    index++;
  }
  return flag3 & flag5 & flag7;
}
int comp(char* str1, char* str2) {
  while (*str1 != '\0' && *str2 != '\0') {
    if (*str1 - *str2 == 0) {
      str1++;
      str2++;
      continue;
    }
    return *str1 - *str2;
  }
  return 0;
}
