#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n;
  cin >> n;
  int count = 0;
  if (n < 357) {
    cout << 0 << endl;
    return 0;
  } else {
    long int p;
    if (n >= 777777753) {
      cout << 26484 << endl;
      return 0;
    }
    if (n > 555555555) {
      n = 777777753;
      p = 555555555;
      count = 17408;
    } else {
      p = 357;
    }
    for (long int i = p; i <= n; i++) {
      int num = i;
      int flag_3 = 0;
      int flag_5 = 0;
      int flag_7 = 0;
      int flag_other = 0;
      while (num > 0) {
        int flag = num % 10;
        if (flag == 3) {
          flag_3++;
        } else if (flag == 5) {
          flag_5++;
        } else if (flag == 7) {
          flag_7++;
        } else {
          flag_other++;
          break;
        }
        num = num / 10;
      }
      if (flag_3 > 0 && flag_5 > 0 && flag_7 > 0 && flag_other == 0) {
        count++;
      }
    }
  }
  cout << count << endl;
}
