#include <bits/stdc++.h>
using namespace std;
int f(int n) {
  int cnt3 = 0;
  int cnt5 = 0;
  int cnt7 = 0;
  int flag = 0;
  while (1) {
    if (n == 0) {
      break;
    }
    if (n % 10 == 3) {
      cnt3++;
    } else if (n % 10 == 5) {
      cnt5++;
    } else if (n % 10 == 7) {
      cnt7++;
    } else {
      flag = 1;
      break;
    }
    n /= 10;
  }
  if (cnt3 > 0 && cnt5 > 0 && cnt7 > 0 && flag == 0) {
    return 1;
  } else {
    return 0;
  }
}
int main() {
  int n;
  cin >> n;
  const int z = 100000000;
  int ans = 0;
  if (n < z) {
    for (int i = 1; i <= n; i += 2) {
      if (f(i)) {
        ans++;
      }
    }
  } else {
    int a = n / z;
    if (a <= 2) {
      ans = 8334;
    } else if (a == 4) {
      ans = 14384;
    } else if (a == 6) {
      ans = 20434;
    } else if (8 <= a) {
      ans = 26484;
    } else {
      int b = n % z;
      int L = 0;
      for (int i = 1; i <= b; i += 2) {
        if (f(i)) {
          L++;
        }
      }
      if (a == 3) {
        ans = 8334 + L;
      } else if (a == 5) {
        ans = 14384 + L;
      } else if (a == 7) {
        ans = 20434 + L;
      }
    }
  }
  cout << ans;
  cout << endl;
  return 0;
}
