#include <bits/stdc++.h>
using namespace std;
int n;
int good[3] = {3, 5, 7};
int cnt = 0;
void dfs(long long, long long);
int main() {
  cin >> n;
  dfs(0, 0);
  cout << cnt << endl;
}
void dfs(long long sum, long long d) {
  if (sum >= n) {
    return;
  }
  long long crr = sum;
  int flag1 = 0;
  int flag2 = 0;
  int flag3 = 0;
  while (crr > 0) {
    long long temp = crr % 10;
    if (temp == 5) flag1 = 1;
    if (temp == 7) flag2 = 1;
    if (temp == 3) flag3 = 1;
    crr /= 10;
  }
  if (flag1 == 1 && flag2 == 1 && flag3 == 1) cnt++;
  for (int i = 0; i < 3; i++) {
    int neww = good[i];
    if (sum * 10 + neww <= n) {
      dfs(sum * 10 + neww, d + 1);
    }
  }
}
