#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
long long dfs(long long a, long long n, bool flag1, bool flag2, bool flag3,
              long long count);
signed main() {
  long long n;
  cin >> n;
  long long ans = 0;
  dfs(0, n, false, false, false, ans);
  cout << ans << endl;
}
long long dfs(long long a, long long n, bool flag1, bool flag2, bool flag3,
              long long count) {
  if (a > n) return 0;
  if (a % 10 == 3) flag1 = true;
  if (a % 10 == 5) flag2 = true;
  if (a % 10 == 7) flag3 = true;
  if (flag1 && flag2 && flag3) count++;
  count = dfs(a * 10 + 3, n, flag1, flag2, flag3, count);
  count = dfs(a * 10 + 5, n, flag1, flag2, flag3, count);
  count = dfs(a * 10 + 7, n, flag1, flag2, flag3, count);
  return count;
}
