#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7, MAX = 1e5;
int dp[10][2][7];
int main() {
  string s, t;
  s = "0";
  cin >> t;
  s = t;
  int sn = s.size();
  if (s[0] == '3') {
    dp[0][0][0]++;
  }
  if (s[0] == '5') {
    dp[0][0][1]++;
  }
  if (s[0] == '7') {
    dp[0][0][2]++;
  }
  for (int i = 1; i < sn; i++) {
    for (int j = 0; j < 3; j++) {
      dp[i][1][j]++;
    }
  }
  for (char i = '3'; i < s[0]; i += 2) {
    dp[0][1][(i - '3') / 2]++;
  }
  for (int i = 0; i < sn - 1; i++) {
    if (s[i + 1] == '3') {
      dp[i + 1][0][0] += dp[i][0][0];
      dp[i + 1][0][3] += dp[i][0][3];
      dp[i + 1][0][4] += dp[i][0][4];
      dp[i + 1][0][6] += dp[i][0][6];
      dp[i + 1][0][3] += dp[i][0][1];
      dp[i + 1][0][4] += dp[i][0][2];
      dp[i + 1][0][6] += dp[i][0][5];
    }
    if (s[i + 1] == '5') {
      dp[i + 1][0][1] += dp[i][0][1];
      dp[i + 1][0][3] += dp[i][0][3];
      dp[i + 1][0][5] += dp[i][0][5];
      dp[i + 1][0][6] += dp[i][0][6];
      dp[i + 1][0][3] += dp[i][0][0];
      dp[i + 1][0][5] += dp[i][0][2];
      dp[i + 1][0][6] += dp[i][0][4];
    }
    if (s[i + 1] == '7') {
      dp[i + 1][0][2] += dp[i][0][2];
      dp[i + 1][0][4] += dp[i][0][4];
      dp[i + 1][0][5] += dp[i][0][5];
      dp[i + 1][0][6] += dp[i][0][6];
      dp[i + 1][0][4] += dp[i][0][0];
      dp[i + 1][0][5] += dp[i][0][1];
      dp[i + 1][0][6] += dp[i][0][3];
    }
    for (char c = '3'; c < s[i + 1]; c += 2) {
      if (c == '3') {
        dp[i + 1][1][0] += dp[i][0][0];
        dp[i + 1][1][3] += dp[i][0][3];
        dp[i + 1][1][4] += dp[i][0][4];
        dp[i + 1][1][6] += dp[i][0][6];
        dp[i + 1][1][3] += dp[i][0][1];
        dp[i + 1][1][4] += dp[i][0][2];
        dp[i + 1][1][6] += dp[i][0][5];
      }
      if (c == '5') {
        dp[i + 1][1][1] += dp[i][0][1];
        dp[i + 1][1][5] += dp[i][0][5];
        dp[i + 1][1][3] += dp[i][0][0];
        dp[i + 1][1][5] += dp[i][0][2];
        dp[i + 1][1][6] += dp[i][0][4];
      }
      if (c == '7') {
        dp[i + 1][1][2] += dp[i][0][2];
        dp[i + 1][1][4] += dp[i][0][0];
        dp[i + 1][1][5] += dp[i][0][1];
        dp[i + 1][1][6] += dp[i][0][3];
      }
    }
    for (char c = '3'; c <= '7'; c += 2) {
      if (c == '3') {
        dp[i + 1][1][0] += dp[i][1][0];
        dp[i + 1][1][3] += dp[i][1][3];
        dp[i + 1][1][4] += dp[i][1][4];
        dp[i + 1][1][6] += dp[i][1][6];
        dp[i + 1][1][3] += dp[i][1][1];
        dp[i + 1][1][4] += dp[i][1][2];
        dp[i + 1][1][6] += dp[i][1][5];
      }
      if (c == '5') {
        dp[i + 1][1][1] += dp[i][1][1];
        dp[i + 1][1][3] += dp[i][1][3];
        dp[i + 1][1][5] += dp[i][1][5];
        dp[i + 1][1][6] += dp[i][1][6];
        dp[i + 1][1][3] += dp[i][1][0];
        dp[i + 1][1][5] += dp[i][1][2];
        dp[i + 1][1][6] += dp[i][1][4];
      }
      if (c == '7') {
        dp[i + 1][1][2] += dp[i][1][2];
        dp[i + 1][1][4] += dp[i][1][4];
        dp[i + 1][1][5] += dp[i][1][5];
        dp[i + 1][1][6] += dp[i][1][6];
        dp[i + 1][1][4] += dp[i][1][0];
        dp[i + 1][1][5] += dp[i][1][1];
        dp[i + 1][1][6] += dp[i][1][3];
      }
    }
  }
  cout << dp[sn - 1][0][6] + dp[sn - 1][1][6] << endl;
  return 0;
}
