#include <bits/stdc++.h>
using namespace std;
int dfs(int s, int N) {
  int ret;
  if (s > N) {
    return 0;
  }
  bool flg3 = false;
  bool flg5 = false;
  bool flg7 = false;
  while (s > 0) {
    int digit = s % 10;
    s /= 10;
    if (digit == 3)
      flg3 = true;
    else if (digit == 5)
      flg5 = true;
    else if (digit == 7)
      flg7 = true;
  }
  if (flg3 && flg5 && flg7)
    ret = 1;
  else
    ret = 0;
  if (s <= N) {
    ret += dfs(10 * s + 3, N);
    ret += dfs(10 * s + 5, N);
    ret += dfs(10 * s + 7, N);
  }
  return ret;
}
int main() {
  int N, ans;
  cin >> N;
  ans = dfs(0, N);
  cout << ans << endl;
  return 0;
}
