#include <bits/stdc++.h>
int n;
int ans = 0;
using namespace std;
int recurse(string now, int a, int b, int c) {
  int kaisu;
  if (stoi(now) > n) {
    return 0;
  }
  kaisu = recurse("3" + now, 1, b, c) + recurse("5" + now, a, 1, c) +
          recurse("7" + now, a, b, 1);
  if (a == 1 && b == 1 && c == 1) {
    return kaisu + 1;
  } else {
    return kaisu;
  }
}
int main() {
  cin >> n;
  int sum;
  sum = recurse("3", 1, 0, 0) + recurse("5", 0, 1, 0) + recurse("7", 0, 0, 1);
  cout << sum << endl;
  return 0;
}
