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