#include <iostream>
using namespace std;
long long a = 0;
long long ans;

void dfs(long long n, int f) {
  if (n > a) return;
  if (f == 0b111) ans++;
  n *= 10;
  dfs(n + 3, f | 0b001);
  dfs(n + 5, f | 0b010);
  dfs(n + 7, f | 0b100);
}

int main() {
  cin >> a;
  dfs(0, 0);
  cout << ans << endl;
  return 0;
}
