#include <bits/stdc++.h>
using namespace std;
int dfs(int N, int Num) {
  int ans = 0;
  if (Num > N) {
    return 0;
  }
  string temp = to_string(Num);
  bool flag = true;
  if (temp.find('7') == string::npos) flag = false;
  if (temp.find('5') == string::npos) flag = false;
  if (temp.find('3') == string::npos) flag = false;
  if (flag) ans += 1;
  ans += dfs(N, Num * 10 + 3);
  ans += dfs(N, Num * 10 + 5);
  ans += dfs(N, Num * 10 + 7);
  return ans;
}
int main(void) {
  int N;
  cin >> N;
  int ans = dfs(N, 0);
  cout << ans << "\n";
}
