#include <bits/stdc++.h>
using namespace std;
int main(void) {
  unsigned int N, ans = 0;
  cin >> N;
  unsigned int i = 357;
  int j = 2;
  while (i < N) {
    bool isS = false, isF = false, isT = false;
    bool _isS = false, _isF = false, _isT = false;
    string str;
    str = to_string(i);
    for (auto c : str) {
      _isS = false;
      _isF = false;
      _isT = false;
      switch (c) {
        case '7':
          _isS = true;
          isS = true;
          break;
        case '5':
          _isF = true;
          isF = true;
          break;
        case '3':
          _isT = true;
          isT = true;
          break;
      }
      if (!(_isS || _isF || _isT)) break;
    }
    if ((isS && isF && isT) && (_isS || _isF || _isT)) {
      ++ans;
    }
    if (++j == 3) {
      j = 0;
      i += 6;
    } else {
      i += 2;
    }
  }
  cout << ans << endl;
  return 0;
}
