#include<bits/stdc++.h>

#define PI 3.14159265359

using namespace std;

/******** Utility ***************/
int bsize(int bits, int _max){
  int c = 0;
  for(int ix=0; ix!=_max; ++ix)
    if((bits&(1<<ix)) !=0){
      ++c;
    }
  return c;
}

long factrial(long n){
  assert(n >= 0);
  if(n <= 1)
    return 1;
  long _sum = 1;
  for(int ix=0; ix!=(n-1); ++ix)
    _sum *= n-ix;
  return _sum;
}

template<typename T>
void show(vector<T> v)
{
  for(auto _v: v)
    cout << _v << " ";
  cout << endl;
}

template<typename T>
void show2(vector<vector<T>> v)
{
  for(auto __v: v){
    cout << "(";
    for(auto _v: __v){
      cout << _v << ", ";
    }
    cout << ")" << endl;
  }
}
/******** end of Utility ***************/

int main(void)
{
  // input
  long count = 0;
  long N;
  stringstream s8,s10;
  cin >> N;

  // main
  for(int ix=7; ix<=N; ++ix){
    s8.str("");
    s10.str("");
    s8 << oct << ix;
    s10 << dec << ix;
    if(s10.str().find("7")!=string::npos || s8.str().find("7")!=string::npos){
      ++count;
    }
  }
  cout << N - count << endl;
}
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<set>
#include<map>
#include<cmath>
#define rep(i ,n) for(int i = 1; i <= n; ++i)
#define Rep(i ,n) for(int i = n; i >= 1; --i)
using namespace std;
typedef long long ll;
typedef vector<int>  vi;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 100;
const int mod = 1e9 + 7;

int main(){
    ll T = 10000000000;
    int n;string s;cin >> n >> s;
    string p = "";
    while(p.size() < n + 10) p += "110";
    ll ans = 0;
    for(int i = 0;i <3;i++){
        if(s != p.substr(i,n)) continue;
        ans += T - (n + i - 1) / 3;
    }
    cout << ans << endl;
    return 0;
}