#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lli = long long int;
ll MM = 1000000000;
ll mod = MM + 7;
ll n;
ll ans = 0;
void dfs(ll x, int a, int b, int c) {
  if (x > n) return;
  if (a == 1 && b == 1 && c == 1) ans++;
  dfs(10 * x + 3, 1, b, c);
  dfs(10 * x + 5, a, 1, c);
  dfs(10 * x + 7, a, b, 1);
}
int main() {
  scanf("%lld", &n);
  dfs(0, 0, 0, 0);
  printf("lld\n", ans);
  return 0;
}
