/******************* This is ZerothKing *******************/
#include <bits/stdc++.h>
using namespace std;

#define REP(i, a, b) for(int i = int(a); i < int(b); i++)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())

const double pi = acos(-1.0);

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef set<ll> setll;
typedef multiset<int> mseti;
typedef vector<ll> vll;
typedef vector<vll> vvl;

void solve() {
	int i, j, k = 0, n, m;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int temp = i;
		bool inc = false;
		while (temp) {
			if (temp % 10 == 7) {
				k++;
				inc = true;
				break;
			}
			temp /= 10;
		}
		if (inc) continue;
		temp = i;
		while (temp) {
			if (temp % 8 == 7) {
				k++;
				break;
			}
			temp /= 8;
		}
	}
	cout << n - k;
}


int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE

	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
}
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define st first
#define nd second
#define pii pair<int,int>
#define mp make_pair
#define pll pair<long long,long long>

using namespace std;

const int nax = 1e6 + 5;
char ans[nax];
void solve(){
    string s; cin >> s;
    int lo = nax / 2;
    int hi = nax / 2 - 1;
    bool rev = false;
    for(char x : s){
        if(x == 'R') rev = !rev;
        else{
            if(!rev){
                if(lo <= hi && ans[hi] == x){
                    hi--;
                }
                else ans[++hi] = x;
            }
            else{
                if(lo <= hi && ans[lo] == x){
                    lo++;
                }
                else ans[--lo] = x;
            }
        }
    }
    if(!rev){
        for(int i=lo;i<=hi;i++) cout << ans[i];
    }
    else{
        for(int i=hi;i>=lo;i--) cout << ans[i];
    }

}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    int tt = 1;
    // cin >> tt;
    while(tt--) solve();

    return 0;
}
