#include <bits/stdc++.h>
using namespace std;
bool check_shit(int a) {
  int flag_3 = 0, flag_5 = 0, flag_7 = 0;
  while (a) {
    if (a % 10 == 3)
      flag_3 = 1;
    else if (a % 10 == 5)
      flag_5 = 1;
    else if (a % 10 == 7)
      flag_7 = 1;
    a /= 10;
  }
  if (flag_3 && flag_5 && flag_7)
    return true;
  else
    return false;
}
void shigosan(int N, int m, int &ans) {
  if (N >= m * 10 + 3) {
    if (check_shit(m * 10 + 3)) ans++;
    shigosan(N, m * 10 + 3, ans);
  }
  if (N >= m * 10 + 5) {
    if (check_shit(m * 10 + 5)) ans++;
    shigosan(N, m * 10 + 5, ans);
  }
  if (N >= m * 10 + 7) {
    if (check_shit(m * 10 + 7)) ans++;
    shigosan(N, m * 10 + 7, ans);
  }
}
int main() {
  int N;
  cin >> N;
  int ans = 0;
  shigosan(N, 0, ans);
  cout << ans << endl;
}
