#include<iostream>
#include <string>       // std::string
#include <iostream>     // std::cout
#include <sstream>
#include <algorithm>    // std::sort
#include <vector>
#define ll long long
using namespace std;

ll conv(ll n)
{
	std::stringstream ss;
	ss << n;
	string s,sc;
	ss>>s;
	sort(s.begin(), s.end());
	sc=s;
	reverse(s.begin(), s.end());

	ll a,b;
		std::stringstream s1,s2;
		s1<<s;
		s2<<sc;
		s1>>a;
		s2>>b;

	return a-b;

}

void solve()
{
	ll n, k;
	cin >> n >> k;
	while(k--)
	{
		n=conv(n);
	}
	cout<<n<<endl;

}

int main()
{	//fio;

	solve();

	//pf("\n\n\n\n"); Time();
	return 0;
}

//#include <bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<unordered_map>
#include<queue>

#define INF 0x3f3f3f3f
#define ll long long
#define LL long long
#define ull unsigned long long
#define endl '\n'
#define ios ios::sync_with_stdio(false);
#define open freopen("in.in","w",stdout);
using namespace std;
const int maxn = 1e5 + 10;
const ll mod = 1e9 + 7;
int a[15],b[15];
int main() {
    int n,k,la=-1;
    cin>>n>>k;
    while(k--){
        if(n==la)break;
        la=n;
        int cnt=0,tmp = n;
        while(tmp){
            a[cnt]=tmp%10;
            b[cnt]=a[cnt];
            cnt++;
            tmp/=10;
        }
        sort(a,a+cnt,less<int>());
        sort(b,b+cnt,greater<int>());
        int p=1;
        tmp=0;
        for(int i=0;i<cnt;i++){
            if(a[i]<b[i]){
                a[i+1]--;
                a[i]=a[i]+10;
            }
            a[i]-=b[i];
            tmp=tmp+p*a[i];
            p*=10;
        }
        n=tmp;
//        cout<<n<<endl;
    }
    cout<<n<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define sc second
#define fr first
#define scl(n) scanf("%lld",&n)
#define scll(n,m) scanf("%lld%lld",&n,&m)
#define scs(ch) scanf("%s", ch)

char ch[200005],tmp[]="110";

ll ckr(ll i,ll j,ll n)
{
    for(; i<n&&j<3; j++,i++)
    {
        if(ch[i]!=tmp[j])return 0;
    }
    return 1;
}

ll cnt(ll i,ll n)
{
    ll z=0;
    while(i<n)
    {
        if(ckr(i,0,n))
        {
            z++;
        }
        else
        {
            return -1;
        }
        i+=3;
    }

    return z;
}
int main()
{
    ll test,t,i,j,k,a,b,c,x,y,z,n,m,ans=0,nn=1e10;
    scl(n);
    scs(ch);
    for(i=0; i<3; i++)
    {
        a=ckr(0,i,n);
        if(a)
        {
            x=cnt(3-i,n);
            //cout<<i<< " " <<x<<endl;
            if(x!=-1)
            {
                ans+=(nn-x);
            }
        }

    }
    printf("%lld\n",ans);

    return 0;
}

//给你一个数x,然后要你找到两个数a,b使得b=x+a,且a,b位数不一样.要你求这样的a,b个数.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=55;
ll x,n,a[N];
ll span[N];//这一位假如进位可以到哪一位.
ll f[N];//到i的时候进位不进位可以有多少种方案数.
ll cnt[N];//记录每一位的大小.
ll possible[N];//可以进位的方案数
int main()
{
    //a+x=b,且a,b位数不能相同,肯定是a存在进位.考虑每次a进位的情况即可?
    cin>>n>>x;
    for(ll i=1;i<=n;i++)   scanf("%lld",&a[i]);
    ll copy=x;
    for(ll i=n;i>=1;i--)
    {
        cnt[i]=copy/a[i];
        copy%=a[i];
    }//记录每一位的大小
    for(ll i=n;i>=1;i--)
    {
        ll num=0;
        for(ll j=i;j<n;j++)
        {
            if(cnt[j]==(a[j+1]/a[j]-1ll)) num++;
            else                          break;
        }span[i-1]=num;
    }//记录我i这一位进位可以跃进到哪一位?
    //for(int i=1;i<=n;i++)   cout<<span[i]<<' ';puts("");
    f[n]=1;possible[n]=1;
//    for(int i=1;i<=n;i++)   cout<<cnt[i]<<' ';puts("");
    for(ll i=n-1;i>=0;i--)
    {
        if(cnt[i])//假如这一位有数字,说明可以进位.
        {
            f[i]+=possible[i+span[i]+1];
        }f[i]+=f[i+1];
        possible[i]=possible[i+span[i]+1]+f[i+1];
    }cout<<f[0]<<endl;
    return 0;
}
//527581354 0 4 0 0 0 0 0 0


//Shrey Dubey

#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<unordered_map>
#include<vector>
#include<set>
#include<list>
#include<iomanip>
#include<queue>
#include<stack>
#include <math.h>
#include<climits>
#include<bitset>
#include<cstring>
#include<numeric>
#include<array>
#include<deque>

using namespace std;
typedef long long ll;
typedef long double ld;

#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define prDouble(x) cout<<fixed<<setprecision(10)<<x //to print decimal numbers
#define pb push_back
#define ff first
#define sec second
#define umap unordered_map
#define mp make_pair
#define KOBE ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fo(n) for(ll i = 0; i<n; i++)
#define fnd(stl, data) find(stl.begin(), stl.end(), data)
#define forn(x,n) for(ll x = 0; x<n; x++)
#define imax INT_MAX
#define lmax LLONG_MAX
#define imin INT_MIN
#define lmin LLONG_MIN
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pair<ll,ll> >
#define vs vector<string>
#define vb vector<bool>
#define pr(t) cout<<t<<"\n"
#define int long long
#define ql queue<ll>
#define qp queue<pair<ll,ll> >
#define endl "\n"
#define nl cout<<"\n"
#define re cin >>
#define pll pair<ll,ll>
#define FOR(a,b) for(ll i = a; i<=b; i++)
#define all(x) x.begin(),x.end()
#define LG 20

// ll dx[] = {1,0,-1,0};
// ll dy[] = {0,1,0,-1};

ll mod = 1e9 + 7;

ll cl(ld a){
    if(a>(ll) a){
        return (ll)a+1;
    }
    else{
        return (ll)a;
    }
}

ll flr(ld a){
    if(a < 0.0){
        return (ll) a - 1;
    }
    return (ll) a;
}

ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//code starts here

ll n,k;

const ll M = 3e6+100;
ll dp[4][M] = {0};
ll pre[4][M] = {0};

void precomp(){
    for(ll i = 1; i<=3; i++){
        for(ll j = i; j<=3*n; j++){
            if(i == 1){
                if(j <= n) dp[i][j] = 1;
            }else{
                if(j <= i*n) dp[i][j] = pre[i-1][j-1];
                if(j <= i*n && j > n) dp[i][j] -= pre[i-1][j-n-1];
            }
            pre[i][j] += pre[i][j-1] + dp[i][j];
        }
    }
    // for(ll i = 1; i<=3; i++){
    //     for(ll j = 1; j<=3*n; j++) cout<<dp[i][j]<<" ";
    //     nl;
    // }
    // nl;
    // for(ll i = 1; i<=3; i++){
    //     for(ll j = 1; j<=3*n; j++) cout<<pre[i][j]<<" ";
    //     nl;
    // }
}

void solve(){
    re n; re k;
    precomp();
    ll tot = 0;
    // ll sm;
    // for(ll i = 3; i<=3*n; i++){
    //     if(tot + dp[3][i] >= k){
    //         sm = i;
    //         break;
    //     }
    //     tot += dp[3][i];
    // }

    for(ll s = 3; s<=3*n; s++){
        if(tot + dp[3][s] >= k){
            // cout<<s<<"()\n";
            k -= tot;
            // cout<<k<<"()()\n";
            ll ct = 0;
            for(ll i = 1; i<=s; i++){
                if(ct + dp[2][s-i] >= k){
                    k -= ct;
                    cout<<i<<" ";
                    ll ct2 = 0;
                    for(ll j = 1; j<=s-i; j++){
                        if(ct2 + dp[1][s-i-j] >= k){
                            cout<<j<<" "<<s-i-j<<"\n";
                            return;
                        }
                        ct2+=dp[1][s-i-j];
                    }
                }
                ct += dp[2][s-i];
            }
        }
        tot += dp[3][s];
    }
}

int32_t main(){
    KOBE;
    ll t;
    t = 1;
    // re t;
    while(t--) solve();
}

//common errors
// row - n, col - m always and loop var
// see the freq of numbers carefully
// see if there's array overflow
// use map for large inputs
// always check for n = 1 condition
// check loop starting and end points :(

//problem ideas
//check piegonhole wherever possible
//there might be many instances of limited answers like 0,1,2 only
// see suffix and prefix
//don't be obsessed with binary search
// try to find repeating pattern in matrices

#pragma GCC optimize ("O3")
#pragma GCC target("avx512f")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    LL(n);
    ll ans=0;
    set<ll> S;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            if((n/i)%2==1)S.insert(n/i);
            if(i%2==1)S.insert(i);
        }
    }
    out(S.size()*2);
}


#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define sz(x) (int)x.size()
#define bit(n, k) (((n) >> (k)) & 1)

const int maxn = 1e2 + 10, mod = 1e9 + 7;

pair<int, int> arr[maxn];
bool mark[maxn];
vector<int> g[maxn];
int n;

