#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N;
int A[15];
int x[15][15], y[15][15];
void dfs(ll M, int bits, int& count) {
  if (M > N) return;
  if (bits == 0b111) count++;
  dfs(M * 10 * 7, bits | 0b100, count);
  dfs(M * 10 * 5, bits | 0b010, count);
  dfs(M * 10 * 3, bits | 0b001, count);
}
int main() {
  cin >> N;
  ll M = 0;
  int bits = 0b000;
  int count = 0;
  dfs(M, bits, count);
  cout << count << endl;
}
