#include <bits/stdc++.h>
using namespace std;
int main() {
  string N;
  cin >> N;
  vector<int> a(10), b(10), c(10), d(10);
  a[0] = 1;
  b[0] = 1;
  for (int i = 1; i < 10; i++) {
    a[i] = a[i - 1] * 3;
    b[i] = b[i - 1] * 2;
  }
  for (int i = 3; i < 10; i++) {
    c[i] = a[i] - b[i] * 3 + 3;
  }
  d[2] = 0;
  for (int i = 3; i < 10; i++) {
    d[i] = d[i - 1] + c[i];
  }
  int ans = 0;
  int n = N.size();
  if (n < 3) {
    cout << 0 << endl;
  } else {
    ans += d[n - 1];
    if (N[0] >= 8) {
      cout << d[n] << endl;
    } else if (N[0] <= 2) {
      cout << d[n - 1] << endl;
    } else if (N[0] == 4) {
      cout << d[n - 1] + d[n] / 3 << endl;
    } else if (N[0] == 6) {
      cout << d[n - 1] + d[n] / 3 * 2 << endl;
    }
  }
}
