#include <bits/stdc++.h>
int n;
int count(int num);
int is(int num);
int main(void) {
  scanf("%d", &n);
  int ans;
  ans += count(0);
  printf("%d\n", ans);
  return 0;
}
int count(int num) {
  int ret = 0;
  if (num <= n) {
    if (is(num)) {
      ret++;
    }
    ret += count(num * 10 + 3);
    ret += count(num * 10 + 5);
    ret += count(num * 10 + 7);
  }
  return ret;
}
int is(int num) {
  int tmp, f1 = 0, f2 = 0, f3 = 0;
  while (num != 0) {
    tmp = num % 10;
    num = num / 10;
    if (tmp == 3) {
      f1 = 1;
    } else if (tmp == 5) {
      f2 = 1;
    } else if (tmp == 7) {
      f3 = 1;
    }
  }
  if (f1 * f2 * f3 == 1)
    return 1;
  else
    return 0;
}
