#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-11;
const long long MOD = 1000000007;
const int N = 100000 + 7;
void fast() { std::ios_base::sync_with_stdio(0); }
int n;
int ans = 0;
bool isok(int x) {
  vector<int> arr(9);
  while (x) {
    arr[x % 10]++;
    x /= 10;
  }
  return (arr[3] > 0 && arr[5] > 0 && arr[7] > 0);
}
void backtrack(int x) {
  if (x > n) return;
  if (isok(x)) ans++;
  backtrack(x * 10 + 3);
  backtrack(x * 10 + 5);
  backtrack(x * 10 + 7);
}
int main() {
  scanf("%d", &n);
  backtrack(0);
  printf("%d\n", ans);
  return 0;
}
