#include <bits/stdc++.h>
using namespace std;
int f(int n, int N, bool b3, bool b5, bool b7) {
  if (n == 0) {
    return f(n * 10 + 3, N, true, b5, b7) + f(n * 10 + 5, N, b3, true, b7) +
           f(n * 10 + 7, N, b3, b5, true);
  }
  if (n <= N) {
    if (b3 && b5 && b7) {
      return 1 + f(n * 10 + 3, N, true, b5, b7) +
             f(n * 10 + 5, N, b3, true, b7) + f(n * 10 + 7, N, b3, b5, true);
    } else
      return f(n * 10 + 3, N, true, b5, b7) + f(n * 10 + 5, N, b3, true, b7) +
             f(n * 10 + 7, N, b3, b5, true);
  }
  return 0;
}
int main() {
  int N;
  cin >> N;
  cout << f(0, N, 0, 0, 0) << endl;
  return 0;
}
