#include <bits/stdc++.h>
using namespace std;
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, a;
  int tmp;
  int flag3, flag5, flag7;
  for (list<long long>::iterator 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);
    a = *itr;
    flag3 = 0;
    flag5 = 0;
    flag7 = 0;
    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 == 1) cnt++;
  }
  cout << cnt << endl;
  return 0;
}
