#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  long long int n, ans = 0, ans3 = 0, ans5 = 0, ans7 = 0, a, b, c, d;
  cin >> n;
  a = n;
  c = a;
  for (long long int i = 0; i < n; i++) {
    if (c < 357) break;
    a = c;
    while (a >= 1) {
      b = a % 10;
      a /= 10;
      if (b == 3) {
        ans3 += 1;
      }
      if (b == 5) {
        ans5 += 1;
      }
      if (b == 7) {
        ans7 += 1;
      }
      if (b != 3 && b != 5 && b != 7) {
        d = 1;
      }
    }
    if (ans3 > 0 && ans5 > 0 && ans7 > 0 && d == 0) {
      ans += 1;
    }
    ans3 -= ans3;
    ans5 -= ans5;
    ans7 -= ans7;
    c -= 1;
    d -= d;
  }
  cout << ans << "\n";
  return 0;
}
