#include <bits/stdc++.h>
using namespace std;
int M = 0;
int n;
int A[1000];
void dfs(int k) {
  int f3 = 0, f5 = 0, f7 = 0;
  long long num = 0;
  for (int i = 0; i < k; i++) {
    num = num * 10 + A[i];
    if (A[i] == 3)
      f3 = 1;
    else if (A[i] == 5)
      f5 = 1;
    else if (A[i] == 7)
      f7 = 1;
  }
  if (num > n) return;
  if (f3 * f5 * f7 == 1) M++;
  A[k] = 3;
  dfs(k + 1);
  A[k] = 5;
  dfs(k + 1);
  A[k] = 7;
  dfs(k + 1);
}
int main() {
  cin >> n;
  dfs(0);
  cout << M;
  return 0;
}
