#include <bits/stdc++.h>
//#include "atcoder/all"
using namespace std;
using ll = long long;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
const ll mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;

  vector<vector<ll>> dp(65, vector<ll>(2));
  dp[0][0] = 1;
  dp[0][1] = 1;

  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;

    if (s == "OR") {
      dp[i + 1][0] = dp[i][0];
      dp[i + 1][1] = dp[i][0] + 2 * dp[i][1];
    } else {
      dp[i + 1][0] = dp[i][0] * 2 + dp[i][1];
      dp[i + 1][1] = dp[i][1];
    }
  }

  cout << dp[n][1] << endl;
}
/*      Author : Kaustubh Gangwar
        Institute : IIITA        */
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define vi vector<int>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define f(i, a, b) for (int i = a; i < b; i++)
#define fe(i, a, b) for (int i = a; i <= b; i++)
#define sz(x) (int)((x).size())
#define CODING ios_base::sync_with_stdio(false);
#define SAMRAT cin.tie(0), cout.tie(0);
#define mll map<ll, ll>
#define nl '\n'
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef pair<ll, ll> pll;

ll bpow(ll a, ll b)
{
    a = a;
    ll ans = 1;
    while (b)
    {
        if (b & 1)
            ans = ans * a;
        a = a * a;
        b >>= 1;
    }
    return ans;
}

int32_t main()
{
    CODING SAMRAT
    int test = 1;
    //cin >> test;
    while (test--)
    {
    ll n;
    cin>>n;
    ll ans[n+5]={0};
    
    f(i,1,n+4)
    {
        ll temp=i;
        int flag=0;
        while(temp)
        {   if(temp%10==7)
            flag=1;
            temp=temp/10;
        }
        temp=i;
        while(temp)
        {   if(temp%8==7)
            flag=1;
            temp=temp/8;
        }
        
        
        if(flag)
        {
            ans[i]=ans[i-1];
            
        }
        else
        ans[i]=ans[i-1]+1;
    }
    
    cout<<ans[n];
        
    }

    

    return 0;
}