#include <bits/stdc++.h>
using namespace std;
int res, n;
void dfs(long long now, int msk){
  if(now > n) return;
  if(msk == 7) res++;
  dfs(now*10 + 3, msk|1);
  dfs(now*10 + 5, msk|2);
  dfs(now*10 + 7, msk|4);
}
int main(){
  cin >> n;
  dfs(0, 0);
  cout << res << endl;
  return 0;
}
