#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int dfs(int N, int th, int fi, int se, int oldNum);
int main() {
  int N;
  scanf("%d", &N);
  int ans = dfs(N, 1, 1, 1, 0);
  cout << ans;
  return 0;
}
int dfs(int N, int th, int fi, int se, int oldNum) {
  int count = 0;
  int newNum;
  newNum = oldNum * 10 + 3;
  if (fi == 0 && se == 0 && newNum <= N) {
    count++;
  }
  if (newNum <= N) count += dfs(N, 0, fi, se, newNum);
  newNum = oldNum * 10 + 5;
  if (th == 0 && se == 0 && newNum <= N) {
    count++;
  }
  if (newNum <= N) count += dfs(N, th, 0, se, newNum);
  newNum = oldNum * 10 + 7;
  if (th == 0 && fi == 0 && newNum <= N) {
    count++;
  }
  if (newNum <= N) count += dfs(N, th, fi, 0, newNum);
  return count;
}
