#include <bits/stdc++.h>
using namespace std;
long long n, ans, nlen;
void f(long long val, long long len) {
  if (val >= n) return;
  if (len == nlen) {
    long long a3, a5, a7;
    a3 = a5 = a7 = 0;
    long long t = val, i = 0;
    while (t) {
      long long tt = t % 10;
      if (tt == 3)
        a3++;
      else if (tt == 5)
        a5++;
      else if (tt == 7)
        a7++;
      t /= 10;
    }
    if (a3 == 0 or a5 == 0 or a7 == 0)
      return;
    else {
      ans++;
    }
    return;
  }
  f(val * 10 + 3, len + 1);
  f(val * 10 + 5, len + 1);
  f(val * 10 + 7, len + 1);
}
long long numLen(long long v) {
  int t = 0;
  while (v) {
    t++;
    v /= 10;
  }
  return t;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  nlen = numLen(n);
  for (long long i = nlen; i >= 3; i--) {
    f(0, 0);
    long long vt = 0;
    for (long long j = 0; j < nlen - 1; j++) {
      vt = vt * 10 + 9;
    }
    n = vt;
    nlen--;
  }
  cout << ans << '\n';
  return 0;
}
