#include <bits/stdc++.h>
using namespace std;
long long N;
long long _case[10] = {0, 0, 0, 6, 36, 150, 540, 1806, 5796, 18150};
long long presum = 0;
int num3 = 0;
int num5 = 0;
int num7 = 0;
void cal(int n, long long val) {
  if (n == -1) {
    if (num3 == 0 || num5 == 0 || num7 == 0) {
      return;
    } else {
      if (val < N) presum++;
    }
    return;
  }
  val += 3 * pow(10, n);
  num3++;
  cal(n - 1, val);
  num3--;
  num5++;
  val += 2 * pow(10, n);
  cal(n - 1, val);
  num5--;
  num7++;
  val += 2 * pow(10, n);
  cal(n - 1, val);
  num7--;
  return;
}
void solve() {
  long long ans = 0;
  int num = floor(log10(N) + 1);
  for (int i = 0; i < num + 1; i++) {
    cal(i - 1, 0);
  }
  cout << ans + presum;
  return;
}
int main() {
  cin >> N;
  solve();
  cout << endl;
  return 0;
}
