#include <bits/stdc++.h>
using namespace std;
int ans = 0;
void dfs(long long now, long long end) {
  bool check3 = false, check5 = false, check7 = false;
  cout << "今見る数字は" << now << endl;
  int num = now;
  if (now > end) {
    cout << end << "以上だね。ここで再帰終了" << endl;
    return;
  }
  while (num) {
    if (num % 10 == 3) {
      cout << num << "から3を検知" << endl;
      check3 = true;
    }
    if (num % 10 == 5) {
      cout << num << "から5を検知" << endl;
      check5 = true;
    }
    if (num % 10 == 7) {
      cout << num << "から7を検知" << endl;
      check7 = true;
    }
    num = num / 10;
    if (check3 == true && check5 == true && check7 == true) {
      cout << "七五三数だね" << endl;
      ++ans;
      break;
    }
  }
  dfs((10 * now) + 3, end);
  dfs((10 * now) + 5, end);
  dfs((10 * now) + 7, end);
  return;
}
int main() {
  long long N;
  ans = 0;
  cin >> N;
  dfs(0, N);
  cout << ans << endl;
}
