#include <bits/stdc++.h>
using namespace std;
int M = 0;
int n;
int A[15];
bool vis[1000000000];
void dfs(int k) {
  int flag = 1;
  do {
    int num = 0;
    for (int i = 0; i < k; i++) num = num * 10 + A[i];
    if (num <= n && vis[num] == false) {
      vis[num] = true;
      M++;
    } else
      flag = 0;
  } while (next_permutation(A, A + k));
  if (flag == 1) {
    A[k] = 3;
    dfs(k + 1);
    A[k] = 5;
    dfs(k + 1);
    A[k] = 7;
    dfs(k + 1);
  }
}
int main() {
  A[0] = 3;
  A[1] = 5;
  A[2] = 7;
  int k = 3;
  cin >> n;
  dfs(k);
  cout << M;
  return 0;
}
