#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
ll ans = 0;
ll n;
void func(bool a, bool b, bool c, string now) {
  if (now != "" && atoi(now.c_str()) > n) return;
  if (a && b && c && atoi(now.c_str()) <= n) ans++;
  func(true, b, c, '3' + now);
  func(a, true, c, '5' + now);
  func(a, b, true, '7' + now);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  func(false, false, false, "");
  cout << ans << endl;
  return 0;
}
