#include <bits/stdc++.h>
using namespace std;
int n, cnt = 0;
void dfs(int now, int ok) {
  if (now > n) return;
  if (ok == 0b111) cnt++;
  dfs(now * 10 + 7, ok | 0b100);
  dfs(now * 10 + 5, ok | 0b010);
  dfs(now * 10 + 3, ok | 0b001);
}
int main() {
  cin >> n;
  dfs(0, 0);
  cout << cnt << endl;
}
