#include <bits/stdc++.h>
using namespace std;
void process(unsigned long long N, int use[3], int finish,
             unsigned long long *ans, unsigned long long number, int pos);
int main() {
  unsigned long long N;
  unsigned long long temp;
  int use[3] = {0, 0, 0};
  int count;
  unsigned long long ans = 0;
  cin >> N;
  temp = N;
  count = 0;
  while (temp > 0) {
    count++;
    temp /= 10;
  }
  process(N, use, count, &ans, 0, 0);
  cout << ans << endl;
}
void process(unsigned long long N, int use[3], int finish,
             unsigned long long *ans, unsigned long long number, int pos) {
  int i;
  if (use[0] > 0 && use[1] > 0 && use[2] > 0 && number < N) {
    *ans += 1;
  }
  if (pos > finish) {
    return;
  }
  for (i = 0; i < 3; i++) {
    use[i]++;
    process(N, use, finish, ans, number * 10 + (i + 1) * 2 + 1, pos + 1);
    use[i]--;
  }
}
