#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
const long long inf = 0x3f3f3f3f;
using namespace std;
int check(int n) {
  int x3, x5, x7;
  x3 = x5 = x7 = 0;
  while (n) {
    if (n % 10 == 3) x3++;
    if (n % 10 == 5) x5++;
    if (n % 10 == 7) x7++;
    n /= 10;
  }
  return x3 && x5 && x7;
}
int solve3(int n) {
  int ans, sum;
  ans = 0;
  for (int i = 3; i <= 7; i += 2)
    for (int j = 3; j <= 7; j += 2)
      for (int k = 3; k <= 7; k += 2) {
        sum = i * 100 + j * 10 + k;
        if (sum <= n && check(sum)) {
          ans++;
        }
      }
  return ans;
}
int solve4(int n) {
  int ans, sum;
  ans = 0;
  for (int i = 3; i <= 7; i += 2)
    for (int j = 3; j <= 7; j += 2)
      for (int k = 3; k <= 7; k += 2)
        for (int y = 3; y <= 7; y += 2) {
          sum = i * 1000 + j * 100 + k * 10 + y;
          if (sum <= n && check(sum)) {
            ans++;
          }
        }
  return ans;
}
int solve5(int n) {
  int ans, sum;
  ans = 0;
  for (int i = 3; i <= 7; i += 2)
    for (int j = 3; j <= 7; j += 2)
      for (int k = 3; k <= 7; k += 2)
        for (int y = 3; y <= 7; y += 2)
          for (int x = 3; x <= 7; x += 2) {
            sum = i * 10000 + j * 1000 + k * 100 + y * 10 + x;
            if (sum <= n && check(sum)) ans++;
          }
  return ans;
}
int solve6(int n) {
  int ans, sum;
  ans = 0;
  for (int i = 3; i <= 7; i += 2)
    for (int j = 3; j <= 7; j += 2)
      for (int k = 3; k <= 7; k += 2)
        for (int y = 3; y <= 7; y += 2)
          for (int x = 3; x <= 7; x += 2)
            for (int d = 3; d <= 7; d += 2) {
              sum = i * 100000 + j * 10000 + k * 1000 + y * 100 + x * 10 + d;
              if (sum <= n && check(sum)) ans++;
            }
  return ans;
}
int solve7(int n) {
  int ans, sum;
  ans = 0;
  for (int i = 3; i <= 7; i += 2)
    for (int j = 3; j <= 7; j += 2)
      for (int k = 3; k <= 7; k += 2)
        for (int y = 3; y <= 7; y += 2)
          for (int x = 3; x <= 7; x += 2)
            for (int d = 3; d <= 7; d += 2)
              for (int c = 3; c <= 7; c += 2) {
                sum = i * 1000000 + j * 100000 + k * 10000 + y * 1000 +
                      x * 100 + d * 10 + c;
                if (sum <= n && check(sum)) ans++;
              }
  return ans;
}
int solve8(int n) {
  int ans, sum;
  ans = 0;
  for (int i = 3; i <= 7; i += 2)
    for (int j = 3; j <= 7; j += 2)
      for (int k = 3; k <= 7; k += 2)
        for (int y = 3; y <= 7; y += 2)
          for (int x = 3; x <= 7; x += 2)
            for (int d = 3; d <= 7; d += 2)
              for (int c = 3; c <= 7; c += 2)
                for (int r = 3; r <= 7; r += 2) {
                  sum = i * 10000000 + j * 1000000 + k * 100000 + y * 10000 +
                        x * 1000 + d * 100 + c * 10 + r;
                  if (sum <= n && check(sum)) ans++;
                }
  return ans;
}
int solve9(int n) {
  int ans, sum;
  ans = 0;
  for (int i = 3; i <= 7; i += 2)
    for (int j = 3; j <= 7; j += 2)
      for (int k = 3; k <= 7; k += 2)
        for (int y = 3; y <= 7; y += 2)
          for (int x = 3; x <= 7; x += 2)
            for (int d = 3; d <= 7; d += 2)
              for (int c = 3; c <= 7; c += 2)
                for (int r = 3; r <= 7; r += 2)
                  for (int g = 3; g <= 7; g += 2) {
                    sum = i * 100000000 + j * 10000000 + k * 1000000 +
                          y * 100000 + x * 10000 + d * 1000 + c * 100 + r * 10 +
                          g;
                    if (sum <= n && check(sum)) ans++;
                  }
  return ans;
}
int solve10(int n) {
  int ans, sum;
  ans = 0;
  for (int i = 3; i <= 7; i += 2)
    for (int j = 3; j <= 7; j += 2)
      for (int k = 3; k <= 7; k += 2)
        for (int y = 3; y <= 7; y += 2)
          for (int x = 3; x <= 7; x += 2)
            for (int d = 3; d <= 7; d += 2)
              for (int c = 3; c <= 7; c += 2)
                for (int r = 3; r <= 7; r += 2)
                  for (int g = 3; g <= 7; g += 2)
                    for (int f = 3; f <= 7; f += 2) {
                      sum = i * 1000000000 + j * 100000000 + k * 10000000 +
                            y * 1000000 + x * 100000 + d * 10000 + c * 1000 +
                            r * 100 + g * 10 + f;
                      if (sum <= n && check(sum)) ans++;
                    }
  return ans;
}
int main() {
  int n, s = 0;
  scanf("%d", &n);
  int t = n;
  while (t) {
    s++;
    t /= 10;
  }
  switch (s) {
    case 3:
      printf("%d\n", solve3(n));
      break;
    case 4:
      printf("%d\n", solve4(n) + solve3(n));
      break;
    case 5:
      printf("%d\n", solve5(n) + solve4(n) + solve3(n));
      break;
    case 6:
      printf("%d\n", solve6(n) + solve5(n) + solve4(n) + solve3(n));
      break;
    case 7:
      printf("%d\n", solve7(n) + solve6(n) + solve5(n) + solve4(n) + solve3(n));
      break;
    case 8:
      printf("%d\n", solve8(n) + solve7(n) + solve6(n) + solve5(n) + solve4(n) +
                         solve3(n));
      break;
    case 9:
      printf("%d\n", solve9(n) + solve8(n) + solve7(n) + solve6(n) + solve5(n) +
                         solve4(n) + solve3(n));
      break;
    case 10:
      printf("%d\n", solve10(n) + solve9(n) + solve8(n) + solve7(n) +
                         solve6(n) + solve5(n) + solve4(n) + solve3(n));
      break;
  }
  return 0;
}
