#include <bits/stdc++.h>
using namespace std;
int n;
int ans = 0, three, five, seven;
void solve(int a) {
  if (a > n) return;
  three = 0, five = 0, seven = 0;
  while (a > 0) {
    if (a % 10 == 3)
      three++;
    else if (a % 10 == 5)
      five++;
    else if (a % 10 == 7)
      seven++;
    a /= 10;
  }
  if (three && five && seven) ans++;
  solve(a * 10 + 3);
  solve(a * 10 + 5);
  solve(a * 10 + 7);
}
int main() {
  cin >> n;
  solve(0);
  cout << ans << endl;
}
