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