#include <bits/stdc++.h>
using namespace std;
int main() {
  long int N;
  cin >> N;
  vector<int> a = {3, 5, 7};
  vector<int> b = {1};
  for (int i = 0; i < 26500; ++i) {
    if ((a.at(i) * 10 + 3) <= N)
      a.push_back(a.at(i) * 10 + 3);
    else if ((a.at(i) * 10 + 5) <= N)
      a.push_back(a.at(i) * 10 + 5);
    else if ((a.at(i) * 10 + 7) <= N)
      a.push_back(a.at(i) * 10 + 7);
    else
      break;
  }
  for (int i = 0; i < a.size(); ++i) {
    int X = 0;
    int Y = 0;
    int Z = 0;
    if (a.at(i) % 10 == 3) X += 1;
    if (a.at(i) % 10 == 5) Y += 1;
    if (a.at(i) % 10 == 7) Z += 1;
    if (a.at(i) % 100 / 10 == 3) X += 1;
    if (a.at(i) % 100 / 10 == 5) Y += 1;
    if (a.at(i) % 100 / 10 == 7) Z += 1;
    if (a.at(i) % 1000 / 100 == 3) X += 1;
    if (a.at(i) % 1000 / 100 == 5) Y += 1;
    if (a.at(i) % 1000 / 100 == 7) Z += 1;
    if (a.at(i) % 10000 / 1000 == 3) X += 1;
    if (a.at(i) % 10000 / 1000 == 5) Y += 1;
    if (a.at(i) % 10000 / 1000 == 7) Z += 1;
    if (a.at(i) % 100000 / 10000 == 3) X += 1;
    if (a.at(i) % 100000 / 10000 == 5) Y += 1;
    if (a.at(i) % 100000 / 10000 == 7) Z += 1;
    if (a.at(i) % 1000000 / 100000 == 3) X += 1;
    if (a.at(i) % 1000000 / 100000 == 5) Y += 1;
    if (a.at(i) % 1000000 / 100000 == 7) Z += 1;
    if (a.at(i) % 10000000 / 1000000 == 3) X += 1;
    if (a.at(i) % 10000000 / 1000000 == 5) Y += 1;
    if (a.at(i) % 10000000 / 1000000 == 7) Z += 1;
    if (a.at(i) % 100000000 / 10000000 == 3) X += 1;
    if (a.at(i) % 100000000 / 10000000 == 5) Y += 1;
    if (a.at(i) % 100000000 / 10000000 == 7) Z += 1;
    if (X >= 1 && Y >= 1 && Z >= 1) b.push_back(a.at(i));
  }
  cout << b.size() - 1 << endl;
}
