#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  long long tmp = n, d = 0;
  vector<long long> tp;
  while (tmp) {
    d++;
    tp.push_back(tmp % 10);
    tmp /= 10;
  }
  reverse(tp.begin(), tp.end());
  long long r3[10], r2[10], cnt[10];
  r3[0] = 1, r2[0] = 1;
  for (int i = 0; i < 9; i++) {
    r3[i + 1] = r3[i] * 3;
    r2[i + 1] = r2[i] * 2;
  }
  long long s[10];
  s[0] = 0;
  for (int i = 0; i < 9; i++) {
    cnt[i + 1] = r3[i + 1] - 3 * r2[i + 1] + 3;
    s[i + 1] = s[i] + cnt[i + 1];
  }
  if (n <= 300) {
    cout << 0 << endl;
    return 0;
  }
  if (tp[0] >= 8) {
    cout << s[d] << endl;
    return 0;
  }
  if (tp[0] == 6) {
    long long ans = 2 * (r3[d - 1] - 3 * r2[d - 1] + 4) + s[d - 1];
    cout << ans << endl;
    return 0;
  }
  if (tp[0] == 4) {
    long long ans = r3[d - 1] - 2 * r2[d - 1] + 3 + s[d - 1];
    cout << ans << endl;
    return 0;
  }
  if (tp[0] <= 2) {
    cout << s[d - 1] << endl;
    return 0;
  }
  if (tp[0] == 7 || tp[0] == 5 || tp[0] == 3) {
    long long ans = s[d - 1], cn = 1, u3 = 3, u5 = 5, u7 = 7;
    for (int i = 0; i < d - 1; i++) {
      cn *= 10;
      u3 += cn * 3;
      u5 += cn * 5;
      u7 += cn * 7;
    }
    if (u3 + 1 < n) {
      cout << ans << endl;
      return 0;
    }
    for (long long i = u3 + 1; i <= n; i++) {
      long long ttt = i;
      if (ttt == u5) continue;
      while (ttt) {
        if (ttt % 10 != 7 || ttt % 10 != 5 || ttt % 10 != 3) break;
        ttt /= 10;
      }
      if (ttt == 0) ans++;
    }
    cout << ans << endl;
    return 0;
  }
}
