#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n < 357) {
    puts("0");
    return 0;
  }
  int ans = 0;
  for (int i = 357; i <= n; i += 2) {
    int temp = i;
    bool while_flag = true;
    bool count3 = false;
    bool count5 = false;
    bool count7 = false;
    while (temp && while_flag) {
      switch (temp % 10) {
        case 3:
          count3 = true;
          break;
        case 5:
          count5 = true;
          break;
        case 7:
          count7 = true;
          break;
        default:
          while_flag = false;
          break;
      }
      temp /= 10;
    }
    if (while_flag && count3 && count5 && count7) {
      ans++;
    }
    if (i % 10 == 7) {
      i += 4;
    }
  }
  cout << ans << endl;
  return 0;
}
