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

ll N;
int cnt = 0;

void dfs(ll x, int a, int b, int c) {
  if (x > N) return;
  if (a >= 1 && b >= 1 && c >= 1) cnt++;
  dfs(10 * x + 3, a + 1, b, c);
  dfs(10 * x + 5, a, b + 1, c);
  dfs(10 * x + 7, a, b, c + 1);
}

int main() {
  cin >> N;
  dfs(0, 0, 0, 0);
  cout << cnt << endl;
}