void create(double d) {
	memset(mark, 0, sizeof mark);
	for (auto &i : g)
		i.clear();
	for (int i = 0; i < n; i++) {
		if (abs(arr[i].second + 100) < d) {
		   g[102].pb(i);
		   g[i].pb(102);
		}
		if (abs(arr[i].second - 100) < d) {
			g[104].pb(i);
			g[i].pb(104);
		}
		for (int j = i + 1; j < n; j++) {
			int dy = abs(arr[i].second - arr[j].second);
			int dx = abs(arr[i].first - arr[j].first);
			if (sqrt(dx * dx + dy * dy) < d) {
				g[i].pb(j);
				g[j].pb(i);
			}
		}
	}
}

void dfs(int u) {
	if (mark[u])
		return;
	mark[u] = 1;
	for (int v : g[u])
		dfs(v);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> arr[i].first >> arr[i].second;
	double l = 0.5;
	double r = 101;
	for (int i = 0; i < 30; i++) {
		create(2.0 * (r + l) / 2);
		dfs(102);
		if (mark[104])
			r = (r + l) / 2;
		else
			l = (r + l) / 2;
	}
	cout << setprecision(10) << (l + r) / 2;
	return 0;
}

#include <bits/stdc++.h>

// #include <atcoder/all>

using namespace std;
// using namespace atcoder;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
// #define int ll

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

double distance(pii a, pii b) {
    return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
}

