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