#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
long long mod = 1000000007;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
void chmin(long long &a, long long b) {
  if (a > b) a = b;
}
const long long INF = 1LL << 60;
int ans = 0, n;
void dfs(int x, bool f3, bool f5, bool f7) {
  if (x > n) return;
  if (f3 && f5 && f7) ans++;
  dfs(10 * x + 3, true, f5, f7);
  dfs(10 * x + 5, f3, true, f7);
  dfs(10 * x + 7, f3, f5, true);
}
int main() {
  cin >> n;
  dfs(0, 0, 0, 0);
  cout << ans << endl;
  return 0;
}
