#include <bits/stdc++.h>
using namespace std;

long long n,ans;

void dfs(long long x,long long a,long long b,long long c){
  if(x>n) return;
  if(a&&b&&c){ans++;}
  dfs(10*x+3,1,b,c);
  dfs(10*x+5,a,1,c);
  dfs(10*x+7,a,b,1);
}

int main(){
  cin >> n;
  ans=0;
  dfs(0,0,0,0);
  cout << ans << endl;
}