#include <bits/stdc++.h>
using namespace std;
const int inf = 1012345678;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int ans[1000000];
int sum[1000000];
vector<int> v;
int N;
int bfs(int num) {
  if (num > N)
    return 0;
  else {
    v.push_back(num);
    bfs(num * 10 + 3);
    bfs(num * 10 + 5);
    bfs(num * 10 + 7);
  }
  return 0;
}
int main() {
  cin >> N;
  bfs(0);
  int ans = 0;
  for (int i = 0; i < v.size(); i++) {
    bool a = false;
    bool b = false;
    bool c = false;
    int n = v[i];
    while (n) {
      if (n % 10 == 3) a = true;
      if (n % 10 == 5) b = true;
      if (n % 10 == 7) c = true;
      n /= 10;
    }
    if (a && b && c) ans++;
  }
  cout << ans << endl;
  return 0;
}
