#include <bits/stdc++.h>
using namespace std;
long long const INF = 1LL << 60;
long long N;
void search(long long cur_val, int state, long long &cnt) {
  if (N < cur_val) return;
  if (state == 0b111) cnt++;
  search(cur_val * 10 + 7, state | 0b001, cnt);
  search(cur_val * 10 + 5, state | 0b010, cnt);
  search(cur_val * 10 + 3, state | 0b100, cnt);
}
int main() {
  cin >> N;
  long long ans = 0;
  search(0, 0, ans);
  cout << ans << endl;
  return 0;
}
