#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  int sum = 0;
  for (int i = 0; i < a; i++) {
    int b = i % 10;
    int c = (i % 100) / 10;
    int d = (i % 1000) / 100;
    int e = (i % 10000) / 1000;
    int f = (i % 100000) / 10000;
    int g = (i % 1000000) / 100000;
    int h = (i % 10000000) / 1000000;
    int j = (i % 100000000) / 10000000;
    int k = (i % 1000000000) / 100000000;
    if (a < 100) {
    } else if (a < 1000 && a >= 100) {
      if (((b != 3 || b != 5 || b != 7) || (c != 3 || c != 5 || c != 7) ||
           (d != 3 || d != 5 || d != 7)) ||
          ((b != 3 && c != 3 && d != 3) || (b != 5 && c != 5 && d != 5) ||
           (b != 7 && c != 7 && d != 7))) {
      } else {
        sum++;
      }
    } else if (a < 10000 && a >= 1000) {
      if (((b != 3 || b != 5 || b != 7) || (c != 3 || c != 5 || c != 7) ||
           (d != 3 || d != 5 || d != 7) || (e != 3 || e != 5 || e != 7)) ||
          ((b != 3 && c != 3 && d != 3 && e != 3) ||
           (b != 5 && c != 5 && d != 5 && e != 5) ||
           (b != 7 && c != 7 && d != 7 && e != 7))) {
      } else {
        sum++;
      }
    } else if (a < 100000 && a >= 10000) {
      if (((b != 3 || b != 5 || b != 7) || (c != 3 || c != 5 || c != 7) ||
           (d != 3 || d != 5 || d != 7) || (e != 3 || e != 5 || e != 7) ||
           (f != 3 || f != 5 || f != 7)) ||
          ((b != 3 && c != 3 && d != 3 && e != 3 && f != 3) ||
           (b != 5 && c != 5 && d != 5 && e != 5 && f != 5) ||
           (b != 7 && c != 7 && d != 7 && e != 7 && f != 7))) {
      } else {
        sum++;
      }
    } else if (a < 1000000 && a >= 100000) {
      if (((b != 3 || b != 5 || b != 7) || (c != 3 || c != 5 || c != 7) ||
           (d != 3 || d != 5 || d != 7) || (e != 3 || e != 5 || e != 7) ||
           (f != 3 || f != 5 || f != 7) || (g != 3 || g != 5 || g != 7)) ||
          ((b != 3 && c != 3 && d != 3 && e != 3 && f != 3 && g != 3) ||
           (b != 5 && c != 5 && d != 5 && e != 5 && f != 5 && g != 5) ||
           (b != 7 && c != 7 && d != 7 && e != 7 && f != 7 && g != 7))) {
      } else {
        sum++;
      }
    } else if (a < 10000000 && a >= 1000000) {
      if (((b != 3 || b != 5 || b != 7) || (c != 3 || c != 5 || c != 7) ||
           (d != 3 || d != 5 || d != 7) || (e != 3 || e != 5 || e != 7) ||
           (f != 3 || f != 5 || f != 7) || (g != 3 || g != 5 || g != 7) ||
           (h != 3 || h != 5 || h != 7)) ||
          ((b != 3 && c != 3 && d != 3 && e != 3 && f != 3 && g != 3 &&
            h != 3) ||
           (b != 5 && c != 5 && d != 5 && e != 5 && f != 5 && g != 5 &&
            h != 5) ||
           (b != 7 && c != 7 && d != 7 && e != 7 && f != 7 && g != 7 &&
            h != 7))) {
      } else {
        sum++;
      }
    } else if (a < 100000000 && a >= 10000000) {
      if (((b != 3 || b != 5 || b != 7) || (c != 3 || c != 5 || c != 7) ||
           (d != 3 || d != 5 || d != 7) || (e != 3 || e != 5 || e != 7) ||
           (f != 3 || f != 5 || f != 7) || (g != 3 || g != 5 || g != 7) ||
           (h != 3 || h != 5 || h != 7) || (j != 3 || j != 5 || j != 7)) ||
          ((b != 3 && c != 3 && d != 3 && e != 3 && f != 3 && g != 3 &&
            h != 3 && j != 3) ||
           (b != 5 && c != 5 && d != 5 && e != 5 && f != 5 && g != 5 &&
            h != 5 && j != 5) ||
           (b != 7 && c != 7 && d != 7 && e != 7 && f != 7 && g != 7 &&
            h != 7 && j != 7))) {
      } else {
        sum++;
      }
    } else {
      if (((b != 3 || b != 5 || b != 7) || (c != 3 || c != 5 || c != 7) ||
           (d != 3 || d != 5 || d != 7) || (e != 3 || e != 5 || e != 7) ||
           (f != 3 || f != 5 || f != 7) || (g != 3 || g != 5 || g != 7) ||
           (h != 3 || h != 5 || h != 7) || (j != 3 || j != 5 || j != 7) ||
           (k != 3 || k != 5 || k != 7)) ||
          ((b != 3 && c != 3 && d != 3 && e != 3 && f != 3 && g != 3 &&
            h != 3 && j != 3 && k != 3) ||
           (b != 5 && c != 5 && d != 5 && e != 5 && f != 5 && g != 5 &&
            h != 5 && j != 5 && k != 5) ||
           (b != 7 && c != 7 && d != 7 && e != 7 && f != 7 && g != 7 &&
            h != 7 && j != 7 && k != 7))) {
      } else {
        sum++;
      }
    }
  }
  cout << sum << endl;
}
