#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  queue<int> q;
  int ans = 0;
  q.push(357);
  q.push(375);
  q.push(537);
  q.push(573);
  q.push(735);
  q.push(753);
  int tmp;
  while (q.front() <= n) {
    tmp = q.front();
    q.push(tmp * 10 + 3);
    q.push(tmp * 10 + 5);
    q.push(tmp * 10 + 7);
    q.pop();
    ans++;
  }
  cout << ans << endl;
}
