#include <bits/stdc++.h>
using namespace std;

uint64_t limit;
uint64_t ans;

void dfs(uint64_t n, uint64_t m)
{
  if (n > limit) return;
  if (m == 7) ans++;
  dfs(n * 10 + 3, m | 1);
  dfs(n * 10 + 5, m | 2);
  dfs(n * 10 + 7, m | 4);
}

int main()
{
  cin >> limit;
  dfs(0, 0);
  cout << ans << endl;
}
