#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int, int>, 4> fd{make_pair(1, 0), make_pair(-1, 0),
                                  make_pair(0, 1), make_pair(0, -1)};
int main() {
  int n;
  cin >> n;
  int tans = 0;
  string ns = to_string(n);
  int keta = ns.length();
  int a = INF;
  for (int i = (3); i < (keta); i++) {
    if (a == INF) a = 1;
    a = a * pow(3, i) - 3 * pow(2, i) + i;
  }
  for (int i = (0); i < (keta); i++) {
    int head = stoi(ns.substr(i, 1));
    int headb;
    if (head < 3) {
      headb = 3;
    } else if (head < 5) {
      headb = 2;
    } else if (head < 7) {
      headb = 1;
    } else {
      headb = 0;
    }
    headb *= pow(3, keta - i - 1);
    tans += headb;
    if (head != 7 && head != 5 && head != 3) break;
  }
  int bb = pow(3, keta - 3);
  for (int i = (2); i < (keta + 1); i++) bb *= i;
  tans = bb - tans;
  int toans = 0;
  for (int i = (0); i < (keta); i++) {
    int head = stoi(ns.substr(i, 1));
    int headb;
    if (head < 5) {
      headb = 2;
    } else if (head < 7) {
      headb = 1;
    } else {
      headb = 0;
    }
    headb *= pow(2, keta - i - 1);
    toans += headb;
    if (head != 7 && head != 5) break;
  }
  tans += toans;
  toans = 0;
  for (int i = (0); i < (keta); i++) {
    int head = stoi(ns.substr(i, 1));
    int headb;
    if (head < 3) {
      headb = 2;
    } else if (head < 7) {
      headb = 1;
    } else {
      headb = 0;
    }
    headb *= pow(2, keta - i - 1);
    toans += headb;
    if (head != 7 && head != 3) break;
  }
  tans += toans;
  toans = 0;
  for (int i = (0); i < (keta); i++) {
    int head = stoi(ns.substr(i, 1));
    int headb;
    if (head < 3) {
      headb = 2;
    } else if (head < 5) {
      headb = 1;
    } else {
      headb = 0;
    }
    headb *= pow(2, keta - i - 1);
    toans += headb;
    if (head != 5 && head != 3) break;
  }
  tans += toans;
  if (a != INF) tans += a;
  cout << tans << endl;
}
