#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
void Main() {
  int n;
  cin >> n;
  priority_queue<int, vector<int>, greater<int>> q;
  q.push(357);
  q.push(375);
  q.push(537);
  q.push(573);
  q.push(735);
  q.push(753);
  ll ans = 0;
  int y = 0;
  while (1) {
    int x = q.top();
    q.pop();
    if (x > n) break;
    if (y == x) continue;
    ans++;
    int ten = 1;
    while (x / ten) ten *= 10;
    q.push(x * 10 + 3);
    q.push(x * 10 + 5);
    q.push(x * 10 + 7);
    q.push(x + 3 * ten);
    q.push(x + 5 * ten);
    q.push(x + 7 * ten);
    cerr << "x"
         << ": " << x << endl;
    int y = x;
  }
  cout << ans << endl;
}
int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
