#include <bits/stdc++.h>
using namespace std;
int f(int x) {
  if (x < 3)
    return 0;
  else if (x < 5)
    return 1;
  else if (x < 7)
    return 2;
  else
    return 3;
}
int g(int cnt) {
  int x = 0;
  for (int i = 3; i <= cnt; ++i) {
    x += pow(3, i) - pow(2, i) + 3;
  }
  return x;
}
int main() {
  int n;
  cin >> n;
  if (n < 357) {
    cout << 0 << endl;
    return 0;
  }
  int cnt = 0;
  int a = 1;
  while (n / 10) {
    int tmp = n % 10;
    n /= 10;
    cnt++;
    tmp = f(tmp);
    a *= tmp;
  }
  a *= f(n);
  int ans = g(cnt) + a;
  cout << ans << endl;
  return 0;
}
