#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
vector<int> s = {357, 375, 537, 573, 735, 753};
void seiri() {
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == s[i - 1]) {
      s.erase(s.begin() + i);
      i--;
    }
  }
  return;
}
int main() {
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  int n;
  cin >> n;
  int b = 0;
  int c;
  for (int i = 4; i < 10; i++) {
    c = (int)s.size();
    for (int j = b; j < c; j++) {
      for (int k = 0; k < i; k++) {
        s.push_back(s[j] / (int)pow(10, k) * pow(10, k + 1) + 3 * pow(10, k) +
                    s[j] % (int)(pow(10, k)));
        s.push_back(s[j] / (int)pow(10, k) * pow(10, k + 1) + 5 * pow(10, k) +
                    s[j] % (int)(pow(10, k)));
        s.push_back(s[j] / (int)pow(10, k) * pow(10, k + 1) + 7 * pow(10, k) +
                    s[j] % (int)(pow(10, k)));
      }
    }
    b += 6 * pow(3, i - 3);
    sort(s.begin(), s.end());
    seiri();
  }
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] <= n) ans++;
  }
  cout << ans << endl;
  return 0;
}
