#include <bits/stdc++.h>
using namespace std;
int N;
int n = 0;
void keisan(int x, int a, int b, int c) {
  if (x > N) return;
  if (a && b && c) n++;
  keisan(x * 10 + 3, 1, b, c);
  keisan(x * 10 + 5, a, 1, c);
  keisan(x * 10 + 7, a, b, 1);
}
int main() {
  cin >> N;
  keisan(0, 0, 0, 0);
  cout << n << endl;
}
