#include<bits/stdc++.h>
using namespace std;
using lint = long long;
lint N;
lint ans = 0;

void dfs(lint c3, lint c5, lint c7, lint num){
  if(num > N) return;
  if(c3 && c5 && c7) ans++;
  dfs(1, c5, c7, 10 * num + 3);
  dfs(c3, 1, c7, 10 * num + 5);
  dfs(c3, c5, 1, 10 * num + 7);
}

signed main(){
  cin >> N;
  dfs(0, 0, 0, 0);
  cout << ans << endl;
}