#include <bits/stdc++.h>
using namespace std;
long long n;
string s = "357";
long long shichigosan(string x) {
  if (stoll(x) >= n) {
    return 0;
  }
  int seven = 0, five = 0, three = 0;
  for (int i = 0; i < x.size(); i++) {
    if (x[i] == '7')
      seven++;
    else if (x[i] == '5')
      five++;
    else if (x[i] == '3')
      three++;
  }
  int c;
  if (seven && five && three)
    c = 1;
  else
    c = 0;
  for (int i = 0; i < s.size(); i++) {
    c += shichigosan(x + s[i]);
  }
  return c;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  cout << shichigosan("0");
  return 0;
}
