#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  long long a, b, c, i, j, k, l, m, n, counter, num753;
  for (i = 3; i < 8; i += 2) {
    for (j = 3; j < 8; j += 2) {
      if (i != j) {
        for (k = 3; k < 8; k += 2) {
          if (k != j) {
            num753 = (100 * i + 10 * j + k);
            for (l = 0; l < 8; l++) {
              for (m = 3; m < 8; m += 2) {
                if (l == 0) {
                  num753 = num753;
                } else {
                  num753 = num753 * 10 + m;
                }
                if (N - num753 >= 0) {
                  counter++;
                }
                cout << num753 << endl;
              }
            }
          }
        }
      }
    }
  }
  cout << counter << endl;
}
