#include <bits/stdc++.h>
using namespace std;
int N;
int cnt = 0;
int x[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int convert(int *a, int len) {
  int ans = 0;
  for (int i = 0; i < len; i++) {
    ans += a[i] * pow(10, len - i - 1);
  }
  return ans;
}
bool check(int *a, int len) {
  if (convert(a, len) > N) {
    cout << cnt << endl;
    exit(0);
  }
  int cnt3 = 0, cnt5 = 0, cnt7 = 0;
  for (int i = 0; i < len; i++) {
    if (a[i] == 3)
      cnt3++;
    else if (a[i] == 5)
      cnt5++;
    else if (a[i] == 7)
      cnt7++;
  }
  if (cnt3 != 0 && cnt5 != 0 && cnt7 != 0 && cnt3 + cnt5 + cnt7 == len) {
    cnt++;
  }
  return true;
}
bool backtrack(int t, int n) {
  if (t >= n) {
    bool xx = check(x, n);
    if (!xx)
      return false;
    else
      return true;
  } else {
    for (int i = 3; i <= 7; i += 2) {
      x[t] = i;
      backtrack(t + 1, n);
      x[t] = 0;
    }
  }
}
int main() {
  cin >> N;
  stringstream ss;
  string str;
  ss << N;
  ss >> str;
  int n = str.length();
  if (N < 357) {
    cout << "0" << endl;
    return 0;
  }
  for (int i = 3; i <= n; i++) {
    bool xxx = backtrack(0, i);
  }
  return 0;
}
