#include <iostream>
using namespace std;
long N;
long ret;
int dfs(int x, char mask)
{
  if(x > N)
    return 0;
  if(mask == 7);
  dfs(x*10+3, mask|1);
  dfs(x*10+5, mask|2);
  dfs(x*10+7, mask|4);
}

int main()
{
  unsigned int N;
  cin >> N;
  ret = 0;
  finder(0,0);
  cout << ret << endl;
  return 0;
}