#include <bits/stdc++.h>
using namespace std;
int ndig(int i) { return pow(3, i) - pow(2, i) * 3 + 3; }
bool check(int i) {
  string str = to_string(i);
  if (str.find("0") == string::npos && str.find("1") == string::npos &&
      str.find("2") == string::npos && str.find("3") != string::npos &&
      str.find("4") == string::npos && str.find("5") != string::npos &&
      str.find("6") == string::npos && str.find("7") != string::npos &&
      str.find("8") == string::npos && str.find("9") == string::npos) {
    return true;
  } else {
    return false;
  }
}
int main() {
  int N;
  cin >> N;
  string str = to_string(N);
  int count = 0;
  if (str.size() <= 2) {
    cout << 0 << endl;
    return 0;
  }
  string three = "", seven = "";
  for (int i = 1; i < str.size(); i++) {
    count += ndig(i);
    three += '3';
    seven += '7';
  }
  switch (str[0]) {
    case '3':
      for (int i = 3 * pow(10, str.size() - 1) + stoi(three) - 2;
           i <= min(N, (int)(3 * pow(10, str.size() - 1) + stoi(seven)));
           i += ((i % 10000000 > 7777777) ? 5000000 : 2)) {
        if (check(i) == true) count++;
      }
      break;
    case '4':
      count += ndig(str.size()) / 3;
      break;
    case '5':
      count += ndig(str.size()) / 3;
      for (int i = 5 * pow(10, str.size() - 1) + stoi(three) - 2;
           i <= min(N, (int)(5 * pow(10, str.size() - 1) + stoi(seven)));
           i += ((i % 10000000 > 7777777) ? 5000000 : 2)) {
        if (check(i) == true) count++;
      }
      break;
    case '6':
      count += ndig(str.size()) / 3 * 2;
      break;
    case '7':
      count += ndig(str.size()) / 3 * 2;
      for (int i = 7 * pow(10, str.size() - 1) + stoi(three) - 2;
           i <= min(N, (int)(7 * pow(10, str.size() - 1) + stoi(seven)));
           i += ((i % 10000000 > 7777777) ? 5000000 : 2)) {
        if (check(i) == true) count++;
      }
      break;
    case '8':
      count += ndig(str.size());
      break;
    case '9':
      count += ndig(str.size());
      break;
  }
  cout << count << endl;
}
