#include <bits/stdc++.h>
using namespace std;
long long update(long long t) {
  char s[10], cnt = 0;
  while (t) {
    s[cnt++] = t % 10 + '0';
    t /= 10;
  }
  if (s[0] == '3')
    s[0] = '5';
  else if (s[0] == '5')
    s[0] = '7';
  else {
    bool flag = true;
    for (int i = 1; i < cnt; i++) {
      if (s[i] != '7') {
        for (int j = 0; j < i; j++) s[j] = '3';
        if (s[i] == '3')
          s[i] = '5';
        else
          s[i] = '7';
        flag = false;
        break;
      }
    }
    if (flag) {
      for (int i = 0; i < cnt; i++) s[i] = '3';
      s[cnt++] = '3';
    }
  }
  t = 0;
  for (int i = cnt - 1; i >= 0; i--) t = t * 10 + s[i] - '0';
  return t;
}
bool check(long long t) {
  bool f1 = false, f2 = false, f3 = false;
  while (t) {
    long long p = t % 10;
    if (p == 3)
      f1 = true;
    else if (p == 5)
      f2 = true;
    else
      f3 = true;
    t /= 10;
  }
  return f1 && f2 && f3;
}
int main() {
  long long n;
  scanf("%lld", &n);
  long long ans = 0, tmp = 333;
  while (tmp <= n) {
    tmp = update(tmp);
    if (check(tmp)) ans++;
  }
  printf("%lld\n", ans);
}
