#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
bool nagomi(int n) {
  bool flag = false;
  bool flag3 = false;
  bool flag5 = false;
  bool flag7 = false;
  while (n != 0) {
    if (n % 10 == 3)
      flag3 = true;
    else if (n % 10 == 5)
      flag5 = true;
    else if (n % 10 == 7)
      flag7 = true;
    n /= 10;
    if ((flag3 && flag5) && flag7) {
      flag = true;
      break;
    }
  }
  if (flag)
    return true;
  else
    return false;
}
int main() {
  int n;
  cin >> n;
  queue<int> cho;
  for (int i = 3; i <= 7; i += 2) {
    cho.push(i);
  }
  int num = 3;
  int count = 0;
  while (num < n) {
    num = cho.front();
    cho.pop();
    for (int i = 3; i <= 7; i += 2) {
      int b = num * 10 + i;
      cho.push(b);
    }
    if (nagomi(num)) count++;
  }
  cout << (count) << endl;
  return 0;
}
