#include <bits/stdc++.h>
using namespace std;
static const long long maxLL = (long long)1 << 62;
const long long MOD = 1000000007;
const long long INF = 1e18;
int ca[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
signed main() {
  int i, j, k;
  int n, cnt = 0;
  cin >> n;
  if (n < 1000) {
    int num = n;
    for (i = 0; i <= num; i++) {
      if (i % 10 == 1 || i % 10 == 2 || i % 10 == 4 || i % 10 == 6 ||
          i % 10 == 8 || i % 10 == 9 || i % 10 == 0)
        continue;
      string s = to_string(i);
      vector<int> list(10, 0);
      for (j = 0; j < s.length(); j++) {
        list[s[j] - 48]++;
      }
      if (list[7] == 1 && list[5] == 1 && list[3] == 1) cnt++;
    }
    cout << cnt << endl;
    getchar();
    getchar();
    return 0;
  }
  vector<int> a(10, 4);
  string s = to_string(n);
  if (s[0] - 48 >= 7) {
    a[s.length() - 1] = 4;
  } else if (s[0] - 48 >= 5) {
    a[s.length() - 1] = 3;
  } else if (s[0] - 48 >= 3) {
    a[s.length() - 1] = 2;
  } else {
    a[s.length() - 1] = 1;
  }
  vector<bool> flag(4, false);
  vector<int> li(10, 0);
  int i1, i2, i3, i4, i5, i6, i7, i8, i9;
  int len = s.length();
  for (int i1 = len > 8 ? 1 : 0; i1 < a[8]; i1++) {
    li[8] = i1;
    for (int i2 = len > 7 ? 1 : 0; i2 < a[7]; i2++) {
      li[7] = i2;
      for (int i3 = len > 6 ? 1 : 0; i3 < a[6]; i3++) {
        li[6] = i3;
        for (int i4 = len > 5 ? 1 : 0; i4 < a[5]; i4++) {
          li[5] = i4;
          for (int i5 = len > 4 ? 1 : 0; i5 < a[4]; i5++) {
            li[4] = i5;
            for (int i6 = len > 3 ? 1 : 0; i6 < a[3]; i6++) {
              li[3] = i6;
              for (int i7 = len > 2 ? 1 : 0; i7 < a[2]; i7++) {
                li[2] = i7;
                for (int i8 = len > 1 ? 1 : 0; i8 < a[1]; i8++) {
                  li[1] = i8;
                  for (int i9 = 1; i9 < a[0]; i9++) {
                    li[0] = i9;
                    bool flag2[4] = {false, false, false, false};
                    for (int index = 0; index < s.length(); index++) {
                      flag2[li[index]] = true;
                    }
                    if (flag2[1] == false || flag2[2] == false ||
                        flag2[3] == false) {
                    } else {
                      cnt++;
                    }
                  }
                }
              }
            }
            if (s.length() == 4) goto labelend;
          }
          if (s.length() == 5) goto labelend;
        }
        if (s.length() == 6) goto labelend;
      }
      if (s.length() == 7) goto labelend;
    }
    if (s.length() == 8) goto labelend;
  }
labelend:
  cout << cnt << endl;
  getchar();
  getchar();
  return 0;
}
