#include <bits/stdc++.h>
using namespace std;
int i, j, n, m;
string s, t;
int dfs(int x, bool a, bool b, bool c) {
  if (x > n) return 0;
  int ret = 0;
  if (a && b && c) ret++;
  ret += dfs(x * 10 + 7, true, b, c);
  ret += dfs(x * 10 + 5, a, true, c);
  ret += dfs(x * 10 + 3, a, b, true);
  return ret;
}
signed main() {
  cin >> n;
  cout << dfs(0, false, false, false) << endl;
  return 0;
}
