#include <bits/stdc++.h>
using namespace std;
long N;
long ret;
int dfs(long x, int mask) {
  if (x > N) return 0;
  if (mask == 7) ret++;
  dfs(x * 10 + 3, mask | 1);
  dfs(x * 10 + 5, mask | 2);
  dfs(x * 10 + 7, mask | 4);
}
int main() {
  cin >> N;
  ret = 0;
  dfs(0, 0);
  cout << ret << "¥n";
  return 0;
}
