#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, nc, a[10], b[10], c[10];
  cin >> n;
  nc = n;
  a[3] = 6;
  b[3] = 18;
  c[3] = 3;
  for (int i = 3; i < 9; i++) {
    a[i + 1] = 3 * a[i] + b[i];
    b[i + 1] = 2 * b[i] + 2 * c[i];
    c[i + 1] = c[i];
  }
  int keta;
  for (int i = 0; i < 10; i++) {
    nc /= 10;
    if (nc == 0) {
      keta = i + 1;
      break;
    }
  }
  int ans = 0;
  for (int i = 3; i <= keta - 1; i++) {
    ans += a[i];
  }
  if (n < 357) {
    cout << 0 << endl;
    return 0;
  }
  if (n < 33 * pow(10, keta - 2))
    cout << ans << endl;
  else if (n < 38 * pow(10, keta - 2)) {
    for (int i = n; i >= 33 * pow(10, keta - 2); i--) {
      int d3 = 0, d5 = 0, d7 = 0, ic = i;
      while (ic != 0) {
        if (ic % 10 == 3) d3++;
        if (ic % 10 == 5) d5++;
        if (ic % 10 == 7) d7++;
        ic /= 10;
      }
      if (d3 > 0 && d5 > 0 && d7 > 0 && d3 + d5 + d7 == keta) ans++;
    }
    cout << ans << endl;
  } else if (n < 53 * pow(10, keta - 2)) {
    cout << ans + a[keta] / 3 << endl;
  } else if (n < 58 * pow(10, keta - 2)) {
    for (int i = n; i >= 33 * pow(10, keta - 2); i--) {
      int d3 = 0, d5 = 0, d7 = 0, ic = i;
      while (ic != 0) {
        if (ic % 10 == 3) d3++;
        if (ic % 10 == 5) d5++;
        if (ic % 10 == 7) d7++;
        ic /= 10;
      }
      if (d3 > 0 && d5 > 0 && d7 > 0 && d3 + d5 + d7 == keta) ans++;
    }
    cout << ans + a[keta] / 3 << endl;
  } else if (n < 73 * pow(10, keta - 2)) {
    cout << ans + (2 * a[keta]) / 3 << endl;
  } else if (n < 78 * pow(10, keta - 2)) {
    for (int i = n; i >= 33 * pow(10, keta - 2); i--) {
      int d3 = 0, d5 = 0, d7 = 0, ic = i;
      while (ic != 0) {
        if (ic % 10 == 3) d3++;
        if (ic % 10 == 5) d5++;
        if (ic % 10 == 7) d7++;
        ic /= 10;
      }
      if (d3 > 0 && d5 > 0 && d7 > 0 && d3 + d5 + d7 == keta) ans++;
    }
    cout << ans + (2 * a[keta]) / 3 << endl;
  }
}
