#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int mod = 1e9 + 7;
vector<long long> z;
void zzz(int i, long long j) {
  z.push_back(j);
  if (i < 9) {
    zzz(i + 1, j * 10 + 3);
    zzz(i + 1, j * 10 + 5);
    zzz(i + 1, j * 10 + 7);
  }
}
int main() {
  long long s;
  cin >> s;
  zzz(0, 0);
  sort(z.begin(), z.end());
  int ans = 0;
  for (int i = 0; z[i] <= s; i++) {
    int flag[10] = {};
    while (z[i]) {
      flag[z[i] % 10]++;
      z[i] /= 10;
      if (flag[3] && flag[5] && flag[7]) {
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
