#include <bits/stdc++.h>
using namespace std;
long long judge753(long long a) {
  bool flag3 = 0;
  bool flag5 = 0;
  bool flag7 = 0;
  int tmp;
  while (a > 0) {
    tmp = a % 10;
    if (tmp == 3) flag3 = 1;
    if (tmp == 5) flag5 = 1;
    if (tmp == 7) flag7 = 1;
    a = a / 10;
  }
  if (flag3 * flag5 * flag7) {
    return 1;
  } else {
    return 0;
  }
}
int main() {
  long long N;
  cin >> N;
  list<long long> v;
  v.push_back(3);
  v.push_back(5);
  v.push_back(7);
  long long cnt;
  for (auto itr = v.begin(); itr != v.end(); ++itr) {
    if (*itr * 10 + 3 <= N) v.push_back(*itr * 10 + 3);
    if (*itr * 10 + 5 <= N) v.push_back(*itr * 10 + 5);
    if (*itr * 10 + 7 <= N) v.push_back(*itr * 10 + 7);
    cnt += judge753(*itr);
  }
  cout << cnt;
}
