#include <bits/stdc++.h>
using namespace std;
int up(int x) {
  int d[15], cnt = 0;
  while (x) {
    d[cnt++] = x % 10;
    x /= 10;
  }
  int i = 0;
  for (; i < cnt; i++) {
    if (d[i] == 7)
      d[i] = 3;
    else {
      if (d[i] == 3)
        d[i] = 5;
      else if (d[i] == 5)
        d[i] = 7;
      break;
    }
  }
  if (i >= cnt) d[cnt++] = 3;
  int ans = 0;
  for (i = cnt - 1; i >= 0; i--) ans = ans * 10 + d[i];
  return ans;
}
bool ok(int x) {
  int f1 = 0, f2 = 0, f3 = 0;
  while (x) {
    int k = x % 10;
    if (k == 3) f1++;
    if (k == 5) f2++;
    if (k == 7) f3++;
    if (f1 && f2 && f3) return true;
    x /= 10;
  }
  return false;
}
int main() {
  int n;
  scanf("%d", &n);
  int k = 333;
  int ans = 0;
  while (k <= n) {
    if (ok(k)) ans++;
    k = up(k);
  }
  printf("%d\n", ans);
  return 0;
}
