#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, num, k, ans = 0;
  int a[200000];
  cin >> n;
  a[0] = 333;
  a[1] = 335;
  a[2] = 337;
  a[3] = 353;
  a[4] = 355;
  a[5] = 357;
  a[6] = 373;
  a[7] = 375;
  a[8] = 377;
  a[9] = 533;
  a[10] = 535;
  a[11] = 537;
  a[12] = 553;
  a[13] = 555;
  a[14] = 557;
  a[15] = 573;
  a[16] = 575;
  a[17] = 577;
  a[18] = 733;
  a[19] = 735;
  a[20] = 737;
  a[21] = 753;
  a[22] = 755;
  a[23] = 757;
  a[24] = 773;
  a[25] = 775;
  a[26] = 777;
  num = 27;
  int i = 27;
  int o = 0;
  int b = 3000, c = 5000, d = 7000;
  while (1) {
    for (int j = 0; j < num; j++) {
      a[i + j] = a[o] + b;
    }
    if (a[i] > 1000000000) break;
    i += num;
    for (int j = 0; j < num; j++) {
      a[i + j] = a[o] + c;
    }
    if (a[i] > 1000000000) break;
    i += num;
    for (int j = 0; j < num; j++) {
      a[i + j] = a[o] + d;
    }
    if (a[i] > 1000000000) break;
    i += num;
    o = i + 1;
    num *= 3;
    b *= 10;
    c *= 10;
    d *= 10;
  }
  for (k = 0; k < 200000; k++) {
    if (a[k] > n)
      break;
    else {
      int z = 10, q[3] = {0, 0, 0};
      while (a[k] != 0) {
        if (a[k] % z == 3) q[0] = 1;
        if (a[k] % z == 5) q[1] = 1;
        if (a[k] % z == 7) q[2] = 1;
        a[k] /= 10;
      }
      if (q[0] + q[1] + q[2] == 3) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
