#include <iostream>
using namespace std;

typedef long long ll;
ll N, ans = 0;

void dfs(ll x, bool a, bool b, bool c){
  if (x > N) {
    return;
  }
  if(a && b && c) {
    ans++;
  }

  dfs(10 * x + 3, true, b, c);
  dfs(10 * x + 5, a, true, c);
  dfs(10 * x + 7, a, b, true);
}

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