signed main() {
    fio();

    int n;
    cin >> n;
    vector<pii> yx(n);
    rep (i, n) cin >> yx[i].second >> yx[i].first;
    sort(all(yx));

    double ok = 0, ng = 100;
    rep (_, 200) {
        double r = (ok + ng) / 2;
        bool update_flag = true;
        vector<bool> dp(n);
        while (update_flag) {
            update_flag = false;
            rep (i, n) {
                if (yx[i].first + 100 < 2 * r) {
                    if (not dp[i]) {
                        dp[i] = true;
                        update_flag = true;
                    }
                }
                rep (j, n) {
                    if (dp[j]) {
                        double dist = distance(yx[i], yx[j]);
                        if (dist < 2 * r) {
                            if (not dp[i]) {
                                dp[i] = true;
                              	update_flag = true;
                            }
                        }
                    }
                }
            }
        }
        bool flag = true;
        rep (i, n) {
            if (dp[i]) {
                if (100 - yx[i].first < 2 * r) {
                    flag = false;
                }
            }
        }
        (flag ? ok : ng) = r;
    }
    Sp(ok);
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
template<class T> void chmax(T& a, T b){
    if(a < b){
        a = b;
    }
}
template<class T> void chmin(T& a, T b){
    if(a > b){
        a = b;
    }
}
int main()
{
    string s;
    cin >> s;
    deque<char>ans;

    bool c = true;
    rep(i,s.size()){
        if(s[i] == 'R')c = !c;
        else{
            if(c){
                if(ans.empty())ans.push_back(s[i]);
                else{
                    if(ans.back() == s[i])ans.pop_back();
                    else ans.push_back(s[i]);
                }
            }

            else{
                if(ans.empty())ans.push_front(s[i]);
                else{
                    if(ans.front() == s[i])ans.pop_front();
                    else ans.push_front(s[i]);
                }
            }
        }
    }

    if(c){
        while(!ans.empty()){
            cout << ans.front();
            ans.pop_front();
        }
    }
    else{
        while(!ans.empty()){
            cout << ans.back();
            ans.pop_back();
        }
    }
    cout << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ll long long
#define pi (3.141592653589)
#define mod 1000000007
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rfo(i, a, b) for (int i = (int)a; i >= (int)b; i--)
#define fo(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define see(x) cout << (x) << endl
#define hh cout << endl
#define INF 1e18
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

template <typename C,
          typename T = std::decay_t<decltype(*begin(std::declval<C>()))>,
          typename std::enable_if<!std::is_same<C, std::string>::value>::type * = nullptr>
std::ostream &operator<<(std::ostream &os, const C &container)
{
    bool first = true;
    std::stringstream ss;
    ss << '[';
    for (const auto &x : container)
    {
        if (!first)
        {
            ss << ", ";
        }
        first = false;
        ss << x;
    }
    ss << ']';
    return os << ss.str();
}
template <class T1, class T2>
std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &p)
{
    os << '{' << p.first << ", " << p.second << '}';
    return os;
}

ll mod_pow(ll a, ll b)
{
    if (b < 0)
        return 0;
    a %= mod;
    if (b == 0)
        return 1;
    if (b == 1)
        return a % mod;
    if (b == 2)
        return ((a % mod) * (a % mod)) % mod;
    return (mod_pow(mod_pow(a, b / 2), 2) * mod_pow(a, b % 2)) % mod;
}

bool isPrime(int n)
{
    if (n == 1)
        return false;
    if (n == 2)
        return true;
    for (int i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
            return false;
    }
    return true;
}

int32_t main()
{
    fast int tc = 1;
    // cin >> tc;
    while (tc--)
    {
        string n, m;
        cin >> n;

        int rot = 0;
        int c = 0;

        deque<char> q;

        fo(i, 0, n.size() - 1)
        {

            if (n[i] == 'R')
            {
                c = 1 - c;
            }
            else
            {

                if (c == 0)
                {

                    if (!q.empty() and q.back() == n[i])
                    {
                        q.pop_back();
                        continue;
                    }
                    q.push_back(n[i]);
                }
                else
                {

                    if (!q.empty() and q.front() == n[i])
                    {
                        q.pop_front();
                        continue;
                    }
                    q.push_front(n[i]);
                }
            }
        }
        // cout << q.pop_back();
        if (c)
        {
            while (!q.empty())
            {
                char c = q.back();
                cout << c;
                q.pop_back();
            }
        }
        else
        {

            while (!q.empty())
            {
                char c = q.front();
                cout << c;
                q.pop_front();
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define     M                     1000000007
#define     ll                    long long
#define     FIO                   ios_base::sync_with_stdio(false);cin.tie(NULL)
#define     ifor(st,lim)          for(int i=st;i<lim;i++)
#define     jfor(stt,llim)        for(int j=stt;j<llim;j++)
#define     pb                    push_back

void solve() {
	int n; cin>>n;
	string s; cin>>s;

	if(s[0] != s[n-1]) {
		cout<<1;
	}else {
		char c = s[0];

		for(int i=1;i<n-2;i++) {
			if(s[i] == s[i+1] and s[i] != c and s[i+1] != c) {
				cout<<2;
				exit(0);
			}else if(s[i] != s[i+1] and s[i] != c and s[i+1] != c) {
				cout<<2;
				exit(0);
			}
		}
		cout<<-1;
	}
}

void file_i_o() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
}
int main(){
	file_i_o();
	FIO;
	int t=1;
	while(t--) {
		solve();
	}
}

#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main(){
  cin>>n>>s;
  if(s[0]!=s[n-1]){
    cout<<1<<endl;
    return 0;
  }
  for(int i=1;i<n-2;i++){
    if(s[0]!=s[i]&&s[i+1]!=s[n-1]){
      cout<<2<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}


#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll,ll> P;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define EFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i, n) FOR(i,0,n)
#define INF 1e12

int main(void){
    ll n,m, ans_max = -INF;
    cin >> n >> m;
    vector<ll> a(n, 0);
    vector<P> root(m);
    vector<ll> ans(n, INF);

    REP(i, n) cin >> a[i];

    REP(i, m) cin >> root[i].first >> root[i].second;

    sort(root.begin(), root.end());

    REP(i, m){
        ll from = root[i].first, to = root[i].second;
        from--; to--;
        ans[to] = min({ans[to], ans[from], a[from]});
    }

    REP(i, n){
        ans_max = max(ans_max, a[i] - ans[i]);
    }
    cout << ans_max << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
// --------------------------------------------------------
template<class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; }
#define FOR(i,l,r) for (ll i = (l); i < (r); ++i)
#define RFOR(i,l,r) for (ll i = (r)-1; (l) <= i; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define COUNT(c,v) count(ALL(c),(v))
#define SZ(c) ((ll)(c).size())
#define BIT(b,i) (((b)>>(i)) & 1)
#define PCNT(b) __builtin_popcountll(b)
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << "l." << __LINE__ << " : " << #x << " = " << (x) << '\n'
ll llceil(ll a, ll b) { return (a + b - 1) / b; }
ll bitlen(ll b) { if (b <= 0) { return 0; } return (64LL - __builtin_clzll(b)); }
string toupper(const string& S) { string T(S); REP(i,SZ(T)) T[i] = toupper(T[i]); return T; }
string tolower(const string& S) { string T(S); REP(i,SZ(T)) T[i] = tolower(T[i]); return T; }
template<class T> void cout_line(const vector<T>& ans, ll l, ll r) { for (ll i = l; i < r; i++) { if (i != l) { cout << " "; } cout << ans[i]; } cout << '\n'; }
template<class T> void debug_line(const vector<T>& ans, ll l, ll r, ll L = 0) { cerr << "l." << L << " :"; for (ll i = l; i < r; i++) { cerr << " " << ans[i]; } cerr << '\n'; }
using P = pair<ll,ll>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VVS = vector<VS>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VVVLL = vector<VVLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VVVB = vector<VVB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
using VLD = vector<ld>;
using VVLD = vector<VLD>;
using VVVLD = vector<VVLD>;
static const double EPS = 1e-10;
static const double PI  = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const ll INF = (1LL << 62) - 1;  // 4611686018427387904 - 1
// --------------------------------------------------------
// #include <atcoder/all>
// using namespace atcoder;

ll pow_mod(ll x, ll n, ll mod) {
    ll res = 1;
    if (n > 0) {
        res = pow_mod(x, n / 2, mod);
        if (n % 2 == 0) res = (res * res) % mod;
        else res = (((res * res) % mod) * x) % mod;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    ll N, M; cin >> N >> M;

    ll ans = (pow_mod(10,N,M*M) - pow_mod(10,N,M)) / M;
    COUT(ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;

    vector<int> god(A + B);

    if (A > B)
    {
        int sum = 0;
        for (int i = 0; i < A; i++)
        {
            god.at(i) = i + 1;
            sum += i + 1;
        }

        for (int i = 0; i < B; i++)
        {
            if (A + i == god.size() - 1)
            {
                god.at(A + i) = sum * (-1);
            }
            else
            {
                god.at(A + i) = (i + 1) * (-1);
                sum += (i + 1) * (-1);
            }
        }
    }
    else
    {
        int sum = 0;
        for (int i = 0; i < B; i++)
        {
            god.at(i) = (i + 1) * (-1);
            sum += (i + 1) * (-1);
        }

        for (int i = 0; i < A; i++)
        {
            if (B + i == god.size() - 1)
            {
                god.at(B + i) = sum * (-1);
            }
            else
            {
                god.at(B + i) = i + 1;
                sum += i + 1;
            }
        }
    }
    for (int i = 0; i < god.size(); i++)
    {
        if (i != god.size() - 1)
            cout << god.at(i) << " ";
        else
            cout << god.at(i) << endl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
    ll t,i,j,k;
    ll a,b;
    cin>>a>>b;
    vector <ll> res;
    if(a>b)
    {
        ll x=(a*(a+1))/2-(b*(b-1))/2;
        for(i=1;i<=a;i++)
            cout<<i<<" ";
        for(i=1;i<b;i++)
            cout<<-i<<" ";
        cout<<-x<<endl;
    }
    else
    {
        ll x=(b*(b+1))/2-(a*(a-1))/2;
        for(i=1;i<=a-1;i++)
            cout<<i<<" ";
        for(i=1;i<=b;i++)
            cout<<-i<<" ";
        cout<<x<<endl;
    }
}


 #include<bits/stdc++.h>
#include<stdlib.h>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<time.h>
#include <cstdio>
#include <iostream>
#include <vector>
#define ll long long
#define int long long
#define inf 0x3f3f3f3f
#define mods 1000000007
#define modd 998244353
#define PI acos(-1)
#define fi first
#define se second
#define lowbit(x) (x&(-x))
#define mp make_pair
#define pb push_back
#define si size()
#define E exp(1.0)
#define fixed cout.setf(ios::fixed)
#define fixeds(x) setprecision(x)
#define IOS ios::sync_with_stdio(false);cin.tie(0)
 using namespace std;
 ll gcd(ll a,ll b){if(a<0)a=-a;if(b<0)b=-b;return b==0?a:gcd(b,a%b);}
template<typename T>void read(T &res){bool flag=false;char ch;while(!isdigit(ch=getchar()))(ch=='-')&&(flag=true);
for(res=ch-48;isdigit(ch=getchar());res=(res<<1)+(res<<3)+ch - 48);flag&&(res=-res);}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll qp(ll a,ll b,ll mod){ll ans=1;if(b==0){return ans%mod;}while(b){if(b%2==1){b--;ans=ans*a%mod;}a=a*a%mod;b=b/2;}return ans%mod;}//快速幂%
ll qpn(ll a,ll b, ll p){ll ans = 1;a%=p;while(b){if(b&1){ans = (ans*a)%p;--b;}a =(a*a)%p;b >>= 1;}return ans%p;}//逆元   (分子*qp(分母,mod-2,mod))%mod;

map<string,ll>sb;

 string b[222222];
signed main(){

ll n;
read(n);
for(int i=1;i<=n;i++){

    cin>>b[i];
    //string c="!";
    if(b[i][0]!='!'){
   // c=c+b[i];
    //sb[c]++;
    continue;
    }
    else{
        sb[b[i]]++;
    }
}

for(int i=1;i<=n;i++){
 if(b[i][0]!='!'){
    string c="!";
    c=c+b[i];
    if(sb[c]!=0){
        cout<<b[i];
        return 0;
    }

 }

}

cout<<"satisfiable";

}

#include <bits/stdc++.h>
using namespace std;

int main() {
  int i, N, sum=0;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  for (i = 0; i < N; i++) {
  	cin >> A.at(i);
  }
  for (i = 0; i < N; i++) {
  	cin >> B.at(i);
  }
  for(i = 0; i < N; i++) {
    sum += A.at(i) * B.at(i);
  }
  if(sum == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


#include <bits/stdc++.h>
using namespace std;

int main(){
 string n; cin>>n;
  int k; cin>>k;
  string A=n;
  int a=stoi(n);
  sort(n.begin(),n.end());
  string g2=n;
  reverse(n.begin(),n.end());
  string g1=n;

  for(int i=1;i<=k;i++){
     sort(A.begin(),A.end());
    g2=A;
    reverse(A.begin(),A.end());
    g1=A;
    a=stoi(g1)-stoi(g2);
    A=to_string(a);
  }

  cout<<a<<endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define rrep(i,a,b) for(int i = a ; i < b ; i++)

int n ;
double A[100007] , S[100007] ;

double calculation(double x){
    auto it = upper_bound(A,A+n,2*x) ;
    int i = it - A ;
    return (S[n] + n * x - S[i] - (n - i) * 2 * x) / n ;
}

int main(){
    cin >> n ;
    rep(i,n) cin >> A[i] ;
    sort(A,A+n) ;
    rep(i,n) S[i+1] = S[i] + A[i] ;
    int cnt = 10000 ;
    double lef = 0 , rig = 1e12 ;
    while(cnt > 0){
        double x = (lef * 2 + rig) / 3 , y = (rig * 2 + lef) / 3 ;
        if(calculation(x) < calculation(y)) rig = y ;
        else lef = x ;
        cnt-- ;
    }
    cout << setprecision(10) << calculation(rig) << endl ;
}


#include <bits/stdc++.h>

using namespace std;

int cnt[1000];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("file.inp","r",stdin);
    string s;
    cin >> s;
    int n = s.size();

    long long ans = 0;
    for (int i = n - 1; i >= 2; i--)
    {
        cnt[s[i]]++;
        if (s[i] != s[i - 1] && s[i - 2] == s[i - 1])
        {
            ans += n - i - cnt[s[i - 2]];
            for (int i = 'a'; i <= 'z'; i++)
                cnt[i] = 0;
            cnt[s[i - 2]] = n - i;
        }
    }
    cout << ans;
    return 0;
}

#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <variant>
#include <sstream>
#include <memory>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())
#define sz(v) ((int)(v).size())

#define vec1d(x) vector<x>
#define vec2d(x) vector<vec1d(x)>
#define vec3d(x) vector<vec2d(x)>
#define vec4d(x) vector<vec3d(x)>

#define ivec1d(x, n, v) vec1d(x)(n, v)
#define ivec2d(x, n, m, v) vec2d(x)(n, ivec1d(x, m, v))
#define ivec3d(x, n, m, k, v) vec3d(x)(n, ivec2d(x, m, k, v))
#define ivec4d(x, n, m, k, l, v) vec4d(x)(n, ivec3d(x, m, k, l, v))

#ifdef LOCAL
#include "pretty_print.h"
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

#define nl "\n"

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; }

auto random_address = [] { char *p = new char; delete p; return (uint64_t) p; };
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1));
mt19937_64 rngll(chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1));

int powmod(int a, int b, int mod) {
    if (b == 0) {
        return 1 % mod;
    }
    ll r = powmod(a, b >> 1, mod);
    r = r * r % mod;
    r = (b & 1)? r * a % mod : r;
    return r;
}

int main(int /* argc */, const char** /* argv */)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef LOCAL
    assert(freopen("i.txt", "r", stdin));
    assert(freopen("o.txt", "w", stdout));
#endif

    string s;
    while (cin >> s) {
        int n = s.size();
        reverse(all(s));
        map<char, int> m;

        ll ans = 0;
        for (int i = 0; i < n; ++i) {
            if (i && s[i] == s[i - 1]) {
                ans += i - m[s[i]];
                m.clear();
                m[s[i]] = i + 1;
            } else {
                ++m[s[i]];
            }
        }
        cout << ans << nl;
    }

#ifdef LOCAL
    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
#endif
    return 0;
}


#include <bits/stdc++.h>

#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i, n) for(ll i=n-1;i>=0;--i)
#define rep1(i, n) for(ll i=1; i<=n; ++i)
#define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();++itr)
#define rrepitr(itr, mp) for(auto itr = mp.rbegin(); itr!=mp.rend(); ++itr)
#define ALL(a) (a).begin(),(a).end()

template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

using namespace std;
using ll  = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;
const double PI = 3.1415926535897932384626;

ll mod(ll a, ll m){return (a + m) % m;}

int main(){
    ll h, w;
    cin >> h >> w;

    ll a[h][w];
    rep(i, h)rep(j, w){
        char c;
        cin >> c;
        if(c == '+')a[i][j] = 1;
        else a[i][j] = -1;
    }

    ll dp[h][w];
    rrep(i, h)rrep(j, w){
        int turn = (i + j) % 2;
        if(turn)dp[i][j] = INF;
        else dp[i][j] = -INF;

        if(i + 1 >= h && j + 1 >= w)dp[i][j] = 0;

        if(i + 1 < h){
            if(turn)chmin(dp[i][j], dp[i+1][j] - a[i+1][j]);
            else chmax(dp[i][j], dp[i+1][j] + a[i+1][j]);
        }

        if(j + 1 < w){
            if(turn)chmin(dp[i][j], dp[i][j+1] - a[i][j+1]);
            else chmax(dp[i][j], dp[i][j+1] + a[i][j+1]);
        }
    }

    if(dp[0][0] > 0)cout << "Takahashi";
    else if(dp[0][0] < 0)cout << "Aoki";
    else cout << "Draw";
}

#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define int long long

#pragma region Debugger
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
//void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#pragma endregion Debugger

void start()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int maxm(int a, int b)
{
	return (a > b) ? a : b;
}
int A[2001][2001];
int dp[2001][2001];
int h, w;
int func(int i, int j)
{
	if ((i == h - 1) && (j == w - 1))
	{
		return 0;
	}
	if (i == h - 1)
	{
		if (dp[i][j] != INT_MIN)
		{
			return dp[i][j];
		}
		dp[i][j] = A[i][j + 1] - func(i, j + 1);
		return dp[i][j];
	}
	if (j == w - 1)
	{
		if (dp[i][j] != INT_MIN)
		{
			return dp[i][j];
		}
		dp[i][j] = A[i + 1][j] - func(i + 1, j);
		return dp[i][j];
	}

	if (dp[i][j] != INT_MIN)
	{
		return dp[i][j];
	}

	dp[i][j] = maxm(A[i][j + 1] - func(i, j + 1) , A[i + 1][j] - func(i + 1, j));
	return dp[i][j];

}
int32_t main()
{
	start();
	cin >> h >> w;
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			dp[i][j] = INT_MIN;;
		}
	}
	memset(A, -1, sizeof(A));
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			char ch;
			cin >> ch;
			if (ch == '+')
			{
				A[i][j] = 1;
			}
		}
	}
	int ans = func(0, 0);
	if (ans > 0)
	{
		cout << "Takahashi" << "\n";
	}
	else if (ans < 0)
	{
		cout << "Aoki" << "\n";
	}
	else
	{
		cout << "Draw" << "\n";
	}
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define eb emplace_back
using namespace std;
template <class T = int>
using V = vector<T>;
template <class T = int>
using VV = V<V<T>>;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<ld,ld>;

const int mod = 998244353;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if(!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if(t&1) a *= *this;
        return a;
    }

    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h, w;
    cin >> h >> w;
    V<string> f(h);
    rep(i,h) cin >> f[i];
    mint ans = 1;
    rep(i,h+w-1){
        int y = min(w-1, i);
        int x = i-y;
        //cout << x << y << endl;
        V<int> cnt(3);
        while(1){
            if(x >= h || y < 0) break;
            if(f[x][y] == 'R') cnt[0]++;
            if(f[x][y] == 'B') cnt[1]++;
            if(f[x][y] == '.') cnt[2]++;
            x++, y--;
        }
        int c = 0;
        rep(j,3) if(cnt[j] > 0) c++;
        //cout << c << endl;
        if(c == 3){
            cout << 0 << endl;
            return 0;
        }
        if(c == 2 && cnt[2] == 0){
            cout << 0 << endl;
            return 0;
        }
        if(c == 1 && cnt[2] > 0) ans *= 2;
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define REPP(i,a,b,d) for(int i=(a);i<=(int)(b);i+=(d))
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=(a);i>=(int)(b);i-=(d))
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) for(int i=0; i<(int)(a); i++)
#define FORD(i,a) for(int i=(int)(a)-1; i>=0; i--)
#define pb push_back
typedef long long ll;

const int N = 3005;
const ll MOD = 998244353;
int n, k;
ll memo[N][N];

ll dp(int n, int m) {
	if(n < m) return 0;
	if(m == 0) return (n == 0);
	ll &ret = memo[n][m];
	if(ret != -1) return ret;
	return ret = (dp(n, 2*m) + dp(n-1, m-1)) % MOD;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> k;
	memset(memo, -1, sizeof memo);
	cout << dp(n, k) << '\n';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

using LL = __int128;
istream& operator>>(istream& is, LL& v)
{
    string s;
    is >> s;
    v = 0;
    for (int i = 0; i < (int)s.size(); i++) {
        if (isdigit(s[i])) { v = v * 10 + s[i] - '0'; }
    }
    if (s[0] == '-') { v *= -1; }
    return is;
}

ostream& operator<<(ostream& os, const LL& v)
{
    if (v == 0) { return (os << "0"); }
    LL num = v;
    if (v < 0) {
        os << '-';
        num = -num;
    }
    string s;
    for (; num > 0; num /= 10) { s.push_back((char)(num % 10) + '0'); }
    reverse(s.begin(), s.end());
    return (os << s);
}

LL parse(string &s) {
  LL ret = 0;
  for (int i = 0; i < (int)s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}

int main(){

    string X;
    cin >> X;
    ll M;
    cin >> M;

    ll N = X.size();

    if(N == 1){
        ll x = X[0] - '0';
        if(x <= M){
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
        }
        return 0;
    }

    ll d = 0;
    for(auto x: X){
        chmax(d, ll(x - '0'));
    }

    ll ok = d;
    ll ng = (ll)1e18+1;

    while(ng-ok > 1){
        ll md = (ok+ng)/2;
        LL res = 0;
        string ma = "1000000000000000005";
        LL MA = parse(ma);

        REP(i, N){
            if(res >= MA){
                ng = md;
                goto HELL;
            }
            res *= md;
            ll v = X[i] - '0';
            res += v;
        }

        if(res <= M) ok = md;
        else ng = md;

        HELL:;
    }

    cout << ok - d << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
string x;
int d;
long long m,sum,cnt,rt;
long long calc(long long base){
	sum=0;
	for(int i=0;i<x.size();i++){
		if(sum>(m/base)) return m+1;
		sum*=base;
		sum+=(x[i]-'0');
		if(sum>m) return m+1;
	}
	return sum;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>x>>m;
	d=0;
	for(int i=0;i<x.size();i++) d=max(d,x[i]-'0');
	if(x.size()==1){
		if(x[0]-'0'<=m)
			cout<<1<<endl;
		else
			cout<<0<<endl;
		return 0;
	}
	if(m<=d){
		cout<<0<<endl;
		return 0;
	}
	if(x.size()==2){
		long long ri=(m-(long long)(x[1]-'0'))/(long long)(x[0]-'0');
		cout<<max(ri-d,0LL)<<endl;
		return 0;
	}
	if(x.size()==3){
		long long a=x[0]-'0',b=x[1]-'0',c=x[2]-'0';
		//an^2+bn+c
		long long le=d+1,ri=sqrt(m/a),mid,f;
		while(le<ri){
			mid=(le+ri+1)/2;
			f=a*mid*mid+b*mid+c;
			if(f>m) ri=mid-1;
			else le=mid;
		}
		cout<<max(le-d,0LL)<<endl;
		return 0;
	}
	else{
		for(int i=d+1;;i++){
			rt=calc(i);
			if(rt>m) break;
			cnt++;
		}
		cout<<cnt<<endl;
		return 0;
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define repd(i, a, b) for (int i = a; i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template <typename H>
bool chmin(H &v1, const H v2)
{
    if (v1 > v2)
    {
        v1 = v2;
        return true;
    }
    return false;
}
template <typename H>
bool chmax(H &v1, const H v2)
{
    if (v1 < v2)
    {
        v1 = v2;
        return true;
    }
    return false;
}
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const ll m = 1e9 + 7;

ll powm(ll b, ll p)
{
    if (p == 0)
        return 1;
    if (p % 2 == 1)
        return b * powm(b, p - 1) % m;
    else
    {
        ll t = powm(b, p / 2);
        return t * t % m;
    }
}

int main()
{
    int a, b;
    cin >> a >> b;

    for (int i = b / 2; i > 1; i--)
    {
        if (((a / i) + (a % i != 0) + 1) * i <= b)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << "1" << endl;
}

#include <bits/stdc++.h>

int main(){
    long long l, r;
    std::cin >> l >> r;
    if(l == r){
        std::cout << "0\n";
        return 0;
    }

    long long res = 0;

    std::vector<long long> vec(r - l + 1);
    for(long long i = r - l; i > 1; i--){
        long long cnt = r / i - (l - 1) / i;
        cnt = cnt * (cnt - 1) / 2;

        for(long long j = i * 2; j <= r - l; j += i){
            cnt -= vec[j];
        }

        vec[i] = cnt;
        if(l <= i) res += cnt - r / i + 1;
        else res += cnt;
    }

    std::cout << res * 2 << "\n";
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;

#define rep(i, a, b) for (int i = a; i < b; i++)

bool check7(int a, int base){
    while(a > 0){
        if (a % base == 7)
            return true;
        a /= base;
    }
    return false;
}

void solve()
{
    int n;
    cin >> n;

    unordered_set<int> svns;
    rep(i, 1, n+1){
        if (check7(i, 10)) svns.insert(i);
        else if (check7(i, 8)) svns.insert(i);
    }

    cout << n - svns.size() << endl;
}

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    // int t;
    // cin >> t;
    // while(t--)
        solve();
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define fastrun ios_base::sync_with_stdio;cin.tie(nullptr);cin.tie(nullptr);
typedef long long int ll;
#define t int t;cin>>t;while(t--)
#define For(n) for(int i=0;i<n;i++)
#define INT(a) int a;scanf("%d",&a);
#define LLI(a) ll a;scanf("%lld",&a);
#define DOUBLE(a) double a;scanf("%f",&a);
bool great(pair<int,int>a,pair<int,int>b){
	return (a.first<b.first);
}
int search(vector<int> v,int size,int a){
	int l =0,r=size-1;
	int result = size;
	while(l<=r){
		int mid = (l+r)/2;
		if(v[mid]>a){
			result = mid;
			r=mid-1;
		}
		else{
			l = mid+1;
		}
	}
	return result;
}
template<class c>
c gcd (c a,c b){
	if(b==0)
		return a;
	gcd(b,a%b);
}
bool check(ll a,ll b,ll c,ll d){
	return ((a+b==c+d)||(a-b==c-d)||(abs(a-c)+abs(b-d)<=3));
}
int solve(ll a,ll b,ll c,ll d){
	if(a>c){
		swap(a,c);
		swap(b,d);
	}if(a==c&&b==d)
		return 0;
	else if(check(a,b,c,d))
		return 1;
	else if((a+b)%2==(c+d)%2)
		return 2;
	for(int i=-2;i<=2;i++){
		for(int j=-2;j<=2;j++){
			ll p = c+i;ll q = d+j;
			if(check(a,b,p,q))
				return 2;
		}
	}if((check(a,b,c+3,d)||check(a,b,c-3,d)||check(a,b,c,d+3)||check(a,b,c+3,d)))
		return 2;
	return 3;
}
int main(){
	fastrun
	LLI(a)LLI(b)LLI(c)LLI(d)
	printf("%d\n",solve(a,b,c,d));
}


#include<bits/stdc++.h>
using namespace std;
#ifdef local
string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
typedef long long ll;
#define f(i, l, r) for(int i=l;i<=r;i++)
#define rf(i, r, l) for(int i=r;i>=l;--i)
#define all(x) x.begin(),x.end()
const int N = 2e5+10, mod = 1e9+7;
ll power(ll a, ll b) {ll res = 1;while (b) {if (b & 1)res = res * a % mod;a = a * a % mod;b >>= 1;}return res;}
ll INV(ll a){return power(a,mod-2);}
mt19937 Rand(123456);
int Range(int l,int r){
    return l+Rand()%(r-l+1);
}
vector<int> g[N];
int dis[N];
int T,D;
int mx_dep[N],ans[N];
void dfs(int u,int f){
    if(dis[u]>D){
        D=dis[u];T=u;
    }
    mx_dep[u]=dis[u];
    for(int v:g[u])if(v!=f){
        dis[v]=dis[u]+1;
        dfs(v,u);
        mx_dep[u]=max(mx_dep[u],mx_dep[v]);
    }
}
int sz[N];
int step;
void dfs2(int u,int f){
    debug(u,dis[u]);
    sort(all(g[u]),[&](int l,int r){
       return  mx_dep[l]<mx_dep[r];
    });
    ans[u]=++step;
    for(int v:g[u])if(v!=f){
        dfs2(v,u);
    }
    step++;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef local
    freopen("../in.txt", "r", stdin);
#endif
    int n;cin>>n;
    f(i,1,n-1){
        int u,v;cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    D=-1;dfs(1,0);
    D=-1;int k=T;dis[k]=1;dfs(T,0);
    dfs2(k,0);
    f(i,1,n)cout<<ans[i]<<" ";
}

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N;
vector<vector<int>> edges;
vector<bool> ondiameter;
vector<int> ans;

pii far(int u, int prev, int d) {
    int node = u, dis = 0;
    for (int v : edges[u]) {
        if (v == prev)
            continue;
        pii temp = far(v, u, d + 1);
        if (dis < temp.second + 1) {
            dis = temp.second + 1;
            node = temp.first;
        }
    }
    return make_pair(node, dis);
}

bool tag(int u, int prev, int target) {
    if (u == target)
        return true;
    for (int v : edges[u]) {
        if (v == prev)
            continue;
        if (tag(v, u, target)) {
            ondiameter[u] = true;
            return true;
        }
    }
    return false;
}

int t = 1;
void solve(int u, int prev) {
    ans[u] = t;
    for (int v : edges[u]) {
        if (v == prev || ondiameter[v])
            continue;
        t++;
        solve(v, u);
    }
    for (int v : edges[u]) {
        if (v != prev && ondiameter[v]) {
            t++;
            solve(v, u);
        }
    }
    t++;
}

int main() {
    cin >> N;
    ondiameter.resize(N + 1);
    edges.resize(N + 1);
    ans.resize(N + 1);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    // find diameter
    pii a = far(1, 1, 0);
    pii b = far(a.first, a.first, 0);
    tag(a.first, a.first, b.first);
    solve(a.first, a.first);
    for (int i = 1; i <= N; i++) {
        cout << ans[i] << " ";
    }
    cout << endl;
}


#include<bits/stdc++.h>

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define PB push_back
#define MP make_pair
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
typedef long double Lf;
typedef pair<int, int> pii;

int n, k;
ll ans;

inline int func(int x){
	return max(0, min(n, x - 1) - max(x - n, 1) + 1);
}

int main(){
	scanf("%d%d", &n, &k);

	REP(x, 2, n * 2){
		int y = x - k;
		ans += 1ll * func(x) * func(y);
	}

	printf("%lld\n", ans);
	return 0;
}

#include <vector>
#include <set>
#include <iostream>
#include <algorithm>
#include <string>
#include <utility>

#define mod % 998244353
#define MAX 998244353
#define ll long long
using namespace std;

int main() {
  int high,wide,k;
  cin >> high;
  cin >> wide;
  cin >> k;
  ll ans = 0;
  if(high == wide and high == 1){
    cout << k mod << endl;
    return 0;
  }
  if(high == 1 or wide == 1){
    if(wide == 1){
      wide = high;
    }
    for(int i = 1;i <= k;i ++){
      int m = wide;
      vector<ll> mul(21);
      vector<ll> mult(21);
      mul[0] = i;
      mult[0] = i-1;
      ll pl = 1;
      ll plt = 1;
      for(int j = 0;j < 20;j++){
        mul[j+1] = (mul[j]*mul[j])mod;
        mult[j+1] = (mult[j]*mult[j])mod;
        if(m % 2 == 1){
          pl = (pl*mul[j])mod;
          plt = (plt*mult[j])mod;
        }
        m = m/2;
      }
      ans = (ans+MAX+pl-plt)mod;
    }
    cout << ans mod << endl;

    return 0;
  }

  for(int i = 1;i <= k;i ++){
    ll pl = 1;
    int m = wide;
    vector<ll> mul(21);
    mul[0] = k-i+1;
    for(int j = 0;j < 20;j ++){
      mul[j+1] = (mul[j]*mul[j])mod;
      if(m % 2 == 1){
        pl = (pl*mul[j]) mod;
      }
      m = m/2;
    }

    ll kakerua = 1;
    ll kakerub = 1;

    if(i == 1){
      kakerub = 0;
    }
    m = high;
    vector<ll> mult(21);
    mul[0] = i;
    mult[0] = i-1;
    for(int j = 0;j < 20;j ++){
      mul[j+1] = (mul[j]*mul[j])mod;
      mult[j+1] = (mult[j]*mult[j])mod;
      if(m % 2 == 1){
        kakerua = (kakerua*mul[j])mod;
        kakerub = (kakerub*mult[j])mod;
      }
      m = m/2;
    }
    kakerua = (MAX-kakerub+kakerua)mod;
    pl = (pl*kakerua)mod;
    ans = (ans +pl)mod;
  }
  cout << ans mod<< endl;

  return 0;
}


#include <bits/stdc++.h>
#include <math.h>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

struct UnionFind {
    vector<int> par;
    vector<int> siz;
    vector<map<int, int>> mp;

    UnionFind(int n, vector<int>& C)
        : par(n, -1)
        , siz(n, 1)
    {
        rep(i, n)
        {
            map<int, int> tmp;
            tmp[C[i]] = 1;
            mp.push_back(tmp);
        }
    }

    bool merge(int x, int y)
    {
        int rx = root(x), ry = root(y);
        if (rx == ry)
            return false; //既にmerge済み
        if (siz[rx] < siz[ry])
            swap(rx, ry);

        par[ry] = rx;
        siz[rx] += siz[ry];
        for (auto p : mp[ry]) {
            mp[rx][p.first] += p.second;
        }
        return true;
    }

    int query2(int x, int y)
    {
        int rx = root(x);
        if (mp[rx].count(y))
            return mp[rx][y];
        else
            return 0;
    }

    int size(int x)
    {
        return siz[root(x)];
    }

    int root(int x)
    {
        if (par[x] == -1)
            return x;
        else
            return par[x] = root(par[x]);
    }
};

int main()
{
    int N, Q;
    cin >> N >> Q;
    vector<int> C(N);
    rep(i, N)
    {
        cin >> C[i];
    }
    UnionFind uf(N, C);
    rep(i, Q)
    {
        int type, a, b;
        cin >> type >> a >> b;
        if (type == 1) {
            a--, b--;
            uf.merge(a, b);
        } else {
            a--;
            cout << uf.query2(a, b) << endl;
        }
    }
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define mod 1000000007
using namespace std;
int n,q;
int C[200005];
map<int,int> vec[200005];
int fa[200005];
int fnd(int x){
	return fa[x]==x?fa[x]:fa[x]=fnd(fa[x]);
}
void merge(int x,int y){
	x=fnd(x);y=fnd(y);
	if(x==y) return;
	if(vec[x].size()<vec[y].size()) swap(x,y);
	for(map<int,int>::iterator it=vec[y].begin();it!=vec[y].end();it++)
		vec[x][it->fi]+=it->se;
	vec[y].clear();
	fa[y]=x;
}
int main(){
	scanf("%d %d",&n,&q);
	for(int i=1;i<=n;i++) scanf("%d",&C[i]),fa[i]=i,vec[i][C[i]]=1;
	for(int i=1;i<=q;i++){
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		if(a==1){
			merge(b,c);
		}
		else{
			b=fnd(b);
			if(vec[b].find(c)==vec[b].end()) puts("0");
			else printf("%d\n",vec[b][c]);
		}
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
using   ll = long long;
using   ld = long double;

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define pb                  push_back
#define type                  make_pair
#define F                   first
#define S                   second
#define pll                 pair<int , int>
#define int                 long long int
#define endl                "\n"

#define ALL(v)              v.begin(),v.end()
#define ALLR(v)             v.rbegin(),v.rend()
#define pii                 3.14159265358979323
#define inf                 LLONG_MAX
#define ones(x)             __builtin_popcount(x)
#define fill(a,b)           memset(a,b,sizeof(a))
#define mod                 1000000007
#define hell                998244353

ll mod_pow(ll a,ll b,ll m)
{
    ll res = 1;
    while(b)
    {
        if(b&1)
        {
                res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(int a , int m)
{
        return mod_pow(a , m - 2 , m);
}

void solve()
{
        int n;

        cin >> n;

        int a[n];

        for(int i = 0; i < n; ++i) {
                cin >> a[i];
        }

        sort(a , a + n);

        int res = a[0] * a[0];
        int prev = 0;

        res %= hell;

        int dp[n + 5] {};

        dp[1] = a[0];

        for(int i = 2; i <= n; ++i) {
                dp[i] = dp[i - 2] * 2 + a[i - 2] + a[i - 1];
                dp[i] %= hell;

                res += (dp[i] * a[i - 1]) % hell;
                res %= hell;

                dp[i] += dp[i - 1];
                dp[i] %= hell;
        }

        cout << res << endl;
}

signed main() {
        fast;

        int t = 1;

        // cin >> t;

        while(t--) {
                solve();
        }

        return 0;
}

#include <bits/stdc++.h>

const long long INF = 1e9;
const long long MOD = 1e9 + 7;
//const long long MOD = 998244353;
const long long LINF = 1e18;
using namespace std;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define COUT(x) cout<<(x)<<endl
#define SCOUT(x) cout<<(x)<<" "
#define VECCOUT(x) for(auto&youso_: (x) )cout<<right<<setw(10)<<youso_<<" ";cout<<endl
#define ENDL cout<<endl
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) long long __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define mp make_pair
#define PQ priority_queue<long long>
#define PQG priority_queue<long long,V,greater<long long>>

typedef long long ll;
typedef vector<long long> vl;
typedef vector<long long> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef pair<long long, long long> pll;

#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
template<class T>
void mod(T &x) {
    x %= MOD;
    x += MOD;
    x %= MOD;
}

ll GCD(ll a, ll b) {
    if(b == 0) return a;
    else return GCD(b, a%b);
}

struct COMB{
    vl fact, fact_inv, inv;
    void init_nCk(long long SIZE) {
        fact.resize(SIZE + 5);
        fact_inv.resize(SIZE + 5);
        inv.resize(SIZE + 5);
        fact.at(0) = fact.at(1) = fact_inv.at(0) = fact_inv.at(1) = inv.at(1) = 1;
        for(long long i = 2; i < SIZE + 5; i++) {
            fact.at(i) = fact.at(i - 1)*i%MOD;
            inv.at(i) = MOD - inv.at(MOD%i)*(MOD/i)%MOD;
            fact_inv.at(i) = fact_inv.at(i - 1)*inv.at(i)%MOD;
        }
    }
    long long nCk (long long n, long long k) {
        assert(!(n < k));
        assert(!(n < 0 || k < 0));
        return fact.at(n)*(fact_inv.at(k)*fact_inv.at(n - k)%MOD)%MOD;
    }
};
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if(b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a/b*x;
    return d;
}

void Main() {
    LCIN(N);
    vector<string> S(N);
    VECCIN(S);
    ll ans = 1;
    for(int i = 0; i < N; i++) {
        if(S.at(i) == "OR") {
            ans += (ll)((ll)1 << (i + 1));
        }
    }
    cout << ans << endl;
}

int main() {
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

char mp[110][110];
int n, m;

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%s", mp[i] + 1);
	}
	int ans = 0;
	for (int i = 2; i <= n; i++) {
		int pre = 0;
		for (int j = 1; j <= m; j++) {
			if (mp[i][j] != mp[i - 1][j]) {
				int now;
				if (mp[i][j] == '#')now = 1;
				else now = 2;
				if (pre != now) {
					ans++;
					pre = now;
				}
			}
			else {
				pre = 0;
			}
		}
	}
	for (int j = 2; j <= m; j++) {
		int pre = 0;
		for (int i = 1; i <= n; i++) {
			if (mp[i][j] != mp[i][j - 1]) {
				int now;
				if (mp[i][j] == '#')now = 1;
				else now = 2;
				if (pre != now) {
					ans++;
					pre = now;
				}
			}
			else {
				pre = 0;
			}
		}
	}
	printf("%d\n", ans);
}

#include <bits/stdc++.h>

// #include <iostream>
// #include <vector>
// #include <algorithm>
// #include <stdio.h>
// #include <math.h>
// #include <string>
// #include <cctype>
// #include <map>
// #include <queue>
// #include <limits>
// #include <iomanip>
// #include <sstream>
// #include <cstdlib>
// #include <locale>
// #include <bitset>
// #include <set>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,n) for(int i = n-1; i >= 0; i--)
#define ll long long
#define P pair<int, int>

#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif

const double PI = acos(-1);

unsigned GetDigit(unsigned num) { return log10(num)+1; }

int main()
{
	int h, w;
	cin >> h >> w;

	vector< vector<char> > s(h, vector<char>(w));
	rep(i, h) rep(j, w) cin >> s.at(i).at(j);

	int ans = 0;
	for (int i = 1; i < h; i++)
	{
		for (int j = 1; j < w; j++)
		{
			ans += (
				(s.at(i-1).at(j-1) == '#') +
				(s.at(i).at(j-1) == '#') +
				(s.at(i-1).at(j) == '#') +
				(s.at(i).at(j) == '#')) % 2;
		}
	}

	cout << ans << endl;
}


/*
    author : aryan57
    created : 01-May-2021 18:08:02 IST
*/
#include <bits/stdc++.h>
using namespace std;

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

#define int long long
#define X first
#define Y second
#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define F(i, a, b) for (int i = a; i <= b; i++)
#define RF(i, a, b) for (int i = a; i >= b; i--)

const int mxn = 1e5;
const long long INF = 2e18;
const int32_t M = 1000000007;
// const int32_t M = 998244353;
const long double pie = acos(-1);

void solve_LOG()
{
    string n;
    cin>>n;

    int cnt=0;

    F(i,0,sz(n)-4)
    {
        if(n.substr(i,4)=="ZONe")cnt++;
    }

    cout<<cnt;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
#ifdef ARYAN_SIEVE
    sieve();
#endif
#ifdef ARYAN_SEG_SIEVE
    segmented_sieve();
#endif
#ifdef ARYAN_FACT
    fact_init();
#endif
    // cout<<fixed<<setprecision(10);
    int _t=1;
    // cin>>_t;
    for (int i=1;i<=_t;i++)
    {
        // cout<<"Case #"<<i<<": ";
        solve_LOG();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {
  string S;
  cin >> S;

  int count = 0;

  for (int i = 0; i < 12; i++) {
    if(i < 12 && S.at(i)=='Z') {
      if(i < 11 && S.at(i + 1)=='O') {
        i++;
        if(i < 11 && S.at(i + 1)=='N') {
          i++;
          if(i < 11 && S.at(i + 1)=='e') {
            i++;
            count++;
          }
        }
        else  continue;
      }
      else continue;
    }
  }

  cout << count << endl;

}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>

typedef long long ll;
#define For(i,a,b) for(ll i = a ; i <= b ; i ++)
#define FoR(i,a,b) for(ll i = a ; i >= b ; i --)
ll MAX(ll a , ll b) {
	return (a > b ? a : b);
}
ll MIN(ll a , ll b) {
	return (a < b ? a : b);
}

using namespace std;

ll N , K;
ll cnt_S(ll s) {
	ll l = MAX(1 , s - 2 * N);
	ll r = MIN(s - 2 , N);
	ll mid = s - N - 1;
	//printf ("**%lld %lld %lld " , l , mid , r);
	if (mid < l)
		return (r - l + 1) * (2 * mid + 2 * N - l - r) / 2;
	else if (mid > r)
		return (r - l + 1) * (- 2 * mid + 2 * N + l + r) / 2;
	else
		return (mid - l + 1) * (l + 2 * N - mid) / 2 + (r - mid + 1) * (-r + 2 * N + mid) / 2 - N;
}

int main() {
	cin >> N >> K;
	For (s , 3 , N * 3) {
		ll w = cnt_S(s);
		//printf ("%lld %lld %lld\n" , s , w , K);
		if (K - w <= 0) {
			For (i , 1 , N) {
				ll l = MAX(1 , s - i - N);
				ll r = MIN(N , s - i - 1);
				ll m = MAX(r - l + 1 , 0);
				//printf ("^_^%d %d %d %d\n" , s , i , m , K);
				if (K - m <= 0)
					return (printf ("%lld %lld %lld" , i , K + l - 1LL , s - i - K - l + 1LL) , 0);
				K -= m;
			}
		}
		K -= w;
	}
	return 0;
}

#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pl = pair<ll, ll>;
constexpr int MX = 5005, MOD = 998244353;

pl DP[MX][2];

int main() {
	if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
	cin.tie(0)->sync_with_stdio(0);

	int N, M; cin >> N >> M;
	ll ans = 0;
	for (int i = 1; i <= M; ++i) {
		DP[0][0] = pl(0, M-1), DP[0][1] = pl(1, 1);
		for (int j = 0; j < N-1; ++j) {
			DP[j+1][0] = pl((M-1)*DP[j][0].f+(i-1)*DP[j][1].f, (M-1)*DP[j][0].s+(i-1)*DP[j][1].s);
			DP[j+1][1] = pl(DP[j][0].f+DP[j][0].s+(M-i+1)*DP[j][1].f, DP[j][0].s+(M-i+1)*DP[j][1].s);
			DP[j+1][0].f %= MOD, DP[j+1][0].s %= MOD;
			DP[j+1][1].f %= MOD, DP[j+1][1].s %= MOD;
		}
		(ans += DP[N-1][0].f+DP[N-1][1].f) %= MOD;
	}
	cout << ans;
}


/*
मनस्वी म्रियते कामं कार्पण्यं न तु गच्छति ।
अपि निर्वाणमायाति नानलो याति शीतताम् ॥
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define mod 1000000007
#define pb push_back
#define ll long long int
#define ull unsigned ll
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define p2d(v) for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v) for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v) for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse
#define itr iterator
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
#define test3(x,y,z) cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define test4(w,x,y,z) cout << #w " = " << w << " " << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

/*
const ll infinity = 9e18;

bool compare(ll a,ll b) {return a > b;}
bool compare1(ppl a,ppl b) {return a.ff > b.ff;}
bool compare2(ppl a,ppl b) {return a.ss < b.ss;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}

ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md = mod) {ll product = 1; while(b){if(b&1){product = (product*a)%md;}a = (a*a)%md;b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

ll maxi;

vl func(vl v,ll t)
{

    int n = v.size();

    vector<ll> v1;

    for(int i = 1; i < (1<<n); i++)
    {
        int j = i;

        int k = 0;

        ll sum = 0;

        while(j)
        {
            if(j&1)
            {
                sum += v[k];
            }
            k++;
            j = j>>1;
        }

        if(sum <= t)
        {
            maxi = max(maxi,sum);
        }

        v1.pb(sum);
    }

    sort(all(v1));

    return v1;
}

int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

    ll n,t;
    cin>>n>>t;

    vl a,b;

    forn(i,0,n/2)
    {
        ll x;
        cin>>x;
        a.pb(x);
    }

    forn(i,n/2,n)
    {
        ll x;
        cin>>x;
        b.pb(x);
    }

    maxi = 0;

    vl v1 = func(a,t),v2 = func(b,t);

    for(int i = 0; i < v1.size(); i++)
    {
        ll idx = upper_bound(all(v2),t-v1[i])-v2.begin();
        idx--;

        if(idx >= 0)
        {
            if(v1[i]+v2[idx] <= t)
            {
                maxi = max(maxi,v1[i]+v2[idx]);
            }
        }
    }

    cout<<maxi;

    return 0;
}

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);

int main() {
    ll N, T;
    cin >> N >> T;
    vecl A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];

    vector<ll> B;

    for (int bit = 0; bit < (1<<(N-N/2)); ++bit) {
        long long sum = 0;
        for (int i = 0; i < N-N/2; ++i) if (bit & (1LL<<i)) sum += A[i+N/2];
        B.push_back(sum);
    }

    sort(B.begin(), B.end());
    B.push_back(1LL<<60);

    ll ans = 0;
    for (int bit = 0; bit < (1<<(N/2)); ++bit) {
        long long sum = 0;
        for (int i = 0; i < N/2; ++i) if (bit & (1LL<<i)) sum += A[i];
        if (sum > T) continue;
        auto it = upper_bound(B.begin(), B.end(), T - sum) - B.begin();
        --it;
        chmax(ans, sum + B[it]);
    }
    cout << ans << endl;
}


#line 2 "/home/snow/competitive-programming/competitive-programming-library/snow/template.hpp"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

constexpr long long INF = 1LL << 60;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define to_s to_string
#define len(v) (ll) v.size()
#define debug(x) cout << #x << ": " << (x) << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> tpl;

template <typename T = ll>
using vec = vector<T>;

template <typename T = ll>
using vec2 = vector<vector<T>>;

template <typename T = ll>
using vec3 = vector<vector<vector<T>>>;

template < typename T >
inline bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

template < typename T >
inline bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#line 4 "/home/snow/competitive-programming/competitive-programming-library/snow/io/setup.hpp"

namespace snow{

struct IoSetup {
    IoSetup() {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
        std::cout << std::fixed << std::setprecision(10);
    }
} iosetup;

}
#line 5 "/home/snow/competitive-programming/competitive-programming-library/snow/io/helper.hpp"

template< typename T1, typename T2 >
std::ostream &operator << (std::ostream &os, const std::pair< T1, T2 > &p) {
    os << p.first << " " << p.second;
    return os;
}

template< typename T1, typename T2 >
std::istream &operator >> (std::istream &is, std::pair< T1, T2 > &p) {
    is >> p.first >> p.second;
    return is;
}

template< typename T1, typename T2, typename T3 >
std::ostream &operator << (std::ostream &os, const std::tuple< T1, T2, T3 > &t) {
    auto &[a, b, c] = t;
    os << a << " " << b << " " << c;
    return os;
}

template< typename T1, typename T2, typename T3 >
std::istream &operator >> (std::istream &is, std::tuple< T1, T2, T3 > &t) {
    auto &[a, b, c] = t;
    is >> a >> b >> c;
    return is;
}

template< typename T >
std::ostream &operator << (std::ostream &os, const std::vector< T > &v){
    for (int i = 0; i < (int)v.size(); ++i) {
        os << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return os;
}

template< typename T >
std::istream &operator >>  (std::istream &is, std::vector< T > &v){
    for(T &in : v) is >> in;
    return is;
}

template< typename T >
std::ostream &operator << (std::ostream &os, const std::set< T > &st){
    int ct = 0;
    for(auto& s : st) os << s << (++ct != st.size() ? " " : "");
    return os;
}

template<class... T>
void input(T&... a){
    (std::cin >> ... >> a);
}

void print() {
    std::cout << '\n';
}
template<class T, class... Ts>
void print(const T& a, const Ts&... b){
    std::cout << a;
    (std::cout << ... << (std::cout << ' ', b));
    std::cout << '\n';
}

int drop() {
    std::cout << '\n';
    exit(0);
}
template<class T, class... Ts>
int drop(const T& a, const Ts&... b){
    std::cout << a;
    (std::cout << ... << (std::cout << ' ', b));
    std::cout << '\n';
    exit(0);
}
#line 4 "main.cpp"
using namespace snow;

// #include "snow/algorithm/binary-search.hpp"

// #include "atcoder/modint"
// using namespace atcoder;
// using mint = modint1000000007;

int main() {
    ll N;
    cin >> N;

    ld x0, y0, x1, y1;
    input(x0, y0, x1, y1);

    ld xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;

    ld x_ = x0 - xm, y_ = y0 - ym;

    const double PI = acos(-1);

    complex<ld> p(x_, y_);
    ld deg = ld(2) * PI / ld(N);
    complex<ld> d(cos(deg), sin(deg));

    p *= d;

    ld x = p.real(), y = p.imag();

    print(x + xm, y + ym);

    return 0;
}

#include<bits/stdc++.h>
#define PI 3.141592653589793238462
#define eps 1e-20
using namespace std;
using cd = complex<double>;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdd;
int main(){
    db n,sx,sy,tx,ty;cin>>n>>sx>>sy>>tx>>ty;
    db px=(sx+tx)/2,py=(sy+ty)/2;
    db x=atan2(sy-py,sx-px);
    x+=PI*2.0/n;db r=sqrt((px-sx)*(px-sx)+(py-sy)*(py-sy));
    printf("%.15Lf %.15Lf\n",px+cos(x)*r,py+sin(x)*r);
}


#include <iostream>
using namespace std;
int main(void) {
	int a[2][2];
	int i, j;
	for (i = 0;i < 2;++i) {
		for (j = 0;j < 2;++j) {
			cin >> a[i][j];
		}
	}
	int ans = a[0][0] * a[1][1] - a[0][1] * a[1][0];
	cout << ans << endl;
}

#include <bits/stdc++.h>
typedef long long       ll;
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define mt                make_tuple
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define deb(x)			  cerr << "# " << (#x) << " = " << (x) << endl;
#define sz(x)             (int)x.size()
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int INF = 1234567890;

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << a*d - b*c << '\n';
    return 0;
}
// Dinosaurs are cool!


// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define int long long
#define all(a) a.begin(), a.end()
#define vi vector<int>
#define pii pair<int, int>
#define fe(i, a, b) for (int i = a; i <= (b); ++i)
#define fr(i, a, b) for (int i = b; i >= (a); --i)
using namespace std;

inline int in() {
    int s = 0, f = 0, ch = getchar();
    while (!isdigit(ch))
        f |= ch == '-', ch = getchar();
    while (isdigit(ch))
        s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
    return f ? -s : s;
}
const int N = 1e6 + 5;
const int mod = 4;
const int inf = 1ULL << 60;
int n, m, k;
int a[N], b[N], f[N];
int c[N];

int qp(int a, int b) {
    int sum = 1;
    while (b) {
        if (b & 1)
            sum = sum * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return sum;
}
int inv(int a) {
    return qp(a, mod - 2);
}
bool flag[N];
int p[N], tot;

int find(int x) {
    return x == f[x] ? x : f[x] = find(f[x]);
}

struct node {
    int x, y;
    bool operator<(const node& b) const { return y > b.y; }
};

vector<pair<int, int>> g[N];
void work() {
    n = in();
    int s = in(), d = in();
    fe(i, 1, n) {
        int a = in(), b = in();
        if (a < s && b > d) {
            puts("Yes");
            return;
        }
    }
    puts("No");
}
signed main() {
#ifndef ONLINE_JUDGE
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
#endif
    // for (int _ = in(); _; --_)
    work();
    // system("pause");
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define ll long long

int main() {

    int N, S, D;
    cin >> N >> S >> D;
    int X[N], Y[N];
    rep(i, N) cin >> X[i] >> Y[i];

    rep(i, N) {
        if(X[i] < S && D < Y[i]) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

//#include <atcoder/all>

//using namespace atcoder;
//typedef modint1000000007 mint;

int main(){
  int N;
  cin>>N;
  VL A(N),B(N);
  rep(i,N) cin>>A[i];
  rep(i,N) cin>>B[i];
  ll ans=0;
  rep(i,N) ans+=B[i];
  VVL X(2,VL(N/2));
  rep(i,N) X[i%2][i/2]=A[i]-B[i];
  rep(i,2) sort(all(X[i]));
  rep(i,N/2) X[0][i]+=X[1][i];
  rep(i,N/2) if(X[0][i]>0) ans+=X[0][i];
  cout<<ans<<endl;
}

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  long long X, Y, A, B;

  cin >> X >> Y >> A >> B;

  long long exp = 0;
  while (1) {
    if ((double)X * A > 2e18 || X * A >= Y || X * A > X + B) {
      break;
    }
    X *= A;
    exp++;
  }

  long long re = ((Y - X - 1) / B);
  exp += re;

  cout << exp << endl;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
  long long a=0,b=0,c=0;
  long long i=1;
  long long ans=9223372036854775807;
  long long N;
  cin >> N;

  while(1){
    if(i >= N)break;
    b++;
    i = i << 1;
    a = N / i;
    c = N % i;
    if(a+b+c < ans){
      ans = a+b+c;
    }
  }
  if(b == 0){
    ans = 1;
  }

  cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)
#define popcount __builtin_popcount

const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main() {
  ll N; cin >> N;
  ll result = N, b = 0;
  while (true) {
    ll a = N/(1ll<<b), c = N%(1ll<<b);
    // cout << a << " " << b << " " << c << endl;
    result = min(result, a+b+c);
    if (a==0) break;
    b++;
  }
  cout << result << endl;
  return 0;
}


#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define it register int
#define ct const int
#define il inline
template <class I>
il I Max(I p,I q){return p>q?p:q;}
template <class I>
il I Min(I p,I q){return p<q?p:q;}
template <class I>
il I A(I x){return x<0?-x:x;}
template <class I>
il void sp(I&p,I&q){I x=p;p=q,q=x;}
template <class I>
il void ckMax(I&p,I q){p=(p>q?p:q);}
template <class I>
il void ckMin(I&p,I q){p=(p<q?p:q);}
const int N=1000005,P=998244353;
il void mo(it &p,ct q){p+=q,p>=P?p-=P:0;}
int pw[N],n,m;
il int ksm(it x,it L){it ans=1;while(L) L&1?ans=(0ll+ans)*x%P:0,x=(0ll+x)*x%P,L>>=1;return ans;}
int main(){
	scanf("%d%d",&n,&m);it i,j;
	for(i=pw[0]=1;i<=5000;++i) pw[i]=(0ll+pw[i-1])*m%P;
	it ans=(0ll+n)*ksm(m,n)%P;
	for(i=1;i<n;++i) for(j=1;j<=m;++j) ans=(ans-(0ll+pw[n-i-1])*(0ll+n-i)%P*ksm(m-j,i-1))%P;
	printf("%d",(ans+P)%P);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    int n;
    cin >> n;
    vector<int> ans(n);
    ans[0] = 1;
    for (int i = 1; i < n; i++)
    {
        ans[i] = ans[(i + 1) / 2 - 1] + 1;
    }
    for (int i = 0; i < n; i++)
    {
        cout << ans[i] << " ";
    }
    cout << "\n";
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define f first
#define s second
#define all(c) begin(c),end(c)
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;

const ll MAXN = 1e5;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;
const ll EPS = 1e-9;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	if(n%100 > 0){
		cout << (int)(n/100)+1;
	}
	else
		cout << (int)n/100;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}

int main(){
	fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
	ll n;
	cin>>n;
	vlli a(n), b(n);
	scan(a, 0, n);
	scan(b, 0, n);
	ll ans =0;
	forn(i, 0, n){
		ans+=(a[i]*b[i]);
	}
	if(ans == 0){
		cout<<"Yes"<<endl;
	} else {
		cout<<"No"<<endl;
	}
}

// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#ifndef ONLINE_JUDGE ///???

#endif ///????
#define _USE_MATH_DEFINES

#include<math.h>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
#include <sstream>
#pragma GCC optimize("Ofast") //???

using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(ll i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1LL << 50)
#define MOD (1e9+7)
#define rrep(i,n) for(int i=n-1;i>=0;--i)

//typedef pair < ll, ll> P;

//元がintの分けたものを返す p[0]は1桁目
vector<int> divnum(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
//桁数を返す
int digiter(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p.size();
}
//元がstringの分けたものを返す d[0]は最高位
vector<int> convertstring(string s) {
	vector<int> d;
	ll n = s.size();
	reverse(s.begin(), s.end());
	rep(i, n) {
		d.push_back(s[i] - '0');
	}
	return d;
}

//クエリO(logN)
struct SegmentTree {
private:
	ll n;
	vector<ll> node;

public:
	SegmentTree(vector<ll> v) {//SegmentTree seg(vector<ll>(N,INF))で呼び出し
		ll sz = v.size();
		ll value = (1LL << 50);
		if (v.size() > 0) value = v[0];
		n = 1; while (n < sz) n *= 2;
		node.resize(2 * n - 1, value);
		for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--) node[i] = min(node[2 * i + 1], node[2 * i + 2]);
	}

	void update(ll x, ll val) {
		x += (n - 1);
		node[x] = val;
		while (x > 0) {
			x = (x - 1) / 2;
			node[x] = min(node[2 * x + 1], node[2 * x + 2]);
		}
	}

	ll getmin(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {//区間[a,b)の(a<=x<b)最小値(x)を調べる。
		if (r < 0) r = n;
		if (r <= a || b <= l) return (1LL << 50);
		if (a <= l && r <= b) return node[k];

		ll vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
		ll vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
};

/*long double　は%Lf*/
//queue古い順,stack新しい順

int N, A[25];
int32_t main() {
	cin >> N;
	rep(i, N)cin >> A[i];
	int res = (1 << 30);
	//cout << res << endl;
	for (int i = 0; i < (1 << 21); i++) {
		int cnt = 0, k = 0;
		rep(j, N) {
			if (((i >> j)&1)!=1) {
				k = (k | A[j]);
			}
			else {
				cnt = (cnt ^ k);
				k = A[j];
			}
		}
		cnt = (cnt ^ k);
		chmin(res, cnt);
	}
	cout << res << endl;

}


#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<ll,ll,ll> tll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) {
 if (a < b) { a = b; return true; } return false;
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false;
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  COUT(n-a+b);
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

    ll n;
    cin >> n;
    ll a;
    cin >> a;
    ll b;
    cin >> b;

    cout << n-a+b << '\n';

    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define forn(i,x1,n)     for(int i=x1; i<n; i++)
#define forit(it, m)    for(decltype(m)::iterator it = m.begin(); it!=m.end(); ++it)
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x1)      __builtin_popcountll(x1)
#define zrobits(x1)      __builtin_ctzll(x1)
#define mod             1000000007
// #define mod             998244353
#define inf             1e18
#define ps(x1,y)         fixed<<setprecision(y)<<x1
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x1)            int x1; cin>>x1; while(x1--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

void zeus()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {

	zeus();

	int n, q; cin >> n >> q;

	int a[n + 1];

	forn(i, 0, n) {
		cin >> a[i];
	}
	a[n] = 0;

	sort(a, a + n + 1);
	int diff[n];

	forn(i, 0, n) {
		diff[i] = a[i + 1] - a[i] - 1;
	}
	int prefixsum[n + 1];
	prefixsum[0] = 0;

	forn(i, 0, n) {
		prefixsum[i + 1] = prefixsum[i] + diff[i];
	}

	forn(i, 0, q) {
		int k; cin >> k;
		auto ind = lower_bound(prefixsum, prefixsum + n + 1, k) - prefixsum;
		cout << a[ind - 1] + k - prefixsum[ind - 1] << endl;
	}

}

#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define NeedForSpeed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vii;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
template<class T> bool umin(T& a, const T& b) {return a > b? a = b, true:false;}
template<class T> bool umax(T& a, const T& b) {return a < b? a = b, true:false;}

const int N = 3e5+5;
const int mod = 1e9+7;
const ll inf = 1e18;
const ld Pi = acos(-1);

#define MULTI 0

int n, m, s, k, ans, a[N];

void solve(int t_case){
	cin>>n;
	int cnt = 0;
	n *= 2;
	for(int i=1;i*1ll*i<=n;i++){
		if(n%i == 0){
			int x=i, a2 = n/x+1-x;
			cnt += (a2 % 2 == 0), x=n/i;
			if(x == i) continue;
			a2 = n/x+1-x;
			cnt += (a2 % 2 == 0);
		}
	}
	cout<<cnt<<"\n";
}

signed main(){
	NeedForSpeed
	if(!MULTI) {
		solve(1);
	} else {
		int t; cin>>t;
		for(int t_case = 1; t_case <= t; t_case++) solve(t_case);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define SZ(x) ((int)(x).size())
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) {
    cin >> a[i];
    a[i] %= 200;
  }
  SORT(a);
  map<int, ll> mp;
  REP(i, n) mp[a[i]]++;
  ll ans = 0;
  EACH(e, mp) {
    if (e.second == 1) continue;
    ans += (e.second * (e.second - 1)) / 2;
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;

int main(){
    int a, b;
    cin >> a >> b;
    int sa, sb; sa=0; sb=0;
    while(a >= 10){
        //sa = 0;
        sa += a % 10;
        a /= 10;
    }
    sa += a;
    while(b >= 10){
        //sb = 0;
        sb += b % 10;
        b /= 10;
    }
    sb+= b;
    cout << max(sa, sb) << endl;
}