#include <bits/stdc++.h>
using namespace std;
int n;
int dfs(int s, bool n3, bool n5, bool n7) {
  int r = 0;
  if (s > n) return 0;
  r += dfs(s * 10 + 3, true, n5, n7);
  r += dfs(s * 10 + 5, n3, true, n7);
  r += dfs(s * 10 + 7, n3, n5, true);
  return r + (n3 & n5 & n7);
}
int main(void) {
  cin >> n;
  cout << dfs(0, false, false, false) << endl;
  return 0;
}
