//GOD PLEASE HELP ME ,GOD PLEASE HELP ME , GOD PLEASE HELP ME
//Name Rishiraj Kalita
// sc id : 1912041

#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)    scanf("%d",&x)
#define sl(x)    scanf("%lld",&x)
#define ss(s)    scanf("%s",s)
#define pi(x)    printf("%d\n",x)
#define pl(x)    printf("%lld\n",x)
#define ps(s)    printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z) cout << #x << "=" << x << "," << #y << "=" << y <<","<< #z << "=" << z << endl
#define debv(v) for(auto x:v) cout<<x<<" "
#define debg(g,n) for(int i=1;i<=n;i++){cout<<i<<"--->";for(auto x:g[i]){cout<<x<<" ";}cout<<"\n";}
#define clrg(g,n) for(int i=0;i<=n;i++) g[i].clear();
#define pb push_back
#define mp make_pair
#define e endl
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define inf 9000000000000000000
typedef pair<int, int>    pii;
typedef pair<ll, ll>    pl;
typedef vector<int>        vi;
typedef vector<ll>        vl;
typedef vector<pii>        vpii;
typedef vector<pl>        vpl;
typedef vector<vi>        vvi;
typedef vector<vl>        vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];
vpl v;

void solve() {
    ll i, j, n,k,data,m,f=1;
    cin>>n;
    //deb(n);
    unsigned ll ans=inf;
    data= log(n)/log(2);
    for(i=0;i<=data+10;i++)
    {
        unsigned ll x=pow(2,i);
        unsigned ll y=n/x;
        unsigned ll z=n-(x*y);
        //deb3(i,y,z);
        ans=min(ans,i+y+z);
        if(y==0)
        {
            break;
        }
    }
    cout<<ans<<"\n";

  }

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    //cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
    int i, u, v;
    while(m--){
        cin>>u>>v;
   // u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
}

void dfs(int u, int par){
    for(int v:g[u]){
        if (v == par) continue;
        dfs(v, u);
    }
}

#include <bits/stdc++.h>

using namespace std;

struct cake {
    int a;
    int b;
    int c;
};

int fact(int n) {
    if (n <= 0) {
        return 1;
    }
    return n * fact(n-1);
}

