#include <bits/stdc++.h>
using namespace std;
bool check(int n);
int main(void) {
  int n, count = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (check(i)) {
      count++;
    }
  }
  cout << count << endl;
}
bool check(int n) {
  string s = to_string(n);
  bool flag = false;
  bool flag1 = false, flag2 = false, flag3 = false;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] != '3' && s[i] != '5' && s[i] != '7') {
      return false;
    }
    if (s[i] == '3') flag1 = true;
    if (s[i] == '5') flag2 = true;
    if (s[i] == '7') flag3 = true;
  }
  if (flag1 && flag2 && flag3)
    return true;
  else
    return false;
}
