#include<iostream>
using namespace std;
long long n, cnt;

void dfs(long long x, int f)
{
  if(x>n) return;
  if(f==7) cnt++;
  dfs(x*10+3, f|1);
  dfs(x*10+5, f|2);
  dfs(x*10+7, f|4);
}

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