#include <cstdio>

#include <algorithm>

using namespace std;

int n, ans;

void dfs(long long x, int s) {
  if (x > n)
    return;
  if (s == 7)
    ++ans;
  dfs(x * 10 + 3, s | 1);
  dfs(x * 10 + 5, s | 2);
  dfs(x * 10 + 7, s | 4);
}

int main() {
  scanf("%d", &n);
  dfs(0, 0);
  printf("%d\n", ans);
  return 0;
}
