#include <bits/stdc++.h>
using namespace std;
int N, arr[3] = {3, 5, 7}, ans;
int dfs(int x, int a, int b, int c) {
  if (x > N)
    return 0;
  else if (a == 1 && b == 1 && c == 1)
    ans++;
  dfs(x * 10 + arr[0], 1, b, c);
  dfs(x * 10 + arr[1], a, 1, c);
  dfs(x * 10 + arr[2], a, b, 1);
}
int main() {
  cin >> N;
  dfs(arr[0], 1, 0, 0);
  dfs(arr[1], 0, 1, 0);
  dfs(arr[2], 0, 0, 1);
  cout << ans;
}
