#include <bits/stdc++.h>

using namespace std;

long long N, ans;

void rec(long long s, bool has3, bool has5, bool has7) {
  if (s > N) return;
  if (has3 && has5 && has7) ans++;
  rec(10*s+3, true, has5, has7);
  rec(10*s+5, has3, true, has7);
  rec(10*s+7, has3, has5, true);
}

int main()
{
  cin >> N;
  rec(0, false, false, false);
  cout << ans << endl;
}