#include <bits/stdc++.h>
using namespace std;
int N;
char tfs[3] = {'3', '5', '7'};
int dfs(string s) {
  int ans;
  if (stoi(s) > N)
    return 0;
  else {
    int three, five, seven;
    three = 0;
    five = 0;
    seven = 0;
    for (int i = (int)(0); i < (int)(s.length()); i++) {
      if (s[i] == '3') three++;
      if (s[i] == '5') five++;
      if (s[i] == '7') seven++;
    }
    ans = (three > 0 && five > 0 && seven > 0) ? 1 : 0;
  }
  for (auto c : tfs) {
    ans += dfs(s + c);
  }
  return ans;
}
int main() {
  cin >> N;
  int rep = dfs("0");
  cout << rep << endl;
}
