#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ans = 0;
  if (N < 357) {
    cout << 0 << endl;
  } else {
    if (N > 777777753) N = 777777753;
    for (int i = 357; i < N + 1; i++) {
      string num = to_string(i);
      if (num[0] != '3' and num[0] != '5' and num[0] != '7') {
        i += pow(10, num.length() - 1);
        i = i / pow(10, num.length() - 1) * pow(10, num.length() - 1);
      }
      bool isSeven = false;
      bool isFive = false;
      bool isThree = false;
      bool other = false;
      for (auto n : num) {
        int tmp = n - '0';
        if (tmp == 3)
          isThree = true;
        else if (tmp == 5)
          isFive = true;
        else if (tmp == 7)
          isSeven = true;
        else
          other = true;
        if (other) {
          break;
        }
      }
      if (other)
        continue;
      else {
        if (isThree and isFive and isSeven) {
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
