#include <bits/stdc++.h>
using namespace std;
vector<long long> buf;
long long ctoi(const char c) {
  switch (c) {
    case '0':
      return 0;
    case '1':
      return 1;
    case '2':
      return 2;
    case '3':
      return 3;
    case '4':
      return 4;
    case '5':
      return 5;
    case '6':
      return 6;
    case '7':
      return 7;
    case '8':
      return 8;
    case '9':
      return 9;
    default:
      return -1;
  }
}
long long calc(long long n) {
  if (n < 3) {
    return 0;
  }
  if (n >= 3) {
    return n * (n - 1) * (n - 2) * pow(3, n - 3);
  }
}
void dfs(long long i, const long long size, const long long range_start,
         const long long range_end, long long &cnt, long long N) {
  if (i == size) {
    long long tmp = 0;
    for (long long i = 0; i < buf.size(); ++i) {
      tmp += buf[i] * pow(10, buf.size() - 1 - i);
    }
    if (tmp < N) {
      string s = to_string(tmp);
      long long cnt3 = 0;
      long long cnt5 = 0;
      long long cnt7 = 0;
      bool flg = true;
      for (long long j = 0; j < (long long)s.size(); j++) {
        if (s[j] == '3')
          cnt3++;
        else if (s[j] == '5')
          cnt5++;
        else if (s[j] == '7')
          cnt7++;
      }
      if (cnt3 > 0 && cnt5 > 0 && cnt7 > 0) {
        cnt++;
      }
    }
  } else {
    for (long long j = range_start; j <= range_end; ++j) {
      if (j == 1) buf[i] = 3;
      if (j == 2) buf[i] = 5;
      if (j == 3) buf[i] = 7;
      dfs(i + 1, size, range_start, range_end, cnt, N);
    }
  }
}
int main() {
  long long N;
  cin >> N;
  long long ans = 0;
  string S = to_string(N);
  long long len = (long long)S.size();
  long long range_start = 1;
  long long range_end = 3;
  buf.resize(len);
  dfs(0, len, range_start, range_end, ans, N);
  if (len - 1 >= 3) ans += 6;
  if (len - 1 >= 4) ans += 36;
  if (len - 1 >= 5) ans += 150;
  if (len - 1 >= 6) ans += 540;
  if (len - 1 >= 7) ans += 1806;
  if (len - 1 >= 8) ans += 5796;
  cout << ans << endl;
  return 0;
}
