#include <bits/stdc++.h>
int max(int a, int b) {
  if (a > b)
    return a;
  else
    return b;
}
int min(int a, int b) {
  if (a < b)
    return a;
  else
    return b;
}
int main() {
  int n;
  scanf("%d", &n);
  if (n >= 777777777) n = 777777777;
  int count = 0;
  int tmp = 0;
  int digit = 0;
  int flag, flag3, flag5, flag7;
  for (int i = 357; i <= n; i += 2) {
    tmp = i;
    flag = 0;
    flag3 = 0;
    flag5 = 0;
    flag7 = 0;
    digit = 0;
    while (tmp > 0) {
      if (tmp % 10 != 3 && tmp % 10 != 5 && tmp % 10 != 7) {
        flag = 1;
        break;
      } else if (tmp % 10 == 3)
        flag3 = 1;
      else if (tmp % 10 == 5)
        flag5 = 1;
      else if (tmp % 10 == 7)
        flag7 = 1;
      tmp /= 10;
      digit++;
    }
    if (flag == 0 && flag3 == 1 && flag5 == 1 && flag7 == 1) count++;
    if (flag == 0 && flag7 == 1 && flag3 == 0 && flag5 == 0) {
      int a = 25;
      for (int j = 0; j < digit - 1; ++j) {
        a *= 10;
      }
      i += a;
    }
  }
  printf("%d", count);
  return 0;
}
