#include <bits/stdc++.h>
using namespace std;
int N;
int ans = 0;
void calc_357(int x, int a, int b, int c) {
  if (x > N) return;
  if (a && b && c) ans++;
  calc_357(x * 10 + 3, 1, b, c);
  calc_357(x * 10 + 5, a, 1, c);
  calc_357(x * 10 + 7, a, b, 1);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  calc_357(0, 0, 0, 0);
  cout << ans << endl;
  return 0;
}
