#include <bits/stdc++.h>
int pow_(int a, int n) {
  if (n == 0)
    return 1;
  else {
    return a * pow_(a, n - 1);
  }
}
int g(int n) {
  if (n > 3) return 3 * g(n - 1) + pow_(2, n - 1) * 3 - 6;
  if (n == 3) return 6;
}
int main(int argc, char *argv[]) {
  int n;
  scanf("%d", &n);
  int ans = 0, s, f, t, z, temp, x = 0;
  if (n <= 999) {
    for (int l = 1; l <= n; l++) {
      temp = l;
      s = 0;
      f = 0;
      t = 0;
      z = 0;
      while (temp > 0) {
        if (temp % 10 == 7)
          s++;
        else if (temp % 10 == 5)
          f++;
        else if (temp % 10 == 3)
          t++;
        else {
          z++;
          break;
        }
        temp /= 10;
      }
      if (s * t * f > 0 && z == 0) ans++;
    }
    printf("%d\n", ans);
  } else {
    int d = 0;
    temp = n;
    while (temp > 0) {
      temp /= 10;
      d++;
    }
    for (int i = 3; i < d; i++) {
      ans += g(i);
    }
    for (int i = pow_(10, d); i > n; i--) {
      temp = i;
      s = 0;
      f = 0;
      t = 0, z = 0;
      while (temp > 0) {
        if (temp % 10 == 7)
          s++;
        else if (temp % 10 == 5)
          f++;
        else if (temp % 10 == 3)
          t++;
        else {
          z++;
          break;
        }
        temp /= 10;
      }
      if (s * t * f > 0 && z == 0) ans++;
    }
    printf("%d\n", ans);
  }
  return 0;
}
