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

int N;
int ret = 0;

void dfs(long long cur, int mask) {
  if (cur > N){
    return;
  }
  if (mask == 7){
    ret++;
  }
  dfs(cur * 10 + 3, mask | 4);
  dfs(cur * 10 + 5, mask | 2);
  dfs(cur * 10 + 7, mask | 1);  
}

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