void solve() {
    long long n, m;
    cin >> n;
    cin >> m;
    /*
    vector<cake> v;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                cake c;
                c.a = i;
                c.b = j;
                c.c = k;
                v.push_back(c);
            }
        }
    }
    sort(v.begin(), v.end(), [](const cake & x, const cake & y) {
        if (x.a + x.b + x.c == y.a + y.b + y.c) {
            if (x.a == y.a) {
                return x.b < y.b;
            }
            return x.a < y.a;
        }
        return x.a + x.b + x.c < y.a + y.b + y.c;
    });

    map<int, int> dupa;
    for (cake & c : v) {
        dupa[c.a+c.b+c.c]++;
        //cout << c.a+c.b+c.c << ": " << c.a << " " << c.b << " " << c.c << endl;
    }
    */
    for (long long k = 0; k <= 3*n-3; k++) {
        long long sum = k+3;
        long long f;
        if (k < n) {
            f = (k+2) * (k+1) / 2;
        } else if (k < 2*n) {
            f = (9*n-3*n*n+6*k*n-6*k-2*k*k-4)/2;
        } else {
            f = (3*n-k-1) * (3*n-k-2) / 2;
        }
        //cout << sum << " " << dupa[sum] << " " << f << endl;
        if (m <= f) {
            for (long long a = 1; a <= n; a++) {
                long long rest = sum - a;
                if (rest >= 2 && rest <= 2 * n) {
                    long long mn = max(1LL, rest - n);
                    long long mx = min(rest - 1, n);
                    long long cnt = mx - mn + 1;
                    if (m <= cnt) {
                        for (long long b = 1; b <= n; b++) {
                            long long c = rest - b;
                            if (c >= 1 && c <= n) {
                                m--;
                                if (m == 0) {
                                    cout << a << " " << b << " " << c << endl;
                                    return;
                                }
                            }
                        }
                    } else {
                        m -= cnt;
                    }
                }
            }
            break;
        } else {
            m -= f;
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed;
    cout.precision(12);

    int T = 1;
    //cin >> T;
    for (int t = 0; t < T; t++) {
        solve();
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000 * 1000;

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

  W *= 1000;
  int max_i = W / A;
  int min_ans = INF;
  int max_ans = -1;

  for (int i = 1; i <= max_i; i++)
  {
    if (A * i <= W && W <= B * i)
    {
      min_ans = min(min_ans, i);
      max_ans = max(max_ans, i);
    }
  }

  if (max_ans == -1)
  {
    cout << "UNSATISFIABLE" << endl;
  }
  else
  {
    cout << min_ans << ' ' << max_ans << endl;
  }
}

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

int main() {

    int a,b,c; cin >> a >> b >> c;
    string ans = "No";
    if (a * a + b * b < c * c) {
        ans = "Yes";
    }
    cout << ans << endl;
    return 0;
}


#include "bits/stdc++.h"
using namespace std;
int sy,sx;
int cell_group[50][50];
int cell_point[50][50];
int dx[]={1,0,-1,0}, dy[]={0,1,0,-1};
string dcoms[]={"R","D","L","U"};
string ans="";
chrono::system_clock::time_point start;
chrono::system_clock::time_point _end;

bool comp(const pair<pair<int,string>,pair<int,int>>& lh, const pair<pair<int,string>,pair<int,int>>& rh) {
     return (lh.first.first+cell_point[lh.second.first][lh.second.second]) < (rh.first.first+cell_point[rh.second.first][rh.second.second]);
}

pair<string,int> dfs(int h, int w, int point, unordered_set<int>& used){
    _end = chrono::system_clock::now();
    double elapsed = chrono::duration_cast<chrono::milliseconds>(_end-start).count();
    if(elapsed>1850){
        string ans_reversed (ans.rbegin(), ans.rend());
        cout<<ans_reversed<<endl;
        exit(0);
    }
    vector<pair<pair<int,string>,pair<int,int>>> target;
    point+=cell_point[h][w];
    for(int i=0;i<4;i++){
        int next_h=h+dy[i],next_w=w+dx[i];
        if(next_h<0 or 50<=next_h or next_w<0 or 50<=next_w) continue;
        if(used.find(cell_group[next_h][next_w])==used.end()){
            target.push_back(make_pair(make_pair(point,dcoms[i]),make_pair(next_h, next_w)));
        }
    }
    if(target.size()==0) return make_pair("", point);
    sort(target.begin(), target.end(), comp);

    pair<string,int> fixed_ret=make_pair("", 0);

    if(true){
        int j=target.size()-1;
        int next_h=target[j].second.first;
        int next_w=target[j].second.second;
        string dcom=target[j].first.second;
        int tmp_point=target[j].first.first;
        used.emplace(cell_group[next_h][next_w]);
        pair<string,int> ret = dfs(next_h,next_w,tmp_point,used);
        used.erase(cell_group[next_h][next_w]);
        if(fixed_ret.second<ret.second){
            fixed_ret=make_pair(ret.first+dcom,ret.second);
        }
    }

    random_device seed_gen;
    mt19937 engine = mt19937(seed_gen());
    uniform_real_distribution<> dist1(0, 1.0);

    if(target.size()>=2 && dist1(engine)<0.15){
        random_device seed_gen;
        mt19937 engine = mt19937(seed_gen());
        uniform_int_distribution<> randint(1,target.size()-1);
        int j=randint(engine);

        int next_h=target[j].second.first;
        int next_w=target[j].second.second;
        string dcom=target[j].first.second;
        int tmp_point=target[j].first.first;
        used.emplace(cell_group[next_h][next_w]);
        pair<string,int> ret = dfs(next_h,next_w,tmp_point,used);
        used.erase(cell_group[next_h][next_w]);
        if(fixed_ret.second<ret.second){
            fixed_ret=make_pair(ret.first+dcom,ret.second);
        }
    }

    return fixed_ret;
}

int main(void){
    start = chrono::system_clock::now();

    cin>>sy>>sx;
    for(int i=0;i<50;i++){
        for(int j=0;j<50;j++){
            cin>>cell_group[i][j];
        }
    }
    for(int i=0;i<50;i++){
        for(int j=0;j<50;j++){
            cin>>cell_point[i][j];
        }
    }
    int mx_point=0;
    while(1){
        unordered_set<int> used;
        used.emplace(cell_group[sy][sx]);
        pair<string,int> tmp=dfs(sy,sx,0,used);
        string ans_command=tmp.first;
        int point=tmp.second;
        if(mx_point<point){
            ans=ans_command;
            mx_point=point;
        }
    }
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint dp[2010][2010];
mint x[2010][2010], y[2010][2010], z[2010][2010];
char s[2010][2010];

int main() {
  int h, w;
  cin >> h >> w;
  rep(i,h) {
    rep(j,w) cin >> s[i][j];
  }
  dp[0][0] = 1;
  rep(i,h) {
    rep(j,w) {
      if(i==0&&j==0) continue;
      if(s[i][j]=='#') continue;
      if(j>0) x[i][j] = x[i][j-1]+dp[i][j-1];
      if(i>0) y[i][j] = y[i-1][j]+dp[i-1][j];
      if(i>0&&j>0) z[i][j] = z[i-1][j-1]+dp[i-1][j-1];
      dp[i][j] = x[i][j]+y[i][j]+z[i][j];
    }
  }
  cout << dp[h-1][w-1].x << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()

int main() {
ll H,W,N,M;
  cin>>H>>W>>N>>M;

  vector<vector<ll>> vec(H,vector<ll> (W,0));

  for(ll i=0;i<N;i++) {
ll A,B;
    cin>>A>>B;
 A--;
    B--;
    vec[A][B]=1;
  }

  for(ll i=0;i<M;i++) {
ll C,D;
    cin>>C>>D;
    C--;
    D--;
    vec[C][D]=2;
  }

  vector<vector<bool>> note(H,vector<bool> (W,false));
  ll ans=0;

  for(ll i=0;i<W;i++) {
ll count=0;

    for(ll j=0;j<H;j++) {
      if(vec[j][i]==0) {
        if(count<=0) {
count--;
        }
        else {
count++;
      }
      }

      else if(vec[j][i]==1) {
        if(count<=0) {
count*=-1;
        }
        count++;
      }

        else {
if(count<=0) {
count=0;
}
          else {
            ans+=count;
            for(ll h=j-count;h<j;h++) {
              note[h][i]=true;
            }
            count=0;
          }
        }

       if(j==H-1&&count>0) {
         ans+=count;
for(ll h=j-count+1;h<=j;h++) {
note[h][i]=true;
}
       }

      }

  }

      for(ll i=0;i<H;i++) {
ll count=0;
        for(ll j=0;j<W;j++) {

  if(vec[i][j]==0) {
if(count<=0) {
count--;
}
    else {
count++;
    }
  }
          else if(vec[i][j]==1) {
if(count<=0) {
count*=-1;
}
            count++;
          }

          else {
if(count<=0) {
count=0;
}
            else {
ans+=count;
              for(ll h=j-count;h<j;h++) {
if(note[i][h]) {
ans--;
}
              }
              count=0;
            }
          }

            if(count>0&&j==W-1) {
ans+=count;
              for(ll h=j-count+1;h<=j;h++) {
if(note[i][h]) {
ans--;
}
              }

            }

          }
        }

        cout<<ans<<endl;
      }

#include <bits/stdc++.h>
using namespace std;
#define testing 1
#define FOR(ii,ss,ee) for (ll ii = (ss); ii<=(ll)(ee);++ii)
#define DEC(ii,ss,ee) for (ll ii = (ss); ii>=(ll)(ee);--ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << '=' << x << endl
#define db2(a,b) cerr << #a << "=" << a << " , " << #b << "=" << b << endl
#define dbv(v) cerr << #v << ":"; for (auto it : v) cerr << it << ' '; cerr << endl
#define dba(a,ss,ee) cerr #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
#define ll long long
#define pb push_back
#define inf (int)1e9
#define oo (ll)1e18
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "endl\n";
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti3;
const int MOD = 1e9+7;
template<typename T> void maxself(T &a, T b) {
	a = max(a,b);
}
template <typename T> void minself(T & a, T b) {
	a = min(a,b);
}

#define MAXN
#if !testing
	#define cerr if(0)cout
#endif
int bulb,block;
int32_t main() {
	IAMSPEED
	int n,m; cin >> n >> m >> bulb >> block;
	char A[n+5][m+5];
	int a[n+5][m+5], b[n+5][m+5], c[n+5][m+5], d[n+5][m+5];
	FOR(i,1,n)FOR(j,1,m)A[i][j]='x';
	memset(a,0,sizeof a);
	memset(b,0,sizeof b);
	memset(c,0,sizeof c);
	memset(d,0,sizeof d);
	FOR(i,1,bulb) {
		int x,y; cin >> x >> y;
		A[x][y] = '.';
	}
	FOR(i,1,block) {
		int x,y; cin >> x >> y;
		A[x][y]='#';
	}
	FOR(i,1,n) {
		a[i][1] = A[i][1]=='.';
		FOR(j,2,m) {
			a[i][j] = a[i][j-1];
			if(A[i][j]=='.')a[i][j]=1;
			if (A[i][j] == '#') a[i][j] = 0;
		}
	}
	FOR(i,1,m) {
		b[1][i] = A[1][i]=='.';
		FOR(j,2,n) {
			b[j][i] = b[j-1][i];
			if(A[j][i]=='.')b[j][i]=1;
			if (A[j][i]=='#') b[j][i] = 0;
		}
	}
	FOR(i,1,n) {
		c[i][m] = A[i][m]=='.';
		DEC(j,m-1,1) {
			c[i][j] = c[i][j+1];
			if(A[i][j]=='.')c[i][j]=1;
			if (A[i][j]=='#')c[i][j]=0;
		}
	}
	FOR(i,1,m) {
		d[n][i] = A[n][i]=='.';
		DEC(j,n-1,1) {
			d[j][i] = d[j+1][i];
			if(A[j][i]=='.')d[j][i]=1;
			if (A[j][i]=='#')d[j][i]=0;
		}
	}
	ll ans = 0;
	FOR(i,1,n) {
		FOR(j,1,m) {
			//db2(i,j);
			//db2(a[i][j],b[i][j]);
			//db2(c[i][j],d[i][j]);
			ans += !!max({a[i][j],b[i][j],c[i][j],d[i][j]});
		}
	}
	cout << ans;

}
/*
1 5

*/


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#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(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         cout<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define endl            "\n"
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

void __print(int32_t 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

void fastIO()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

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

    while(k--)
    {
        if(n%200==0)
        {
            n/=200;
        }
        else
        {
            n*=1000;
            n+=200;
        }
    }

    cout<<n;
}

int32_t main()
{
    fastIO();
    //w(t)
    {
        solve();
        cout<<endl;
    }
    return 0;
}

#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
int main(){
    int n,k;
    cin >> n >> k;
    ll ans = n;
    for(int i=0;i<k;i++){
        if(ans%200 == 0){
            ans = ans/200;
        }
        else{
            ans = ans*1000 + 200;
        }
    }
    cout << ans << endl;
    return 0;
}


#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int to[400001], ne[400001], he[200001];
int Q[200001], pl[200001], dl[200001];

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

	int N, K;
	cin >> N >> K;
	int k = 1;
	rep(i, N - 1) {
		int u, v;
		cin >> u >> v;
		to[k] = v;
		ne[k] = he[u];
		he[u] = k++;
		to[k] = u;
		ne[k] = he[v];
		he[v] = k++;
	}

	int q = 0, p = 0;
	Q[q++] = 1;
	while (p < N) {
		int u = Q[p++];
		int tmp = 0;
		int ind = he[u];
		he[u] = 0;
		while (ind) {
			int v = to[ind];
			tmp = ne[ind];
			if (he[v] > 0) {
				Q[q++] = v;
				ne[ind] = he[u];
				he[u] = -ind;
			}
			ind = tmp;
		}
	}

	int are = 1000000, pd0 = are;
	int L = 0, R = (N + K - 1) / K;
	while (L + 1 < R) {
		int wj = (L + R) / 2;

		int num = 0;

		for (int i = N - 1; i >= 0; i--) {
			int po = pd0 - 1;
			int dd = pd0;
			int u = Q[i];
			for (int ind = -he[u]; ind; ind = -ne[ind]) {
				int v = to[ind];
				if (po < pl[v]) po = pl[v];
				if (dd < dl[v]) dd = dl[v];
			}
			if (po >= dd) dd = 0;
			if (dd >= pd0 + wj) {
				num++;
				po = pd0 + wj;
				dd = 0;
			}
			pl[u] = po - 1;
			dl[u] = dd + 1;
		}

		int are = num + (dl[1] > pd0);
		if (are > K) L = wj;
		else R = wj;

		pd0 += are;
	}

	co(R);

	Would you please return 0;
}

#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <vector>
#include <queue>
#define lowbit(x) ((x) & (-(x)))
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 MIN(ll x, ll y) { return x < y ? x : y; }
ll MAX(ll x, ll y) { return x > y ? x : y; }
const ll MAXN = 523;
const ll MO = 998244353;
using namespace std;

ll H , W;
char mp[MAXN][MAXN];
char col[MAXN << 1 | 1];
int ans;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
	cin >> H >> W;
	For (i , 1 , H)
		cin >> (mp[i] + 1);
	For (i , 1 , H)
		For (j , 1 , W) {
			const char &w = mp[i][j];
			if (w == '.')
				continue;
			if (!col[i + j])
				col[i + j] = w;
			else {
				if (col[i + j] != w) {
					printf ("0\n");
					return 0;
				}
			}
		}
	ans = 1;
	For (i , 2 , H + W)
		if (!col[i])
			ans = (ans * 2) % MO;
	printf ("%lld\n" , ans);
    return 0;
}


    #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    using P=pair<ll,ll>;
    const ll INF=1e18;
    const int mod=1e9+7;

    void solve(){
        ll l,r;
        cin>>l>>r;
        vector<ll>x(r+1);
        ll ans=0;
        for(int i=r;i>=2;i--){
          ll p=r/i-(l-1)/i;
          x[i]=p*p;
          for(int j=2*i;j<=r;j+=i){
            x[i]-=x[j];
          }
          ans+=x[i];
        }
        for(ll i=l;i<=r;i++){
          if(i==1){continue;}
          ans-=r/i*2-1;
        }
        cout<<ans<<endl;
    }

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

        solve();

        return 0;
    }

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

int l , r ;

int A[1000007] ;
int ans[1000007] ;
int prime_factor[1000007] ;

void ertstns(){
    memset(prime_factor,-1,sizeof(prime_factor)) ;
    prime_factor[0] = prime_factor[1] = 1 ;
    for(int i = 2 ; i < 1000007 ; i++){
        if(prime_factor[i] == -1){
            for(int j = i ; j < 1000007 ; j += i) prime_factor[j] = i ;
        }
    }
}

int main(){
    ertstns() ;
    cin >> l >> r ;
    rrep(i,max(l,2),r+1){
        int k = i ;
        vector<int> vec ;
        map<int,bool> use ;
        while(k != 1){
            if(!use[prime_factor[k]]) vec.push_back(prime_factor[k]) ;
            use[prime_factor[k]] = true ;
            k /= prime_factor[k] ;
        }
        int t = vec.size() ;
        for(int S = 1 ; S < 1 << t ; S++){
            ll val = 1 ;
            for(int bit = 0 ; bit < t ; bit++){
                if(S >> bit & 1) val *= vec[bit] ;
            }
            ans[val]++ ;
        }
    }
    ll res = 0 , mns = 0 ;
    for(int i = max(l,2) ; i <= r ; i++){
        int k = i ;
        vector<int> vec ;
        map<int,bool> use ;
        while(k != 1){
            if(!use[prime_factor[k]]) vec.push_back(prime_factor[k]) ;
            use[prime_factor[k]] = true ;
            k /= prime_factor[k] ;
        }
        int t = vec.size() ;
        for(int S = 1 ; S < 1 << t ; S++){
            ll count = 0 , val = 1 ;
            for(int j = 0 ; j < t ; j++) if(S >> j & 1){
                count++ ;
                val *= vec[j] ;
            }
            if(count % 2 == 0) res -= ans[val] ;
            else res += ans[val] ;
        }
        if(i * 2 <= r) mns += 2 * (r / i - 1) ;
        mns++ ;
    }
    cout << res - mns << endl ;
}


#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

template<class T>
vector<T> make_vec(size_t a){
	return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
	return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M; cin>>N>>M;
    vi X(M),Y(M),Z(M);
    rep(i,M) cin>>X[i]>>Y[i]>>Z[i];

    vll dp(1<<N);
    dp[0] = 1;
    rep(S,1<<N){
        int popcnt = __builtin_popcount(S);
        bool ok=true;
        rep(i,M){
            if (popcnt>X[i]) continue;
            int mask = (1<<Y[i])-1;
            if (__builtin_popcount(S&mask) > Z[i]){
                ok=false;
                break;
            }
        }
        if (!ok) continue;
        rep(i,N)if(!(S>>i&1)){
            int T = S|(1<<i);
            dp[T] += dp[S];
        }
    }
    cout<<dp[(1<<N)-1]<<endl;
    return 0;
}

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

#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define ff first
#define ss second
#define YES printf("YES\n")
#define NO printf("NO\n")
#define nn "\n"
#define sci(x) scanf("%d", &x)
#define LL_INF (1LL << 62)
#define INF (1 << 30)
#define SetBit(x, k) (x |= (1LL << k))
#define ClearBit(x, k) (x &= ~(1LL << k))
#define CheckBit(x, k) (x & (1LL << k))
#define mod 1000000007
#define N 300005

int n, q;
int arr[N];

int tree[3*N];

void init(int b, int e, int node = 1)
{
  if (b == e)
  {
    tree[node] = arr[b];
    return;
  }
  int left = node * 2;
  int right = node * 2 + 1;
  int mid = (b + e) / 2;
  init(b, mid, left);
  init(mid + 1, e, right);
  tree[node] = tree[left] ^ tree[right];
}

int query(int b, int e, int i, int j, int node = 1)
{
  if (b >= i && e <= j)
    return tree[node];
  if (b > j || e < i)
    return 0;
  int left = node * 2;
  int right = node * 2 + 1;
  int mid = (b + e) / 2;
  return query(b, mid, i, j, left) ^ query(mid + 1, e, i, j, right);
}

void update(int b, int e, int i, int val, int node = 1)
{
  if (b > i || e < i)
    return;
  if (b == e && e == i)
  {
    tree[node] = val;
    return;
  }
  int left = node * 2;
  int right = node * 2 + 1;
  int mid = (b + e) / 2;
  update(b, mid, i, val, left);
  update(mid + 1, e, i, val, right);
  tree[node] = tree[left] ^ tree[right];
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> q;
    for(int i = 1; i <= n; i++){
        cin >> arr[i];
    }

    init(1, n);

    while(q--){
        int t, x, y;
        cin >> t >> x >> y;
        if(t==1){
            update(1, n, x, y^query(1, n, x, x));
        }
        else {
            cout << query(1, n, x, y) << nn;
        }
    }

    return 0;
}


#include<bits/stdc++.h>
//#pragma GCC optimize "trapv"
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define fast_az_fuk      ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll               long long
#define lll              __int128
#define ull              unsigned ll
#define ld               long double
#define pb               push_back
#define pf               push_front
#define dll              deque<ll>
#define vll              vector<ll>
#define vvll             vector<vll>
#define pll              pair<ll,ll>
#define vpll             vector<pll>
#define dpll             deque<pll>
#define mapll            map<ll,ll>
#define umapll           umap<ll,ll>
#define endl             "\n"
#define all(v)           v.begin(),v.end()
#define ms(a,x)          memset(a,x,sizeof(a))
#define random(l,r,T)    uniform_int_distribution<T>(l,r)(rng)

//#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;

template<typename T> istream& operator >>(istream &in,vector<T> &v){ for(auto &x:v) in>>x; return in;}
template<typename T> ostream& operator <<(ostream &out,vector<T> &v){ for(auto &x:v) out<<x<<' '; return out;}
template<typename T1,typename T2> istream& operator >>(istream &in,pair<T1,T2> &p){ in>>p.first>>p.second; return in;}
template<typename T1,typename T2> ostream& operator <<(ostream &out,pair<T1,T2> &p){ out<<p.first<<' '<<p.second; return out;}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
template<class T, class H>using umap=unordered_map<T,H,custom_hash>;
template<class T>using uset=unordered_set<T,custom_hash>;

int32_t main()
{
    clock_t clk = clock();
    fast_az_fuk
    ll n,t; cin>>t>>n; ll a = (n*100+t-1)/t; ll ans = a + (a*t)/100; ans--;cout<<ans;
    // cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n';
    return 0;
}

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
//using namespace __gnu_pbds;

//template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());//uniform_int_distribution<int> (l, r)

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 1e5 + 123;
const int M = 1e6 + 123;
const double pi = 3.14159265359;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

void solve(){
    ll r, x, y;
    cin >> r >> x >> y;
    ld d = sqrt((x*x)+(y*y));
    ll z = d/r;
    if ((x*x)+(y*y) == r*r*z*z){
        cout << z;
    }
    else{
        cout << max(2ll, z+1);
    }
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++){
        //cout << "Case #" << i << ": ";
        solve();
    }
    #ifdef KAZAKH
      //  cout << endl << 1.0 * clock() / CLOCKS_PER_SEC << endl;
    #endif
    return 0;
}


//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const int maxn = 3050;
const int maxm = maxn*maxn*4;
int head[maxm],vis[maxm];
char G[maxn][maxn];
int dis[maxm];
struct Edge{
	int f,t,w,next;
	Edge(int f = 0,int t = 0,int w = 0,int next = 0):f(f),t(t),w(w),next(next){}
}edge[maxm];
int cnt;
const int INF = 1e9;
void addedge(int f,int t,int w){
	edge[cnt] = Edge(f,t,w,head[f]);
	head[f] = cnt++;
}
void dijkstra(int s){
	typedef pair <int,int> node;
	priority_queue<node,vector<node>,greater<node> >q;
	for(int i =1;i< maxm;i++)dis[i] = INF;
	dis[s] = 0;
	q.push(make_pair(dis[s],s));
	while(!q.empty()){
		node tmp = q.top();
		q.pop();
		int u = tmp.second;
		if(vis[u])continue;
		vis[u] = 1;
		for(int i = head[u];~i;i = edge[i].next){
			int v = edge[i].t;
			if(dis[v] > dis[u] + edge[i].w){
				dis[v] = dis[u] + edge[i].w;
				if(!vis[v]){
					q.push(make_pair(dis[v],v));
				}
			}
		}
	}
	return;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	memset(head,-1,sizeof(head));
	int n,m;
	const int B = 2050*2050+1;
	int S = B+100;
	int T = B+101;
	cin >> n >> m;
	for(int i = 1;i <= n;i++){
		string s;
		cin >> s;
		for(int j = 1;j <= m;j++){
			G[i][j] = s[j-1];
			if(s[j-1] == 'S')S = i*2010+j;
			if(s[j-1] == 'G')T = i*2010+j;
		}
	}
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			if(G[i][j] != '#'){
				for(int k = -1;k <= 1;k++){
					for(int l = -1;l <= 1;l++)if(abs(k+l) == 1){
						int x = i+k,y = j+l;
						if(x < 1 or x > n or y < 1 or y > m)continue;
						if(G[i][j] != '#')addedge(i*2010+j,x*2010+y,2);
					}
				}
			}
			if(G[i][j] >= 'a' and G[i][j] <= 'z'){
				addedge(i*2010+j,B+G[i][j],1);
				addedge(B+G[i][j],i*2010+j,1);
			}
		}
	}
	dijkstra(S);
	if(dis[T] == INF)cout << -1;
	else cout << dis[T]/2;
	return 0;
}

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

