#include <bits/stdc++.h>
using namespace std;
int GetOrder(int number);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int number;
  cin >> number;
  int order = GetOrder(number);
  int d[4][order + 1];
  d[0][0] = 1;
  d[1][0] = 0;
  d[2][0] = 0;
  d[3][0] = 0;
  d[0][1] = 3;
  d[1][1] = 1;
  d[2][1] = 0;
  d[3][1] = 0;
  for (int i = 2; i < order + 1; ++i) {
    d[0][i] = 3 * d[0][i - 1];
    d[1][i] = d[0][i - 1] + 2 * d[1][i - 1];
    d[2][i] = 2 * d[1][i - 1] + d[2][i - 1];
    d[3][i] = 3 * d[2][i - 1];
  }
  int digits[order];
  for (int i = order - 1; i >= 0; --i) {
    digits[i] = number % 10;
    number /= 10;
  }
  set<int> remainings;
  remainings.insert(3);
  remainings.insert(5);
  remainings.insert(7);
  int res = 0;
  for (int i = 0; i < order; ++i) res += d[3][i];
  for (int i = 0; i < order; ++i) {
    int length = order - i - 1;
    if (digits[i] == 3) {
      if (remainings.find(3) != remainings.end()) remainings.erase(3);
    } else if (digits[i] == 5) {
      int size = remainings.size();
      if (remainings.find(3) != remainings.end())
        res += d[size - 1][length];
      else
        res += d[size][length];
      if (remainings.find(5) != remainings.end()) remainings.erase(5);
    } else if (digits[i] == 7) {
      int size = remainings.size();
      if (remainings.find(3) != remainings.end())
        res += d[size - 1][length];
      else
        res += d[size][length];
      if (remainings.find(5) != remainings.end())
        res += d[size - 1][length];
      else
        res += d[size][length];
      if (remainings.find(7) != remainings.end()) remainings.erase(7);
    } else {
      int size = remainings.size();
      if (digits[i] < 3) {
        ;
      } else if (digits[i] < 5) {
        if (remainings.find(3) != remainings.end())
          res += d[size - 1][length];
        else
          res += d[size][length];
      } else if (digits[i] < 7) {
        if (remainings.find(3) != remainings.end())
          res += d[size - 1][length];
        else
          res += d[size][length];
        if (remainings.find(5) != remainings.end())
          res += d[size - 1][length];
        else
          res += d[size][length];
      } else {
        if (remainings.find(3) != remainings.end())
          res += d[size - 1][length];
        else
          res += d[size][length];
        if (remainings.find(5) != remainings.end())
          res += d[size - 1][length];
        else
          res += d[size][length];
        if (remainings.find(7) != remainings.end())
          res += d[size - 1][length];
        else
          res += d[size][length];
      }
      break;
    }
  }
  cout << res << "\n";
  return 0;
}
int GetOrder(int number) {
  int count = 0;
  while (number > 0) {
    number /= 10;
    ++count;
  }
  return count;
}
