#include <bits/stdc++.h>
int n;
int ans = 0;
using namespace std;
int recurse(string now) {
  int kaisu;
  if (stoi(now) > n) {
    return 0;
  }
  kaisu = recurse("3" + now) + recurse("5" + now) + recurse("7" + now);
  return kaisu + 1;
}
int main() {
  cin >> n;
  cout << recurse("") - 1 << endl;
  return 0;
}