using namespace std;
// using namespace __gnu_pbds;

#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<vi >
#define vpii vector<pii >
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define mod(x) (((LL)(x)%MOD+MOD)%MOD)
#define o(X) (1<<(X))
#define oL(X) (1LL<<(X))
#define LL long long
#define ppt(x) ((int)__builtin_popcount(x))
#define mst(x,a) memset(x,a,sizeof(x))

const int INF=0x3f3f3f3f,MOD=1023694381;
const LL INF_LL=0x3f3f3f3f3f3f3f3fLL;

template <typename T>
int getplc(T x,int y) {
	return (int)((x>>y)&1);
}

LL qpow(LL a,LL b=MOD-2,LL _MOD=MOD){
	LL res=1;
	for(;b;b>>=1,a=a*a%_MOD){
		if(b&1)
			res=res*a%_MOD;
	}
	return res;
}

template <typename T>
void ckmin(T &a,T b){ a>b?a=b:0; }
template <typename T>
void ckmax(T &a,T b){ a<b?a=b:0; }

template <typename T>
#define errorl(args...) {  \
	string _s = #args;   \
	replace(_s.begin(), _s.end(), ',', ' ');  \
    stringstream _ss(_s);  \
    istream_iterator<string> _it(_ss);  \
    errl(_it, args);  \
}
void errl(istream_iterator<string> it) {}
template<typename T, typename... Args>
void errl(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	errl(++it, args...);
}
#define error(args...) {  \
	string _s = #args;  \
	replace(_s.begin(), _s.end(), ',', ' ');  \
	stringstream _ss(_s);  \
	istream_iterator<string> _it(_ss);  \
	err(_it, args);  \
	cerr<<endl; \
}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << "=" << a << " # ";
	err(++it, args...);
}

int dx4[4]={1,0,-1,0},dy4[4]={0,1,0,-1};
int dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
const int N=1e6+5;

char s[2005][2005];
int vis[2005][2005],dis[2005][2005],ins[30];

vector<pair<int,int>> g[30];

void Solve() {
	int n,m,sx,sy,dx,dy;
	cin>>n>>m;
	rep(i,1,n){
		cin>>(s[i]+1);
		rep(j,1,m){
			if(s[i][j]=='S')sx=i,sy=j;
			else if(s[i][j]=='G')dx=i,dy=j;
			else if(islower(s[i][j])){
				g[s[i][j]-'a'].eb(i,j);
			}
		}
	}

	queue<pair<int,int>>que;

	auto push=[&](int x,int y,int stp){
		if(!vis[x][y]){
			vis[x][y]=1;
			dis[x][y]=stp;
			que.push({x,y});
		}
	};

	que.push({sx,sy});
	vis[sx][sy]=1;

	while(!que.empty()){
		auto u=que.front();que.pop();

		if(islower(s[u.fi][u.se])&&!ins[s[u.fi][u.se]-'a']){
			ins[s[u.fi][u.se]-'a']=1;
			for(auto c:g[s[u.fi][u.se]-'a']){
				push(c.fi,c.se,dis[u.fi][u.se]+1);
			}
		}

		rep(i,0,3){
			int tx=dx4[i]+u.fi,ty=dy4[i]+u.se;
			if(tx<1||tx>n||ty<1||ty>m||s[tx][ty]=='#')continue;
			push(tx,ty,dis[u.fi][u.se]+1);
		}
	}

	if(dis[dx][dy]==0)cout<<-1<<'\n';
	else cout<<dis[dx][dy]<<'\n';
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
//    freopen("o1.txt","w",stdout);
#endif
	ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
	Solve();
	return 0;
}


//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DB double
#define LD long double
#define ST string
#define BS bitset
#define PA pair<LL,LL>
#define VE vector
#define VL VE<LL>
#define VP VE<PA>
#define VVL VE<VL>
#define VVVL VE<VVL>
#define PQ priority_queue
#define PQS priority_queue<LL,vector<LL>,greater<LL>>
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define MP make_pair
#define TS to_string
#define TU to_ullong
#define BPL __builtin_popcountll
#define FOR(i,a,n) for(i=a;i<n;++i)
#define FORR(i,a,n) for(i=n-1;i>=a;--i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) FORR(i,0,n)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define UB(a,n) *upper_bound(ALL(a),n)
#define UBn(a,n) upper_bound(ALL(a),n)-a.begin()
#define LB(a,n) *lower_bound(ALL(a),n)
#define LBn(a,n) lower_bound(ALL(a),n)-a.begin()
#define INF 1000000000000000003
#define PI 3.14159265358979323846264338327950288
//#define MOD 1000000007
#define MOD 998244353
#define ERR 1e-10
#define coutl cout<<fixed<<setprecision(15)
#define FAST cin.tie(0);ios::sync_with_stdio(false)

