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

int N;

int ans=0;

void dfs(long long n,int three,int five,int seven){
  if (n>N){
    return;
  }
  if (three&&five&&seven){
    ans++;
  }
  dfs(10*n+3,1,five,seven);
  dfs(10*n+5,three,1,seven);
  dfs(10*n+7,three,five,1);
  return;
}

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