#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const double pi = 3.141592653589793238462643382795028841971;
int dig[7] = {6, 36, 192, 732, 2538, 8334, 26484};
int digits(long long n) {
  int ans = 0;
  while (n) {
    ans++;
    n /= 10;
  }
  return ans;
}
int main() {
  long long n, ans = 0, mon;
  cin >> n;
  if (n <= 753) {
  } else {
    mon = digits(n);
    ans = dig[mon - 4];
    for (long long i = 3 * pow(10, mon - 1) + 1; i <= n; i += 2) {
      long long nn = i;
      bool m = true, t = false, s = false, fi = false;
      while (nn) {
        int monn = nn % 10;
        if (monn != 3 && monn != 7 && monn != 5) {
          m = false;
          break;
        } else {
          if (monn == 3)
            t = true;
          else if (monn == 5)
            fi = true;
          else if (monn == 7)
            s = true;
        }
        nn /= 10;
      }
      if (m && s && fi && t) ++ans;
    }
  }
  cout << ans << endl;
}
