#include <bits/stdc++.h>
using namespace std;
vector<int> candi;
void track(int n) {
  if (n >= 1000000000) return;
  if (n) candi.push_back(n);
  track(n * 10 + 3);
  track(n * 10 + 5);
  track(n * 10 + 7);
}
int main() {
  int n;
  cin >> n;
  track(0);
  sort(candi.begin(), candi.end());
  int cnt = 0;
  for (int i = 0; i < candi.size(); i++) {
    if (candi[i] > n) break;
    cnt++;
  }
  cout << cnt;
}
