#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
bool is753(int n) {
  int tmp = n;
  int ans753[3] = {0, 0, 0};
  int mod;
  while (tmp >= 1) {
    mod = tmp % 10;
    tmp /= 10;
    if (mod == 7) ans753[0]++;
    if (mod == 5) ans753[1]++;
    if (mod == 3) ans753[2]++;
  }
  if (ans753[0] > 0 && ans753[1] > 0 && ans753[2] > 0)
    return true;
  else
    return false;
}
int solve753(int n, int limit, int is7, int is5, int is3) {
  int ans = 0;
  if (n > limit) return 0;
  ans += solve753(10 * n + 3, limit, is7, is5, 1);
  ans += solve753(10 * n + 5, limit, is7, 1, is3);
  ans += solve753(10 * n + 7, limit, 1, is5, is3);
  if (is3 && is5 && is7)
    return ans + 1;
  else
    return ans;
}
int main() {
  int n;
  cin >> n;
  cout << solve753(0, n, 0, 0, 0);
  return 0;
}
