#include <bits/stdc++.h>
using namespace std;
long long intpow(long long N, long long P) {
  if (P == 0) return 1;
  if (P % 2 == 0) {
    long long t = intpow(N, P / 2);
    return t * t;
  }
  return N * intpow(N, P - 1);
}
long long gcd(long long n, long long m) {
  n = max(n, m);
  m = min(n, m);
  if (n % m == 0) return m;
  return gcd(m, n % m);
}
long long lcm(long long n, long long m) { return n * m / gcd(n, m); }
int main() {
  int n, cnt;
  bool flag0, flag1, flag2, flag3;
  cnt = 0;
  cin >> n;
  vector<int> v;
  for (int i = 1; i < 10000000; i++) {
    int target = i;
    while (target > 0) {
      v.push_back(target % 4);
      target = target / 4;
    }
    long long sum = 0;
    flag3 = flag1 = flag2 = 0;
    flag0 = 1;
    for (int j = 0; j < v.size(); j++) {
      if (v[j] == 0) flag0 = 0;
      if (v[j] == 1) {
        sum += 3 * intpow(10, j);
        flag1 = 1;
      }
      if (v[j] == 2) {
        sum += 5 * intpow(10, j);
        flag2 = 1;
      }
      if (v[j] == 3) {
        sum += 7 * intpow(10, j);
        flag3 = 1;
      }
    }
    if (sum > n) break;
    if (flag0 && flag1 && flag2 && flag3) {
      cout << sum << endl;
      cnt++;
    }
    v.clear();
  }
  cout << cnt << endl;
}
