#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int N = 2e7 + 9, M = 1e7, OO = 0x3f3f3f3f;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
  ;
  int n, counter = 0;
  scanf("%d", &n);
  if (n > 777777777) {
    n = 777777777;
  }
  for (int i = 355; i <= n; i += 2) {
    int num = i;
    int flag3 = 0, flag5 = 0, flag7 = 0;
    int otherflag = 0;
    while (num) {
      if (num % 10 == 3) {
        flag3 = 1;
      } else if (num % 10 == 5) {
        flag5 = 1;
      } else if (num % 10 == 7) {
        flag7 = 1;
      } else {
        otherflag = 1;
        break;
      }
      num /= 10;
    }
    if (flag3 & flag5 & flag7 && !otherflag) {
      counter++;
    }
  }
  printf("%d", counter);
  return 0;
}
