#include <bits/stdc++.h>
using namespace std;
int n, ans;
void dfs(long long sum, int cnt3, int cnt5, int cnt7) {
  if (sum > n) return;
  if (cnt3 > 0 || cnt5 > 0 || cnt7 > 0) ans++;
  dfs(sum * 10 + 3, cnt3 + 1, cnt5, cnt7);
  dfs(sum * 10 + 5, cnt3, cnt5 + 1, cnt7);
  dfs(sum * 10 + 7, cnt3, cnt5, cnt7 + 1);
}
int main() {
  cin >> n;
  dfs(0, 0, 0, 0);
  cout << ans << endl;
  return 0;
}
