#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, count = 0;
  cin >> n;
  int i = 357;
  while (i <= n) {
    int j = i, flag = 0, a = 0, b = 0, c = 0;
    while (j > 0 && flag == 0) {
      if (j % 10 == 3)
        a = 1;
      else if (j % 10 == 5)
        b = 1;
      else if (j % 10 == 7)
        c = 1;
      else
        flag++;
      j /= 10;
    }
    if (a + b + c == 3 && flag == 0) count++;
    if (i % 10 == 3)
      i += 2;
    else if (i % 10 == 5)
      i += 2;
    else if (i % 10 == 7)
      i += 6;
  }
  cout << count << endl;
}
