#include <bits/stdc++.h>
using namespace std;
long long n;
int ans = 0;
int dfs(long long cnt, int san, int go, int nana) {
  if (n < cnt) {
    return 0;
  } else {
    if (san > 0 && go > 0 && nana > 0) {
      ans++;
    }
  }
  dfs(10 * n + 3, 1, go, nana);
  dfs(10 * n + 5, san, 1, nana);
  dfs(10 * n + 7, san, go, 1);
  return 0;
}
int main() {
  cin >> n;
  dfs(0, 0, 0, 0);
  cout << ans << endl;
  return 0;
}