void Yn(LL a){if(a)cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void YN(LL a){if(a)cout<<"YES"<<endl;else cout<<"NO"<<endl;}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL dig(LL n){LL ret=0;while(n)n/=10,++ret;return ret;}
LL GCD(LL a,LL b){LL c=1,tmp=max(a,b);b=min(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
LL cmod(LL a,LL m){if(a%m<0)return a%m+abs(m);else return a%m;}
LL cdiv(LL a,LL b){return ((a<0&&b<0)||(a>=0&&b>=0)?a/b:(a-b+1)/b);}
LL DIV(LL a,LL d,LL m){LL l=m,x=1,y=0,k;while(l){k=d/l;d-=k*l;swap(l,d);x-=k*y;swap(x,y);}return cmod(a*cmod(x,m),m);}
LL POW(LL a,LL n,LL m){LL ans=1;while(n>0){if(n&1)ans=ans*a%m;a=a*a%m;n>>=1;}return ans;}
VL fact,finv,inv;
void comi(LL n){LL i;fact.resize(max(2LL,n+1));finv.resize(max(2LL,n+1));inv.resize(max(2LL,n+1));fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[0]=inv[1]=1;FOR(i,2,n+1){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
bool cmps(PA a,PA b){if(a.SE!=b.SE)return a.SE<b.SE;return a.FI<b.FI;}
template<typename T>bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>void vout(VE<T> &v){LL i;rep(i,v.size()){cout<<v[i];if(i<v.size()-1)cout<<" ";}cout<<endl;}
template<typename T>void v2out(VE<VE<T>> &v){for(auto a:v)vout(a);}

int main(){
    FAST;
    LL i,ans=0,N,K;
    cin>>N>>K;
    if(N+K>=15&&K>=8)cout<<1<<endl;
    else if(N+K>=10&&K>=3)cout<<2<<endl;
    else if(N+K>=3)cout<<3<<endl;
    else cout<<4<<endl;
}

//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;
string to_string(char c) { return string(1,c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return (string)s; }
string to_string(string s) { return s; }
template<class A> string to_string(complex<A> c) {
	stringstream ss; ss << c; return ss.str(); }
string to_string(vector<bool> v) {
	string res = "{"; for(int i = 0; i < (int)v.size(); i++) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> string to_string(bitset<SZ> b) {
	string res = ""; for(size_t i = 0; i < SZ; i++) res += char('0'+b[i]);
	return res; }
template<class A, class B> string to_string(pair<A,B> p);
template<class T> string to_string(T v) { // containers with begin(), end()
	bool fst = 1; string res = "{";
	for (const auto& x: v) {
		if (!fst) res += ", ";
		fst = 0; res += to_string(x);
	}
	res += "}"; return res;
}
template<class A, class B> string to_string(pair<A,B> p) {
	return "("+to_string(p.first)+", "+to_string(p.second)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
	DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define wis(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
#else
#define wis(...) 0
#endif
typedef long long ll;
#define all(x) (x).begin(), (x).end()

const int MAXN = 2010, MOD = 1e9 + 7;

ll dp[MAXN][MAXN], psum[3][MAXN][MAXN];

int main(){
	ios::sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	vector<string> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	dp[0][0] = 1;
	psum[0][1][1] = psum[1][1][1] = psum[2][1][1] = 1;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(a[i - 1][j - 1] == '#'){
				continue;
			}
			if(i == 1 && j == 1){
				continue;
			}
			dp[i][j] = (dp[i][j] + psum[0][i - 1][j]) % MOD;
			dp[i][j] = (dp[i][j] + psum[1][i][j - 1]) % MOD;
			dp[i][j] = (dp[i][j] + psum[2][i - 1][j - 1]) % MOD;
			psum[0][i][j] = psum[0][i - 1][j] + dp[i][j];
			psum[1][i][j] = psum[1][i][j - 1] + dp[i][j];
			psum[2][i][j] = psum[2][i - 1][j - 1] + dp[i][j];
		}
	}
	cout << dp[n][m] << '\n';
}


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

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  const int64_t inf = LLONG_MAX / 2;
  vector<int64_t> a(n);
  vector<int> t(n);

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

  auto f = [&](int64_t x) {
    for (int i = 0; i < n; ++i) {
      if (t[i] == 1) x += a[i];
      else if (t[i] == 2) x = max(x, a[i]);
      else x = min(x, a[i]);
    }
    return x;
  };

  int64_t lb = -inf;
  int64_t ub = inf;
  int64_t d = 0;
  for (int i = 0; i < n; ++i) {
    if (t[i] == 1) lb += a[i], ub += a[i], d += a[i];
    else if (t[i] == 2) lb = max(lb, a[i]);
    else ub = min(ub, a[i]);
    if (lb > ub) {
      if (t[i] == 2) ub=lb;
      else lb=ub;
    }
  }
  lb -= d, ub -= d;
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int64_t x;
    cin >> x;
    if (x <= lb) cout << lb + d << endl;
    else if (x >= ub) cout << ub + d << endl;
    else cout << x + d << endl;
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 4;
vector<int> adj[N];
int c[20] , d[20][N];
int inf;
void bfs(int idx){
    int src = c[idx];
    queue<int> q;
    q.push(src);
    d[idx][src] = 0;
    while((int)q.size()){
        int tp = q.front();
        q.pop();
        for(int v : adj[tp]){
            if(d[idx][v] >= inf){
                d[idx][v] = d[idx][tp] + 1;
                q.push(v);
            }
        }
    }
}

int memo[18][(1<<18)+3] , k;

int solve(int idx , int msk){
    if(__builtin_popcount(msk) == k) {
        return 0;
    }
    int &ret = memo[idx][msk];
    if(~ret)
        return ret;
    ret = 2e7;
    for(int i = 0 ; i < k ; ++i){
        if((msk >> i) & 1)continue;
        ret = min(ret , d[idx][c[i]] + solve(i , msk | (1 << i)));
    }
    return ret;
}
void solve(){
    int n , m;
    cin >> n >> m;
    for(int i = 0 ; i < m ; ++i){
        int u , v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    memset(d , '?' , sizeof d);
    inf = d[0][0];
    cin >> k;
    for(int i = 0 ; i < k ; ++i){
        cin >> c[i];
        bfs(i);
    }
    memset(memo , -1 , sizeof(memo));
    int rs = 1 + solve(0 , 1);
    for(int i = 1 ; i < k ; ++i){
        rs = min(rs , 1 + solve(i , (1 << i)));
    }
    cout << (rs >= 2e7 ? -1 : rs) << '\n';
}
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    int t = 1;
//    cin >> t;
    while(t--){
        solve();
    }
}


//-- In the name of ALLAH --
// We're nothing and you're everything.
// Ya Ali!
#include<bits/stdc++.h>
using namespace std;

#define      pai              acos(-1)
#define      ff               first
#define      ss               second
#define      ll               long long
#define      pb               push_back
#define      mp               make_pair
#define      pll              pair<ll,ll>
#define      sz(a)            (ll)a.size()
#define      endl             "\n"
#define      gcd(a, b)        __gcd(a, b)
#define      lcm(a, b)        ((a)*((b)/gcd(a,b))
#define      all(vec)         vec.begin(),vec.end()
#define      ms(a, b)         memset(a,b,sizeof(a))
#define      rep(i,n)         for(int i= 0; i < int(n); i++)
#define      rep1(i,n)        for(int i= 1; i <= n; i++)
#define      rev(i,n)         for(int i= (int)(n-1);i>=0;i--)
#define      rev1(i,n)        for(int i= (int) n;i>= 1;i--)
#define      TEST_CASE(t)     for(int zz=1;zz<=t;zz++)
#define      PRINT_CASE       printf("Case %d: ",zz)
#define      fii              freopen("input.txt","r",stdin);
#define      foo              freopen("output.txt","w",stdout);
#define      FAST             ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

const ll M   = 1e9+7;
const ll mxn = 1e5+7;

int  main()
{
    ll i,j,k,a,b,c,d,n,m,t,x,y,z,u,v;
    cin>>n>>k;
    if(k==0)
    {

        cout<<n<<endl;
        return 0;
    }

    map<ll,ll>frq;
    for(i=1;i<=(n+1);i++)
    {
        frq[i]=(i-1);
    }
    ll tem=0;
    for(i=(2*n);i>(n+1);i--)
    {
        tem++;
        frq[i]=tem;
    }

    k=abs(k);
    ll ans=0;
    map<ll,bool>vis;
    for(i=1;i<=(2*n);i++)
    {
        if(!vis[i]&&frq[i]>=1)
        {
            a = i+k;
            if(!vis[a]&&frq[a]>=1)
            {
                ans+=(frq[i]*frq[a]);
                vis[i]=true;
                //vis[a]=true;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

/*---------macro---------*/
#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)
#define Clear(a) a = decltype(a)()
#define all(a) begin(a),end(a)
#define rall(a) rbegin(a),rend(a)
#define bit(i,j) ((i>>j)&1)

/*---------type/const---------*/
typedef long long ll;
typedef unsigned long long ull;
typedef string::const_iterator state; //構文解析
const ll big=1000000007;
//const ll big=998244353;
const double PI=acos(-1);
const double EPS=1e-8;//適宜変える
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char newl='\n';
struct{
    constexpr operator int(){return -int(1e9)-1;}
    constexpr operator ll(){return -ll(1e18)-1;}
}neginf;
struct{
    constexpr operator int(){return int(1e9)+1;}
    constexpr operator ll(){return ll(1e18)+1;}
    constexpr auto operator -(){return neginf;}
}inf;

/*---------debug---------*/
#ifdef LOGX
#include <template/debug.hpp>
#define _GLIBCXX_DEBUG
#else
#define dbg(x) ;
#define prt(x) ;
#define _prt(x) ;
#endif

/*---------function---------*/
template<typename T,typename U> T max(const T x,const U y){if(x>y)return x;else return y;}
template<typename T,typename U> T min(const T x,const U y){if(x<y)return x;else return y;}
template<typename T> T max(const vector<T> &a){T ans=a[0];for(T elem:a){ans=max(ans,elem);}return ans;}
template<typename T> T min(const vector<T> &a){T ans=a[0];for(T elem:a){ans=min(ans,elem);}return ans;}
template<typename T,typename U> bool chmin(T &a,const U b){if(a>b){a=b;return true;}return false;}
template<typename T,typename U> bool chmax(T &a,const U b){if(a<b){a=b;return true;}return false;}
bool valid(int i,int j,int h,int w){return (i>=0 && j>=0 && i<h && j<w);}
template<typename T,typename U>
T expm(T x,U y,const ll mod=big){
    T res=1;
    while(y){
        if(y&1)(res*=x)%=mod;
        (x*=x)%=mod;
        y>>=1;
    }
    return res;
}
template<typename T,typename U>
T exp(T x,U y){
    T res=1;
    while(y){
        if(y&1)res*=x;
        x*=x;
        y>>=1;
    }
    return res;
}

int n;
vector<int> p;
vector<vector<int>> g;//g[i][0]がiの親.
vector<vector<bool>> notmy;
vector<int> ans;

//「自分」「相手」の辺を決定する.
bool dfs(int i){
    if(i!=0 && g[i].size()==1)return true;
    bool res=false;
    rep2(j,int(i!=0),g[i].size()){
        res^=(notmy[i][j]=dfs(g[i][j]));
    }
    return !res;
}

//その頂点「に」移動させることを選択した人がどれだけ獲得するか？
int calc(int i){
    if(g[i].size()==1 && i!=0){
        return ans[i]=-1;
    }

    vector<int> mine;
    vector<int> ene;
    rep2(j,int(i!=0),g[i].size()){
        if(notmy[i][j])ene.emplace_back(calc(g[i][j]));
        else mine.emplace_back(calc(g[i][j]));
    }

    sort(rall(mine));
    sort(rall(ene));

    int res=-1;
    //「ene」の個数が偶数個なら, mineは全て自分でとることになる.
    if(ene.size()%2==0){
        for(auto &e:mine)res+=e;
        rep(j,ene.size()){
            if(j%2==0)res+=ene[j];
            else res-=ene[j];
        }
    }
    else{
        for(auto &e:mine)res+=abs(e);
        rep(j,ene.size()){
            if(j%2==0)res+=ene[j];
            else res-=ene[j];
        }
    }
    return ans[i]=res;
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout.precision(10);
    /*--------------------------------*/

    cin >> n;
    p.resize(n);
    g.resize(n);
    rep(i,n-1){
        cin >> p[i+1];
        p[i+1]--;
        g[i+1].emplace_back(p[i+1]);
        g[p[i+1]].emplace_back(i+1);
    }
    notmy.resize(n);
    rep(i,n){
        notmy[i].resize(g[i].size());
    }
    ans.resize(n,0);
    dfs(0);
    dbg(notmy);
    calc(0);
    dbg(ans);
    cout << (n-ans.front())/2 << newl;
}


//#define _GLIBCXX_DEBUG
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include<algorithm>

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;

#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned int uint;
template<class T> inline bool chmax(T& a, const T& b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, const T& b) {if (b<a) {a=b; return true;} return false;}
const int INF = 1000000000;

int main() {
  IOS;
  int K;
  cin >> K;
  ll ans = 0;
  set<tuple<int,int>>st;

  map<ll, int> mp;

  for (int i=1; i*i<=K; i++){
    for (int j=i; j*j<=K; j++){
      if (i*j > K) continue;

        int kmax = K / i / j;
        chmax(mp[i*j], kmax);
        vector<int>v = {i,j};
        sort(all(v));
        st.insert(make_tuple(v[0],v[1]));

    }
  }
  map<vector<int>, bool>isthere;
  for (tuple<int,int> tp: st){
    int first = get<0>(tp);
    int second = get<1>(tp);
    int kmax = mp[first*second];

    for (int i=max(first,second); i<=kmax; i++){
      int third2 = i;
      vector<int> v = {first,second,i};
      sort(all(v));

      //if (isthere[v]) continue;
      if (first == second and second == third2 and first == third2) ans++;

      else if (first == second or second==third2 or first==third2 ){
        ans += 3;
      }
      else {
        ans += 6;
      }

      //isthere[v] = true;
    }
  }

  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int k, t;
long long ans;
int main(){
	scanf("%d", &k);
	for(int i=1; i<=k; i++) for(int j=1; j*i<=k; j++) ans += k/i/j;
	printf("%lld\n", ans);
}


#include <iostream>
using namespace std;
int main(){
  string n;
  cin >> n;

  int N = n.size();
  for(int i=0;i<N;i++){
    bool flag = true;
    for(int j=0;j<n.size()/2;j++){
      if(n[j] != n[n.size()-j-1]){
        flag = false;
        break;
      }
    }
    if(flag){
      cout << "Yes\n";
      return 0;
    }

    n = '0'+n;
  }

  cout << "No\n";
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define ss second
int main(void){
    // Your code here!
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
 int n;
 string s,r;
 cin >> n;
 while(n%10==0 && n>0)
 n/=10;
 s=to_string(n);
 r=s;
 reverse(r.begin(),r.end());
 cout << (s==r ? "Yes" : "No");
 return 0;
}


#include <bits/stdc++.h>

typedef long long LL;

#define rep(i, n)     for (LL i = 0; i < n; ++i)
#define rep1(i, n)    for (int i = 1; i <= n; ++i)
#define repB(i, m, n) for (LL i = m; i <= n; ++i)
#define repR(i, n)    for (LL i = n - 1; i >= 0; --i)
#define all(n)        n.begin(), n.end()

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	int x, y;
	cin >> x >> y;

	if (abs(x - y) < 3) {
		cout << "Yes";
	} else {
		cout << "No";
	}

	return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<complex>
#include<numeric>
#include<functional>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
    LL n,m;
    int i,j,k;
    LL a,b,c;
    int s=0;
    cin>>n>>m;
    for(a=1;a<=1e6+7;a++){
        if(m%a)continue;
        b=m/a;
        if(b<a)break;
        if(a+b==n)s++;
    }
    if(s)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


// Problem: C - Compass Walking
// Contest: AtCoder - AtCoder Beginner Contest 198
// URL: https://atcoder.jp/contests/abc198/tasks/abc198_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

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

#define ll long long
#define pb push_back
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<long long, long long>

const int p = 1e9 + 7;
const int lim = 1e6;

// //Number theory
// int facto[lim];
// void prefacto(){
	// facto[0]=0;
	// for(int i=1; i<=lim; i++)
		// facto[i] = (facto[i-1]*i)%p;
// }

// //Graph theory
// vi status(lim, 0);
// vi adj[lim];
// void edgeInput(int m){
	// for(int i=1; i<=m; i++){
		// int a, b;
		// cin>>a>>b;
		// adj[a].push_back(b);
		// adj[b].push_back(a);
	// }
// }

//Binary search
bool check(int elem){
	return true;
}
void bsearch(){
	int lo=0, hi=1e9, res=-1, mid;
	while(lo<=hi){
		mid = lo + (hi-lo)/2;
		if(check(mid)){
			res = mid;
			hi = mid-1;
		}else{
			lo = mid+1;
		}
	}
}

//Custom comparator
struct Node{};
struct Compare{
	bool operator() (const Node &a, const Node &b){
		return true;
	}
};
bool compare(const Node &a, const Node &b){
	return true;
}

void pre_io(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
}

int32_t main()
{
	pre_io();
	ll r, x, y;
	cin>>r>>x>>y;
	ll dsq = x*x + y*y;
	ll divo = r*r;
	ll quo = dsq/divo, rt = sqrt(quo);
	if(rt*rt*divo==dsq){
		cout<<rt;
	}else{
		cout<<rt+1+(rt==0);
	}
}

#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using db = double; using str = string;
using pi = pair<int,int>;
using vi = vector<int>; using vs = vector<str>;
using vl = vector<ll>; using vd = vector<double>;
using vvi = vector<vector<int>>;
using vvs = vector<vector<string>>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<double>>;
using pqi = priority_queue<int>;
using rpqi = priority_queue<int, vi, greater<int>>;
using umi = unordered_map<int, int>;
using usi = unordered_set<int>;

#define PB push_back
#define PF push_front
#define PK pop_back()
#define PT pop_front()
#define EB emplace_back
#define LB lower_bound
#define UB upper_bound
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define VT vector
#define se second
#define fi first
#define rt return
#define ln "\n"
#define ctu continue
#define F1(e) for(int i=0;i<(e);++i)
#define F2(i,e) for(int i=0;i<(e);++i)
#define F3(i,b,e) for(int i=(b);i<(e);++i)
#define F4(i,b,e,s) for(int i=(b); (s)>0?i<(e):i>(e); i+=(s))
#define Sum(a) accumulate((a).begin(), (a).end() , 0ll);
#define Min(a) *std::min_element((a).begin(), (a).end())
#define Max(a) *std::max_element((a).begin(), (a).end())
#define Sort(c) sort((c).begin(), (c).end())
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define each(x,a) for(auto& x : a)
#define all(c) (c).begin(), (c).end()
#define rall(a) rbegin(a),rend(a)
#define mst(a,x) memset(a, x, sizeof(a))
#define to_unique(a) a.erase(unique(begin(a), end(a)), end(a))
#define bct(x) (__builtin_popcountll(x))
#define in(x, a) a.find((x)) != a.end()
#define sz(x) ((int)(x).size())
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define isok(x, y) (x >= 0 && x < n && y >= 0 && y < m && !vis[x][y])

const ll mod = 1e9 + 7;
const double PI=acos(-1.0);
const int fx[4] = {1, 0, -1, 0}, fy[4] = {0, 1, 0, -1};
const int dx[8]={-1, -1, 0, 1, 1, 1, 0, -1}, dy[8]={0, 1, 1, 1, 0, -1, -1, -1};

template<class A> void read(VT<A>& v);
template<class T> void read(T& x) { cin >> x; }
template<class H, class... T> void read(H& h, T&... t) {
	read(h); read(t...);
}
template<class A> void read(VT<A>& x) {
	each(a, x) read(a);
}

template<class A> void wte(A x) {cout << x;}
template<class H, class... T> void wte(const H& h, const T&... t) {
	wte(h); cout<<' '; wte(t...);
}
template<class A> void wte(VT<A>& x) {
    bool f=1;
	each(a, x){
	    if(f==1) {
	        wte(a); f=0;
	    } else wte(' '),wte(a);
	}
}

int main() {
    IOS;
    vi a(3);
    read(a);
    Sort(a);
    if(a[0]==a[1]) cout<<a[2]<<ln;
    else if(a[2]==a[1]) cout<<a[0]<<ln;
    else cout<<0<<ln;
    return 0;
}


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

int start_time;
int si, sj;
int highscore;
string best_S = "";
vector<vector<int>> t(50, vector<int>(50));
vector<vector<int>> p(50, vector<int>(50));
vector<int> near_i = {1,-1,0,0};
vector<int> near_j = {0,0,1,-1};
vector<char> near = {'D','U','R','L'};

void dfs(int pi, int pj, int score, string &S, vector<bool> &used){
    if(clock() - start_time > 190 * CLOCKS_PER_SEC / 100){
        return;
    }

    if(used.at(t.at(pi).at(pj))){
        return;
    }
    used.at(t.at(pi).at(pj)) = true;
    score += p.at(pi).at(pj);

    if(score > highscore){
        best_S = S;
        highscore = score;
    }

    rep(i, 4){
        if(pi + near_i.at(i) >= 50 || pi + near_i.at(i) < 0 ||  pj + near_j.at(i) >= 50 ||  pj + near_j.at(i) < 0){
            continue;
        }
        S += near.at(i);
        dfs(pi + near_i.at(i), pj + near_j.at(i), score, S, used);
        S.erase(S.size()-1);
    }
    score -= p.at(pi).at(pj);
    used.at(t.at(pi).at(pj)) = false;

}

int main(){
    cin>>si>>sj;
    rep(i,50)rep(j,50){
        cin >> t.at(i).at(j);
    }
    rep(i,50)rep(j,50){
        cin >> p.at(i).at(j);
    }

    start_time = clock();

    vector<bool> used(2500, false);
    string empty_S;
    dfs(si,sj,0,empty_S,used);
    //cout << start_time << endl;
    cout << best_S << endl;

}

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rep(i, n) for(int i = 0; i < n;++i)
#define reps(i, s, n) for(int i = s; i < n;++i)
const int MAX_W = 50, MAX_H = 50;

int dx[4] = {+1,0,-1,0};
int dy[4] = {0,+1,0,-1};
char dm[4] = {'R', 'D', 'L', 'U'};

vvi v(MAX_H, vi(MAX_W, 0)), T(MAX_H, vi(MAX_W, 0)), P(MAX_H, vi(MAX_W, 0));

int f_w(int sx, int sy){
  int allS=P[sy][sx];
  v[sy][sx] = 1;
  rep(i,4){
    int ssx = sx + dx[i], ssy = sy + dy[i];
    if(ssx>=0 && ssx<MAX_W && ssy>=0 && ssy<MAX_H && T[sy][sx]==T[ssy][ssx]) v[ssy][ssx]=1;
  }
  queue<pair<int,int>> Q;
  Q.push(make_pair(sx, sy));
  while(!Q.empty()){
  	int px = Q.front().first, py = Q.front().second;
    Q.pop();
    v[py][px] = 1;
    allS += P[py][px];
    rep(i,4){
      int ppx = px + dx[i], ppy = py + dy[i];
      if(ppx>=0 && ppx<MAX_W && ppy>=0 && ppy<MAX_H && T[py][px]==T[ppy][ppx]) v[ppy][ppx]=1;
    }
    int tx = px, ty = py, s=0, w=-1;
    rep(i,4){
      int ttx = px + dx[i], tty = py + dy[i];
      if(ttx>=0 && ttx<MAX_W && tty>=0 && tty<MAX_H && v[tty][ttx]==0){
        if(s<P[tty][ttx]){
            s = P[tty][ttx];
            tx = ttx;
            ty = tty;
            w = i;
        }
      }
    }
    if(s>0){
        Q.push(make_pair(tx, ty));
        cout<< dm[w];
    }
  }
  return allS;
}

int main() {
    int si, sj;
    cin >> si >> sj;
    rep(i, MAX_H)rep(j, MAX_W) cin >> T[i][j];
    rep(i, MAX_H)rep(j, MAX_W) cin >> P[i][j];
    f_w(sj, si);
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define inf 1e9
#define linf 1e18
#define BASE 1000000
#define EPS 1e-10
#define PI acos(-1)
#define pii pair<int,int>
#define pdi pair<double,int>
#define vi vector<int>
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define ms(x,val_add) memset(x, val_add, sizeof(x))
#define pb(x) push_back(x)
#define make_unique(x) sort(ALL(x)) ; x.erase( unique(ALL(x)), x.end()) ;
#define dbg(x) do { cout << #x << " = " << x << endl; } while(0)
#define mp(x, y) make_pair(x, y)
#define minimize(x, y) x = min(x, y)
#define maximize(x, y) x = max(x, y)

/*** IMPLEMENTATION ***/
bool exitInput = false;
int ntest = 1, itest = 1 ;

const int dx[4] =
{
    -1, 0, 1, 0
};
const int dy[4] =
{
    0, 1, 0, -1
};

const ll Mod = 1000000007LL;
const int maxn = 200000 + 5;
const int maxv = 500 + 5;
const int maxe = 10000 + 5;

void addMod(ll &x, ll y)
{
    x = (x + y) % Mod;
}
ll modPow(ll x, ll p)
{
    if(p == 0)
        return 1;
    ll r = modPow(x, p / 2);
    r = (r * r) % Mod;
    if(p & 1)
        r = (r * x) % Mod;
    return r;
}

string s;
int n, K;
ll fact[17], choose[17][17];
ll woz[maxn][17], wz[maxn][17];
ll f[maxn][17]; // handle missing
ll res = 0;

int main()
{
    #ifdef HOME
    freopen( "input.txt", "r", stdin );
    freopen( "output.txt", "w", stdout );
    #endif // HOME
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << setprecision(10);
    cout << fixed;

    fact[0] = 1;
    for(int i = 1; i <= 15; ++i)
        fact[i] = (fact[i-1] * i) % Mod;
    for(int i = 0; i <= 15; ++i)
        choose[i][0] = choose[i][i] = 1;
    for(int i = 1; i <= 15; ++i)
        for(int j = 1; j < i; ++j)
            choose[i][j] = (choose[i-1][j-1] + choose[i-1][j]) % Mod;

    cin >> s >> K;
    n = s.size();

    // First step: count numbers with smaller length
    woz[0][0] = 1;
    for(int h = 1; h < n; ++h)
    {
        woz[h][1] = 1;
        for(int k = 2; k <= K && k <= h; ++k)
        {
            woz[h][k] = (k * (woz[h-1][k-1] + woz[h-1][k])) % Mod;
            wz[h][k] = ((k-1) * (woz[h-1][k-1] + woz[h-1][k])) % Mod;
        }
        addMod(res, choose[15][K] * woz[h][K]);
        addMod(res, choose[15][K-1] * wz[h][K]);
    }
    //cout << "first step, res = " << res << endl;
    // Second step: count numbers with equal length

    for(int h = 0; h < n; ++h)
    {
        f[h][0] = modPow(K, h);
    }
    for(int h = 1; h < n; ++h)
    {
        for(int k = 1; k <= K && k <= h; ++k)
        {
            f[h][k] = (f[h-1][k-1] * k + f[h-1][k] * (K - k)) % Mod;
        }
    }
    int cnt[16] ={0};
    for(int i = 0; i < n; ++i)
    {
        int h = n - 1 - i;
        int val = ('A' <= s[i] && s[i] <= 'Z'? s[i] - 'A' + 10 : s[i] - '0');
        int lo = (i == 0 ? 1 : 0);
        int hi = (i == n - 1 ? val : val - 1);
        for(int k = lo; k <= hi; ++k)
        {
            cnt[k]++;
            int cnt_existed = 0;
            for(int x = 0; x <= 15; ++x)
                cnt_existed += cnt[x] > 0;
            int cnt_missing = K - cnt_existed;
            if(cnt_missing >= 0)
            {
                addMod(res, choose[16 - cnt_existed][cnt_missing] * f[h][cnt_missing]);
            }
            cnt[k]--;
        }
        cnt[val]++;
    }
    cout << res << endl;

    return 0;
}

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

#define ll long long
#define all(x) x.begin(), x.end()
#define wa(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define int ll

const int mod = 1e9 + 7;
const int N = 2e5 + 5;
int a[N], cnt = 0;
int dp[N][20];
bool vis[20];

int mult(int x, int y){
	return ((x % mod) * (y % mod)) % mod;
}

int sum(int x, int y){
	return ((x % mod) + (y % mod)) % mod;
}

void solve(){
	string s; cin >> s;
	int k; cin >> k;
	int n = s.size();
	for(int i = 1; i <= n; ++i){
		if('0' <= s[i - 1] && s[i - 1] <= '9')
			a[i] = s[i - 1] - '0';
		else
			a[i] = s[i-1] - 'A' + 10;
	}
	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= 16; ++j){
			dp[i][j + 1] = sum(dp[i][j + 1], mult(dp[i - 1][j], (16 - j)));
			dp[i][j] = sum(dp[i][j], mult(dp[i - 1][j], j));
		}
		if(i != 1) dp[i][1] = sum(dp[i][1], 15);
		for(int j = (int) (i == 1); j < a[i]; ++j){
			dp[i][cnt + !vis[j]]++;
		}
		if(!vis[a[i]]) vis[a[i]] = 1, ++cnt;
	}
	cout << ( sum(dp[n][k], (cnt == k)) % mod) << "\n";
}

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int test = 1;
	while(test--) solve();
}


#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

using pis = pair<int,string>;
const int N = 50;
const int LIMIT = 1e7;
const vector<int> dx{0,1,0,-1}, dy{-1,0,1,0};
const vector<char> D{'U','R','D','L'};

int cnt = 0;
vector<vector<int>> t,p;

bool in_range(const pii &pl) {
    if (pl.first < 0 || pl.first >=N) return false;
    if (pl.second < 0 || pl.second >=N) return false;
    return true;
}

int xy_to_t(const pii &pl) {
    return t[pl.first][pl.second];
}

pis dfs(pii &pos,vector<bool> &tile) {
    pis ret = {0,""};
    cnt++;
    if (cnt > LIMIT) return ret;
    if (!in_range(pos)) return ret;
    if (tile[xy_to_t(pos)]) return ret;
    tile[xy_to_t(pos)] = true;
    pis tmp;
    int best = -1;
    REP(i,D.size()) {
        pos.first += dy[i];
        pos.second += dx[i];
        tmp = dfs(pos,tile);
        pos.first -= dy[i];
        pos.second -= dx[i];
        if (ret.first < tmp.first) {
            best = i;
            swap(ret,tmp);
        }
    }
    tile[xy_to_t(pos)] = false;
    ret.first += p[pos.first][pos.second];
    ret.second.push_back(D[best]);
    return ret;
}

int main(void)
{
    IOS
    pii s;
    cin >> s.first >> s.second;
    REP(i,N) {
        vector<int> t1(N);
        REP(j,N) cin >> t1[j];
        t.push_back(t1);
    }
    REP(i,N) {
        vector<int> p1(N);
        REP(j,N) cin >> p1[j];
        p.push_back(p1);
    }

    vector<bool> tile(N*N);

    pis ans = dfs(s,tile);
    reverse(ALL(ans.second));
    ans.second.pop_back();
    OUT(ans.second)

    return 0;
}

//================code===================//

//#define TLE

#ifdef TLE
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#endif

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <ctime>
#include <random>
#include <chrono>
//#include <stdint.h>

#define ci(t) cin>>t
#define co(t) cout<<t
#define LL long long
#define ld long double
#define fa(i,a,b) for(LL i=(a);i<(LL)(b);++i)
#define fd(i,a,b) for(LL i=(a);i>(LL)(b);--i)
#define setp pair<int,ld>
#define setl pair<LL,LL>

#define micro 0.000000000001

using namespace std;

LL gcd(LL a, LL b)
{
	if (!(a && b)) return max(a, b);
	return a % b ? gcd(b, a % b) : b;
}

#ifdef OHSOLUTION
#define ce(t) cerr<<t
#define AT cerr << "\n=================ANS=================\n"
#define AE cerr << "\n=====================================\n"
#define DB(a) cerr << __LINE__ << ": " << #a << " = " << (a) << endl;
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#define LLL LL
#else
#define AT
#define AE
#define ce(t)
#define LLL __int128
#endif

pair <int, int> vu[9] = { {0,1},{1,0},{0,-1} ,{-1,0},{-1,0},{-1,-1}, {0,-1} , {1,-1},{-1,-1} }; //RDLU EWSN

template<typename T, typename U> void ckmax(T& a, U b) { a = a < b ? b : a; }
template<typename T, typename U> void ckmin(T& a, U b) { a = a > b ? b : a; }
struct gcmp { bool operator()(LL a, LL b) { return a < b; } bool operator()(setl& a, setl& b) { return a.second < b.second; } };
struct lcmp { bool operator()(LL a, LL b) { return a > b; } bool operator()(setl& a, setl& b) { return a.second > b.second; } };

const int max_v = 1e5 + 7;
const int max_k = 5e2 + 7;
const int bsz = (1ll << 10) + 7;
const int INF = 1e9 + 7;
const LL LNF = (LL)5e18 + 7ll;
LL mod =  998244353;//1e9 + 7;
template<typename T, typename U> void MOD(T& a, U b) { a += b; if (a >= mod) a -= mod; };

int main()
{
#ifdef OHSOLUTION
	freopen("input.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int a, b; ci(a >> b);

	vector<int> vi(3);
	vi[0] = 0;
	vi[1] = 1;
	vi[2] = 2;

	if (a == b) co(a);
	else
	{
		for (auto& x : vi)
		{
			if (x != a && x != b)
			{
				co(x);
				break;
			}
		}
	}

	return 0;
}


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

int main() {
    string S;
    cin >> S;
    char T;
    cin >> T;
    if (S == "Y")
    {
        T = toupper(T);
    }
    cout << T << endl;
}

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

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define setp(x) fixed << setprecision(x)
#define ordered_set tree<pair<long double, int> , null_type,less<pair<long double, int> >, rb_tree_tag,tree_order_statistics_node_update>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int inf = int(1e9);
const ll INF = ll(1e16);
const int mod = inf + 7;
const int N = 3e5 + 555; // TL MB
const double PI = acos(-1.0);
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}
template<typename T_vector> // neal
void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = int(v.size());

    for (int i = start; i < end; i++)
        cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}

void solve(){
    char a, b;
    cin >> a >> b;
    if(a == 'Y') b = b - 'a' + 'A';
    cout << b;
}

int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
    Red;
  	int T = 1;
  	// cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}


#ifdef Rahul
#include "RAHUL.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const i64 INF = (i64) 4e18 + 42;
const int MOD = (int) 1e9 + 7;

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);

  int n, k; cin >> n >> k;
  vector<int> a(n), b(n);
  for (int &x : a) cin >> x;
  for (int &x : b) cin >> x;
  int m = k - n;
  set<int> sa{0, m};
  for (int i = 0; i < n; ++i) {
    a[i] -= i + 1;
    b[i] -= i + 1;
    sa.insert(a[i]);
  }
  error(sa);
  error(a);
  error(b);
  int ok = 1;
  for (int x : b) {
    ok &= (int) sa.count(x);
  }
  if (!ok) kek(-1);
  a.insert(begin(a), 0);
  b.insert(begin(b), 0);
  a.push_back(m);
  b.push_back(m);
  i64 ans = 0;
  int nx = -1, val = -1;
  for (int i = 1, j = 1; i <= n; ++i) {
    if (nx >= i) a[i] = val;
    if (a[i] < b[i]) {
      j = i;
      while (1) {
        if (nx >= j) a[j] = val;
        if (a[j] >= b[i]) break;
        ++j;
      }
      nx = j;
      val = a[j];
      a[i] = val;
      ans += j - i;
      if (a[j] != b[i]) kek(-1);
    }
    error(i, a[i], b[i], ans);
  }
  error(a);
  error(b);
  for (int &x : a) x *= -1;
  for (int &x : b) x *= -1;
  reverse(ALL(a));
  reverse(ALL(b));
  nx = -1, val = -1;
  for (int i = 1, j = 1; i <= n; ++i) {
    if (nx >= i) a[i] = val;
    if (a[i] < b[i]) {
      j = i;
      while (1) {
        if (nx >= j) a[j] = val;
        if (a[j] >= b[i]) break;
        ++j;
      }
      nx = j;
      val = a[j];
      a[i] = val;
      ans += j - i;
      if (a[j] != b[i]) kek(-1);
    }
    error(i, a[i], b[i], ans);
  }
  error(a);
  error(b);
  kek(ans);
}

#include <bits/stdc++.h>
using namespace std;
#define per(i,a,b) for(int i=(b)-1;i>=a;i--)
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define dd(x) cout<<#x<<" = "<<x<<" "
#define mes(p) memset(p,0,sizeof(p))
#define all(x) x.begin(),x.end()
#define rson mid+1,r,rt<<1|1
#define sz(x) (int)x.size()
#define lson l,mid,rt<<1
#define mp make_pair
#define pb push_back
#define ls (rt<<1)
#define rs (ls|1)
#define se second
#define fi first
typedef pair <int ,int > pii;
typedef vector <int > vi;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;

const int maxn= 1e5+5;
const int N = 1e6 + 6;
int a[maxn], b[maxn], c[maxn];
int main(){
	int n, L;
	scanf("%d%d", &n, &L);
	rep(i,1,n+1) scanf("%d", &a[i]);
	rep(i,1,n+1) scanf("%d", &b[i]);
	a[n+1] = b[n+1] = L + 1;
	rep(i,0,n+2) c[i] = a[i] - i;// dd(i),de(c[i]);
	int f = 1;
	ll ans = 0;
	rep(i,1,n+1){
		if(a[i] == b[i]) continue;
		if(b[i] == b[i-1] + 1 || b[i] == a[i-1] + 1)
			ans += (b[i-1] < a[i]);
		else {
			int k = lower_bound(c, c + n + 2, b[i] - i) - c;
			if(k < i) k = upper_bound(c, c+n+2, b[i]-i) - c - 1;
			if(0 <= k && k < n + 2 && c[k] == b[i] - i)
				ans += abs(k - i);
			else f = 0;
	//		dd(i), de(k);
		}
	//	dd(i), de(ans);
		//a[i] = b[i];
	}
	if(!f) ans = -1;
	cout << ans;
    return 0;
}
/*
10 1000
1 3 5 7 9 11 13 15 17 19
6 8 10 12 14 15 16 998 999 1000
10 1000
2 4 6 8 10 12 14 16 18 20
1 2 3 4 5 7 9 11 13 15
10 100
2 3 4 5 6 7 8 9 10 11
1 2 3 4 5 6 7 8 9 10
10 1000
1 3 5 7 9 11 13 15 17 19
6 7 8 9 10 14 15 16 998 999 1000
*/


#include <iostream>
#include <chrono>
#include <string>
#include <vector>
#include <algorithm>
class DNA {
	private:
		char base[20][20];
	public:
		void inputV(const int& i, const int& j, const std::string& s) {
			for (int k = 0; k < (int)s.size(); k++) {
				if (i + k < 20) base[i + k][j] = s[k];
				else base[i + k - 20][j] = s[k];
			}
		}
		void inputH(const int& i, const int& j, const std::string& s) {
			for (int k = 0; k < (int)s.size(); k++) {
				if (j + k < 20) base[i][j + k] = s[k];
				else base[i][j + k - 20] = s[k];
			}

		}
		void output() {
			for (int i = 0; i < 20; i++) {
				for (int j = 0; j < 20; j++) {
					std::cout << base[i][j];
				}
				std::cout << std::endl;
			}
		}
		//constructor
		DNA() {
			for (int i = 0; i < 20; i++) {
				for (int j = 0; j < 20; j++) {
					base[i][j] = '.';
				}
			}
		}
};
int main() {
	DNA alien;
	int m;
	std::cin >> m >> m;
	std::vector<std::pair<int, std::string>> sequences(m, { 0, "" });
	for (int i = 0; i < m; i++) {
		std::cin >> sequences[i].second;
		sequences[i].first = (int)sequences[i].second.size();
	}
	sort(sequences.begin(), sequences.end());
	int now = 0;;
	int k = 0;
	while(now < 20) {
		for (int i = 0; i < 20; i++) {
			alien.inputH(i, now + 1, sequences[i].second);
		}
		k++;
		now += sequences[k * 20 - 1].first;
	}
	alien.output();

	return 0;

}

#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <random>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
    int N;
    int M;
    vector<string> S(M, "");

    int L = 0;

    cin >> N >> M;
    for (int i = 0; i < M; i++)
    {
        cin >> S.at(i);
        L = max(L, (int)S.at(i).size());
    }

    /*
    todo 親和性の高い部分列同士をあらかじめ結合しておく

    //結合度3以上の二つを結合する。
    for(int ketsugou = L; L > 2; L--){
        for(int i = 0; i)
    }
    */

    //ランダムにあてはめる。
    vector<vector<char>> board(20, vector<char>(20, '.'));
    //todo:Sを並べ替える
    //mt19937 get_rand_mt;
    //shuffle( S.begin(), S.end(), get_rand_mt );
    //sort(S.begin(), S.end(), [](string &a, string &b){return a.size() >= b.size();});

    for (string s : S)
    {
        int best_score = -1;
        int best_pos = -1;
        //横0縦1
        bool best_muki_is_tate = true;
        for (int i = 0; i < 400; i++)
        {
            int pos_i = i / 20;
            int pos_j = i % 20;
            int goodness = 0;
            for (int s_index = 0; s_index < (int)s.size(); s_index++)
            {
                if (board.at((pos_i + s_index) % 20).at(pos_j) == '.')
                {
                    continue;
                }
                else if (board.at((pos_i + s_index) % 20).at(pos_j) == s.at(s_index))
                {
                    goodness += 1;
                }
                else
                {
                    goodness = -1;
                    break;
                }
            }
            if (goodness > best_score)
            {
                best_score = goodness;
                best_pos = i;
                best_muki_is_tate = false;
            }
            goodness = 0;
            for (int s_index = 0; s_index < (int)s.size(); s_index++)
            {
                if (board.at(pos_i).at((pos_j + s_index) % 20) == '.')
                {
                    continue;
                }
                else if (board.at(pos_i).at((pos_j + s_index) % 20) == s.at(s_index))
                {
                    goodness += 1;
                }
                else
                {
                    goodness = -1;
                    break;
                }
            }
            if (goodness > best_score)
            {
                best_score = goodness;
                best_pos = i;
                best_muki_is_tate = true;
            }
        }
        //boardを更新する。
        if (best_score == -1)
        {
            continue;
        }
        int pos_i = best_pos / 20;
        int pos_j = best_pos % 20;
        for (int s_index = 0; s_index < (int)s.size(); s_index++)
        {
            board.at((pos_i + !best_muki_is_tate * s_index)%20).at((pos_j + best_muki_is_tate * s_index)%20) = s.at(s_index);
        }
    }
    for(int i = 0; i < 20; i++){
        for(int j = 0; j < 20; j++){
            cout << board.at(i).at(j);
        }
        cout << endl;
    }
    return 0;
}


// Fearless
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long>
#define PI (2.0 * acos(0.0))
#define testcase ll T; cin >> T; for (ll tc = 1; tc <= T; tc++)
#define info pair<int, pii>
#define mkp make_pair
const long long M = 1e5 + 10, M2 = 1e6 + 10, oo = 1e9 + 7;
void solve () {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << fixed << setprecision(10) << 1.0 * (c * b + a * d) / (b + d + 0.0) << endl;
}
int main () {
    //freopen("E:/newts/in.txt", "r", stdin);
    //freopen("E:/newts/out.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //testcase {
        solve ();
    //}
    return 0;
}

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

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

  if (N <= 3) {
    cout << 1 << endl;
    return 0;
  }

  char caa, cab, cba, cbb;
  cin >> caa >> cab >> cba >> cbb;

  if (caa == 'A' && cab == 'A') cout << 1 << endl;
  else if (cab == 'B' && cbb == 'B') cout << 1 << endl;
  else if (caa == 'B' && cab == 'A' && cba == 'A') {
    int count = 1, count2 = 1, count3 = 1 ;
    for (int i = 3; i < N; i++) {
      count = (count2 + count3) % 1000000007;
      count3 = count2;
      count2 = count;
    }
    cout << count << endl;
  }
  else if (cab == 'B' && cba == 'B' && cbb == 'A') {
    int count = 1, count2 = 1, count3 = 1 ;
    for (int i = 3; i < N; i++) {
      count = (count2 + count3) % 1000000007;
      count3 = count2;
      count2 = count;
    }
    cout << count << endl;
  }
  else {
    int count = 1;
    for (int i = 3; i < N; i++) {
      count = (count * 2) % 1000000007;
    }
    cout << count << endl;
  }

return 0;
}


//abc202_c.cpp
//Fri Jun 18 20:08:47 2021

#include <bits/stdc++.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	map<ll,ll> a;
	vector<ll> b(n),c(n);
	rep(i,n){
		ll tmp;
		cin >> tmp;
		a[tmp]++;
	}
	rep(i,n) cin >> b[i];
	rep(i,n) cin >> c[i];

	ll ans = 0;
	rep(i,n){
//		cout << b[c[i]-1] << endl;
		ans += a[b[c[i]-1]];
	}

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

#include <climits>
#include <iostream>
#include <unordered_map>
#include <map>
#include <vector>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#include <cmath>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tt=1;
    while(tt--){
        int n;
        cin>>n;
        map<long long, multiset<long long>> balls;
        for(int i=0;i<n;i++){
            long long x, id;
            cin>>x>>id;
            if(balls.find(id)==balls.end()){
                multiset<long long> locations;
                locations.insert(x);
                balls.insert(make_pair(id, locations));
                continue;
            }
            (balls.find(id)->second).insert(x);
        }
        long long dp[balls.size()][2];
        for(int i=0;i<balls.size();i++){
            for(int j=0;j<2;j++){
                dp[i][j]=0;
            }
        }
        dp[balls.size()-1][0]=abs(*((balls.rbegin()->second).begin()));
        dp[balls.size()-1][1]=abs(*((balls.rbegin()->second).rbegin()));
        int i=balls.size()-2;
        auto it=balls.rbegin();
        it++;
        for(it;it!=balls.rend();it++){
            long long lastmn=*((prev(it)->second).begin());
            long long lastmx=*((prev(it)->second).rbegin());
            long long mn=*((it->second).begin());
            long long mx=*((it->second).rbegin());
            dp[i][0]=min(dp[i+1][1]+abs(mn-lastmn)+lastmx-lastmn, dp[i+1][0]+abs(lastmx-mn)+lastmx-lastmn);
            dp[i][1]=min(dp[i+1][1]+abs(mx-lastmn)+lastmx-lastmn, dp[i+1][0]+abs(lastmx-mx)+lastmx-lastmn);
            i--;
        }
        long long lastmx=*((balls.begin()->second).rbegin());
        long long lastmn=*((balls.begin()->second).begin());
        long long zero=0;
        long long ans=min(dp[0][1]+abs(lastmn)+lastmx-lastmn, dp[0][0]+abs(lastmx)+lastmx-lastmn);
        cout<<ans<<"\n";
    }

}

//3 4 2 1 5 6

//1 2 3


#include<bits/stdc++.h>
using namespace std;
#define Max(a,b) ((a)<(b))&&((a)=(b))
#define Min(a,b) ((a)>(b))&&((a)=(b))
#define LL long long
#define db double
bool f1;
inline int rd() {
	int res=0;
	char ch;
	while(ch=getchar(),ch<48||ch>57);
	do res=(res<<1)+(res<<3)+(ch^48);
	while(ch=getchar(),ch>47&&ch<58);
	return res;
}
const int M=4e5+5;
int n;
int A[M];
struct info {
	int x,num;
	bool operator <(const info &_) const {
		if(x^_.x)return x<_.x;
		return num<_.num;
	}
}P[M];
int l[M],r[M];
int topl,topr;
char S[M];
bool f2;
int main() {
//	printf("%lf\n",(&f2-&f1)/1024.0/1024.0);
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	n=rd();
	for(int i=1; i<=n*2; ++i) A[i]=rd(),P[i]=(info)<%A[i],i%>;
	sort(P+1,P+n*2+1);
	for(int i=1; i<=n*2; ++i) {
		int ss=lower_bound(P+1,P+n*2+1,(info)<%A[i],i%>)-P;
		if(ss<=n) {
			if(topr)S[r[topr--]]='(',S[i]=')';
			else l[++topl]=i;
		}else {
			if(topl)S[l[topl--]]='(',S[i]=')';
			else r[++topr]=i;
		}
	}for(int i=1; i<=n*2; ++i)printf("%c",S[i]);
	return 0;
}

#include<iostream>
#include<iomanip>

#include<cmath>
#include<algorithm>
#include<numeric>

#include<vector>
#include<string>
#include<set>
#include<map>
#include<stack>
#include<cassert>
//#include<atcoder/all>

#define fi first
#define se second
#define pb(x) emplace_back(x)

using namespace std;
using ll = long long;
using v_ll = vector <ll>;
using vv_ll = vector <v_ll>;

ll max(ll x,ll y){return x>y?x:y;}
ll min(ll x,ll y){return x<y?x:y;}
template<class T> bool chmax(T& x,const T& y){ if (x>=y) return false; x=y; return true;}
template<class T> bool chmin(T& x,const T& y){ if (x<=y) return false; x=y; return true;}
template<class T> void quit(T x){std::cout << x << "\n"; exit(0);}

template<typename T> void vshow(T x){for(auto itr = x.begin();itr!=x.end();itr++){std::cerr << *itr << " ";} std::cerr << "\n";}
template<typename T> void vvshow(T x){for(auto itr = x.begin();itr!=x.end();itr++){vshow(*itr);} std::cerr << "\n";}

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  v_ll A(2*N,0),B(2*N,0),C(2*N,0);
  for(ll i=0;i<2*N;i++){
    cin >> A[i];
    B[i]=A[i];
    // C[i]=B[i];
  }
  sort(B.begin(),B.end());
  ll th = B[N];
  ll cnt1=0;
  for(ll i=0;i<2*N;i++){
    if (A[i]>th)cnt1++;
  }
  for(ll i=0;i<2*N;i++){
    if (A[i]>th || (A[i]==th && cnt1<N)){
      if (A[i]==th) cnt1++;
      A[i]=1;
    }
    else {A[i]=0;}
  }
  stack<ll>S;
  string ans="";
  for(ll i=0;i<2*N;i++){
    if (S.empty()){ans.push_back('('); S.push(A[i]);}
    else if (S.top()==A[i]) {ans.push_back('('); S.push(A[i]);}
    else {ans.push_back(')'); S.pop();}
  }
  cout << ans << "\n";
}


#include<bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
const int maxn=110,mod=998244353;
inline bool ckmin(int &x,const int &y){return x>y?x=y,1:0;}
inline bool ckmax(int &x,const int &y){return x<y?x=y,1:0;}
struct modint{
	int val;
	inline modint(int val_=0):val(val_){}
	inline modint &operator=(int val_){return val=val_,*this;}
	inline modint &operator+=(const modint &k){return val=val+k.val>=mod?val+k.val-mod:val+k.val,*this;}
	inline modint &operator-=(const modint &k){return val=val-k.val<0?val-k.val+mod:val-k.val,*this;}
    inline modint &operator*=(const modint &k){return val=1ll*val*k.val%mod,*this;}
    inline modint &operator^=(int k){
        modint ret=1,tmp=*this;
        for(;k;k>>=1,tmp*=tmp)if(k&1)ret*=tmp;
        return val=ret.val,*this;
    }
    inline modint &operator/=(modint k){return *this*=(k^=mod-2);}
    inline modint &operator+=(int k){return val=val+k>=mod?val+k-mod:val+k,*this;}
    inline modint &operator-=(int k){return val=val<k?val-k+mod:val-k,*this;}
    inline modint &operator*=(int k){return val=1ll*val*k%mod,*this;}
    inline modint &operator/=(int k){return *this*=((modint(k))^=mod-2);}
    template<class T>friend modint operator+(modint a,T b){return a+=b;}
    template<class T>friend modint operator-(modint a,T b){return a-=b;}
    template<class T>friend modint operator*(modint a,T b){return a*=b;}
    template<class T>friend modint operator/(modint a,T b){return a/=b;}
    friend modint operator^(modint a,int b){return a^=b;}
    friend bool operator==(modint a,int b){return a.val==b;}
    friend bool operator!=(modint a,int b){return a.val!=b;}
    inline bool operator!(){return !val;}
    inline modint operator-(){return val?mod-val:0;}
    inline modint &operator++(int){return *this+=1;}
};
using mi=modint;
mi ans,f[maxn*maxn][maxn],fac[maxn];
int a[maxn],m,n;
int main(){
	scanf("%d",&n);
	fac[0]=1;
	for(ri i=1;i<=n;++i){
		scanf("%d",a+i);
		m+=a[i];
		fac[i]=fac[i-1]*i;
	}
	if(m&1)return puts("0"),0;
	m>>=1;
	f[0][0]=1;
	for(ri i=1;i<=n;++i)
		for(ri j=m;j>=a[i];--j)
			for(ri k=n;k;--k)
				f[j][k]+=f[j-a[i]][k-1];
	for(ri i=1;i<n;++i)ans+=f[m][i]*fac[i]*fac[n-i];
	printf("%d",ans);
	return 0;
}

#include <bits/stdc++.h>
#define f(i,j,k) for(long long i=j;i<k;i++)
#define f2(i,j,k) for(long long i=j;i>=k;i--)
#define ll long long
using namespace std;
const long long mod=1e9+7;
const ll infl = 1LL << 60;
ll H,W,A,B;
bool used[16][16];
ll dfs(ll x,ll y,ll a){
    ll ans=0;
    if(y==H){
        return a==0;
    }
    if(x==W){
        return dfs(0,y+1,a);
    }
    if(used[x][y]){
        return dfs(x+1,y,a);
    }
    if(y+1<H&&!used[x][y+1]&&a>0){
        used[x][y]=used[x][y+1]=true;
        ans+=dfs(x+1,y,a-1);
        used[x][y]=used[x][y+1]=false;
    }
    if(x+1<W&&!used[x+1][y]&&a>0){
        used[x][y]=used[x+1][y]=true;
        ans+=dfs(x+1,y,a-1);
        used[x][y]=used[x+1][y]=false;
    }
    ans+=dfs(x+1,y,a);
    return ans;
}
int main(){
    ll h,w,a,b;
    cin>>H>>W>>A>>B;
    cout<<dfs(0,0,A)<<endl;
    return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
template<class T> void chmax(T &a, const T b){ a = max(a, b); }
template<class T> void chmin(T &a, const T b){ a = min(a, b); }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if (
        (a == (b + c + d)) ||
        (b == (a + c + d)) ||
        (c == (a + b + d)) ||
        (d == (a + b + c)) ||
        ((a + b) == (c + d)) ||
        ((a + c) == (b + d)) ||
        ((a + d) == (b + c))
    ) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>

int main(void){

  int a, b, c, d;
  int x, y;

  scanf("%d %d %d %d", &a, &b, &c, &d);
  printf("%d", b - c);

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  int x, y;	cin >> x >> y;
  int high = max(x, y);
  int low = min(x, y);
  if(high - low < 3)	cout << "Yes";
  else cout << "No";
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#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 io ios::sync_with_stdio(false); cin.tie(0)

int main()
{
    io;
    ll t, n;
    cin >> t >> n;
    ll res = (100*n+(t-1))/t + n-1;
    cout << res << endl;
    return 0;
}


    /* Goal to be a Master */
    #include <algorithm>
    #include <bits/stdc++.h>
    #include <cstring>
    #include <climits>
    #include <cstdlib>
    #include <cstdio>
    #include <bitset>
    #include <vector>
    #include <cmath>
    #include <ctime>
    #include <queue>
    #include <stack>
    #include <map>
    #include <set>
    #include<tuple>
    using namespace std;
    #define endl "\n"
    #define fo1(i,n) for(int i=1;i<=n;i++)
    #define min3(a,b,c) min(a,min(b,c))
    #define s(v) (ll)v.size()
    #define e(v) v.empty()
    #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define vi vector<int>
    #define fi first
    #define se second
    #define db double
    #define U unsigned
    #define P pair<int,int>
    #define ll long long
    #define vll vector<ll>
    #define pll pair<ll,ll>
    #define pb push_back
    #define eb emplace_back
    #define mp make_pair
    #define all(x) x.begin(),x.end()
    #define CLR(i,a) memset(i,a,sizeof(i))
    #define fo(i,a,b) for(int i = a;i <= b;++i)
    #define ro(i,a,b) for(int i = a;i >= b;--i)
    #define ppll pair < pll , pll >
    #define sd(x) scanf("%d",&x)
    #define sld(x) scanf("%lld",&x)
    #define INF 1e18
    #define eps 0.00001
    #define le length
    #define debug(n1) cout << n1 << "\n"
    int gcd(int a,int b)
    {
      if(b==0)
        return a;
      else
      return gcd(b,a%b);
    }
    int binex(int base,int pow)
    {
      int res=1;
      while(pow){
      if(pow%2)
      { res*=base;pow--;}
      else
      {base*=base;pow=pow/2;}
      }
      return res;
    }
    void sieve(int a[],int N)
    {
      for(int i=1;i<=N;i++)
        a[i]=1;
      a[1]=0;
      for(int i= 2;i*i<=N;i++)
      {
        if(a[i])
        {
        for(int j=i*i;j<=N;j+=i)
          a[j]=0;
      }
      }
    }
    string CONVERT_TO_BINARY(int s) {
        string res = "";
        while(s != 0) {
            res += (char)('0' + s % 2);
            s /= 2;
        }
        reverse(res.begin() , res.end());
        return res;
    }
    int STOI(string s) {
        int num = 0;
        int po = 1;
        for(int i=s.length()-1;i>=0;i--)
        {
            num += po * (s[i] - '0');
            po *= 10;
        }
        return num;
    }
    int main()
    {
        IOS
        int n,k;
        cin>>n>>k;
        int a[n];
        int m[n+1]={0};
        int h=0;
        for(int i=0;i<n;i++)
        {
          cin>>a[i];h=max(h,a[i]);
          m[a[i]]++;
        }
        ll ans=0;
        if(m[0]<k)
         {
             int diff=k-m[0];
            k-=diff;
         }
        for(int i=1;i<h;i++)
        {

            if(m[i]<k)
            {
                int diff=k-m[i];
              ans+=i*diff;
              k-=diff;
            }
        }

        if(m[h]<k)
        {
            int diff=k-m[h];
           ans+=h*diff;
           k-=diff;
           ans+=(h+1)*m[h];
         }
        else
        {
            ans+=(h+1)*k;
        }
        cout<<ans;
        cout.precision(8);
        cout << fixed;
        return 0;
    }

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD int(1e9+7)
#define INF int(1e9)
#define LINF ll(1e18)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<ll,ll>

int n,k;
int a[310000];

int main(){
  cin>>n>>k;
  rep(i,n){
    int val; cin>>val;
    a[val]++;
  }
  int ans=0;
  rep(i,n){
    if(a[i]<k){
      ans += a[i];
      k=a[i];
    }else{
      ans += k;
    }
  }
  cout<<ans<<endl;
}