#include <bits/stdc++.h>
using namespace std;
string s357 = "357";
int f(string s, int n) {
  int ans = 0;
  for (const auto& e : s357) {
    string tmps = s + e;
    if (n >= stoll(tmps)) {
      if (((string::npos != tmps.find('3')) &&
           (string::npos != tmps.find('5')) &&
           (string::npos != tmps.find('7')))) {
        ans++;
      }
    } else {
      return 0;
    }
    ans += f(tmps, n);
  }
  return ans;
}
int main(void) {
  int N;
  cin >> N;
  cout << f("", N) << endl;
  return 0;
}
