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

#define ll long long
#define ar array

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

	ll n; cin>> n;
	for(int i=1; ; ++i){
		if(stoll(to_string(i)+to_string(i))>n){
			cout<<i-1<<endl;
			break;
		}
	}

	return 0;
}

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(nums) nums.begin(), nums.end()
#define allr(nums) nums.rbegin(), nums.rend()
#define len(a) int((a).size())
typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>ordered_set ;
typedef vector<vector<int>> graph;
const ll inf = INT32_MAX;
const ll minf = INT32_MIN;
template<class T>T cal(T n) {return (n*1ll*(n+1))/2;}
template<class T>T mx(T begin, T end){return max_element(begin, end);}
template<class T>T mn(T begin, T end){return min_element(begin, end);}
template<class T>void getUnique(vector<T>& nums){sort(nums.begin(), nums.end()); nums.erase(unique(nums.begin(), nums.end()), nums.end());}
template<class T>void print(vector<T>nums){for(T i:nums)cout<<i<<" ";cout<<"\n";}
template<class T>void read(vector<T>&nums){for(T& i:nums)cin>>i;}

signed main () {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll test = 1;
    // cin >> test;
    while (test--) {
        int n ;
        cin >> n ;
        vector<int>nums(n) ;
        read(nums) ;
        sort(all(nums)) ;
        bool flag = true ;
        for (int i=1; i<=n; ++i) {
            if (i != nums[i-1]) {
                flag = false ;
                break ;
            }
        }
        cout << (flag ? "Yes" : "No") << "\n" ;
    }

    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector< pii >
#define vpll vector< pll >
#define mpii map<int,int>
#define mpll map<ll,ll>
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define s(v) v.size()
#define test ll t;cin>>t;while(t--)
#define vec vector<ll>
#define read0(v,n) for(int i=0;i<n;i++)cin>>v[i];
#define read1(v,n) for(int i=1;i<=n;i++)cin>>v[i];
#define trav(a,x) for (auto& a: x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define cut(x) {cout<<x;return 0;}
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORB(i,a,b) for(int i=a;i>=b;i--)

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define nl '\n'
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
ll gcd(ll a, ll b)
{
	if (b==0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}
ll pow(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%MOD;
		b/=2;
		a=(a*a)%MOD;
	}
	return ans;
}

const int N=2005;
ll a[N][N],row[N][N],col[N][N],dia[N][N];
char g[N][N];
int main()
{
	fast
	ll n,m;
    cin>>n>>m;
    FOR(i,1,n)
    {
        string s;
        cin>>s;
        FOR(j,1,m)
        {
            g[i][j]=s[j-1];
        }
    }
    FOR(i,1,n)
    {
        FOR(j,1,m)
        {
            if(i==1 and j==1){a[i][j]=0;row[i][j]=1;col[i][j]=1;dia[i][j]=1;continue;}
            if(g[i][j]=='#')
            {
                row[i][j]=0;col[i][j]=0;row[i][j]=0;
                a[i][j]=0;
            }
            else
            {
                ll x=0,y=0,z=0;
                if(i-1>=1)x=col[i-1][j];
                if(i-1>=1 and j-1>=1)y=dia[i-1][j-1];
                if(j-1>=1)z=row[i][j-1];
                a[i][j]=x+y+z;
                row[i][j]=a[i][j]+(j-1>=1?row[i][j-1]:0);
                col[i][j]=a[i][j]+(i-1>=1?col[i-1][j]:0);
                dia[i][j]=a[i][j]+(j-1>=1 and i-1>=1?dia[i-1][j-1]:0);
                row[i][j]%=MOD;
                col[i][j]%=MOD;
                dia[i][j]%=MOD;
                a[i][j]%=MOD;
            }
        }
    }

   // FOR(i,1,n)FOR(j,1,m)cout<<dp[i][j]<<(j==m?nl:' ');
    cout<<a[n][m];

}

//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define P pair<ll,ll>
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;

ll lmax(ll x,ll y){
  if(x < y) return y;
  else return x;
}

ll lmin(ll x, ll y){
  if(x > y)return y;
  else return x;
}

void add(vector<string> &s,vector<vector<ll>> &v, ll a, ll b,vector<vector<ll>> &tate,vector<vector<ll>> &yoko,vector<vector<ll>> &naname){
  ll h = s.size(),w = s[0].size(),x = a, y = b;
  if(s[x-1][y-1] == '#')return;
  if(x+1 <= h){
    if(s[x+1-1][y-1] != '#'){
      v[x+1][y] += tate[x][y];
      tate[x+1][y] += 2*tate[x][y];
      yoko[x+1][y] += tate[x][y];
      naname[x+1][y] += tate[x][y];
      v[x+1][y] %= MOD;
      tate[x+1][y] %= MOD;
      yoko[x+1][y] %= MOD;
      naname[x+1][y] %= MOD;
    }
  }
  if(y+1 <= w){
    if(s[x-1][y+1-1] != '#'){
      v[x][y+1] += yoko[x][y];
      tate[x][y+1] += yoko[x][y];
      yoko[x][y+1] += 2*yoko[x][y];
      naname[x][y+1] += yoko[x][y];
      v[x][y+1] %= MOD;
      tate[x][y+1] %= MOD;
      yoko[x][y+1] %= MOD;
      naname[x][y+1] %= MOD;
    }
  }
  if(x+1 <= h && y+1 <= w){
    if(s[x+1-1][y+1-1] != '#'){
      v[x+1][y+1] += naname[x][y];
      tate[x+1][y+1] += naname[x][y];
      yoko[x+1][y+1] += naname[x][y];
      naname[x+1][y+1] += 2*naname[x][y];
      v[x+1][y+1] %= MOD;
      tate[x+1][y+1] %= MOD;
      yoko[x+1][y+1] %= MOD;
      naname[x+1][y+1] %= MOD;
    }
  }
}

int main(){
  ll H,W;
  cin >> H >> W;
  vector<string> S(H);
  rep(i,H) cin >> S[i];
  vector<vector<ll>> ans(H+1,vector<ll>(W+1,0));
  vector<vector<ll>> tate(H+1,vector<ll>(W+1,0)),yoko(H+1,vector<ll>(W+1,0)),naname(H+1,vector<ll>(W+1,0));
  ans[1][1] = 1,yoko[1][1] = 1,tate[1][1] = 1,naname[1][1] = 1;
  for(int i = 1;i <= H;i++){
    ll s = i,t = 1;
    while(s > 0 && t <= W){
      add(S,ans,s,t,tate,yoko,naname);
      s--;
      t++;
    }
  }
  for(int i = 2;i <= W;i++){
    ll s = H, t = i;
    while(s > 0 && t <= W){
      add(S,ans,s,t,tate,yoko,naname);
      s--;
      t++;
    }
  }

  cout << ans[H][W] << endl;

  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#define speed ios_base::sync_with_stdio(false),cout.tie(0),cin.tie(0)
#define fre freopen("in.txt","r",stdin),freopen("out.txt","w",stdout)
#define N 2*100005
#define M 2002
#define nd second
#define st first
#define endl "\n"
#define pii pair<ll,ll>
#define pb push_back
#define mp make_pair
#define inf 1e9+7
#define mid (start+end)/2
#define sp " "
typedef long long int ll;

string s;

void solve(){
    cin>>s;
    for (int i = 1; i < 3; ++i)
    {
        if(s[i]!=s[i-1]){
            cout<<"Lost";
            return;
        }
    }
    cout<<"Won";
}

int main()
{
    speed;
    // fre;
    int TT=1;
    //cin>>TT;
    while(TT--)solve();
    return 0;
}

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

typedef long long ll;

map<int64_t, int> prime_factor(int64_t n)
{
    map<int64_t, int> ret;
    for (int64_t i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

int main()
{
    char a, b, c;
    cin >> a >> b >> c;
    if (a == b && a == c)
    {
        cout << "Won" << endl;
    }
    else
    {
        cout << "Lost" << endl;
    }

    return 0;
}


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

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

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

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&...tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&...args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

int f(int x, int N) {
  for (int i = 10; i >= 0; i--) {
    if (x >= N && (x & (1 << i))) {
      x -= 1 << i;
    }
  }
  return x;
}

int main() {
  int N;

  scanf("%d", &N);

  for (int i = 0; i < N; i++) {
    int a = f(i * 2 + 0, N);
    int b = f(i * 2 + 1, N);
    printf("%d %d\n", a + 1, b + 1);
  }

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep2(i,j,n) for (int i=j; i <=(int)(n); i++)

int a[100010];

int main() {
	int n,m,p,q;

	cin >> n;

	rep2(i,1,n)a[i]=1;
	if(n==1){
		cout << 1 << endl;
		return 0;
	}
	m=n/2+1;
	rep2(i,1,m){
		p=i+i;
		q=a[i];
		while (p<=n) {
			if (a[p]==q)a[p]++;
			p+=i;
		}
	}
	rep2(i,1,n){
		cout << a[i] << " ";
	}
	return 0;
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

using namespace std;
//using namespace atcoder;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;

// edit

vector<int> primes = {
        2, 3, 5, 7, 11, 13, 17, 19,
        23, 29, 31, 37, 41, 43, 47,
        53, 59, 61, 67, 71,
};

vector<vector<ll>> dp;
ll A, B;
vector<int> xmask;

ll rec(int idx, int mask) {
    if (A + idx == B + 1) {
        return 1;
    }
    if (dp[idx][mask] != -1) {
        return dp[idx][mask];
    }

    ll ret = 0;

    ll x = A + idx;
    ret += rec(idx + 1, mask);
    if (mask & xmask[x - A]) {
    } else {
        int nmask = mask | xmask[x - A];
        ret += rec(idx + 1, nmask);
    }

//    cerr << A + idx << " " << mask << " " << ret << endl;
    return dp[idx][mask] = ret;
}

void solve() {
    cin >> A >> B;
//    while (primes.back() > B - A + 1) {
//        primes.pop_back();
//    }
    dp.resize(B - A + 1, vector<ll>(1 << (primes.size()), -1));
    xmask.resize(B - A + 1);
    for (ll x = A; x <= B; ++x) {
        xmask[x - A] = 0;
        for (int j = 0; j < primes.size(); ++j) {
            if (x % primes[j] == 0) {
                xmask[x - A] |= (1 << j);
            }
        }
    }

    ll ans = rec(0, 0);
    cout << ans << endl;

}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

vll d(100005, INF);
vpair edges[100005];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P>> que;
    d[s] = 0;
    que.push(P(0, s));

    while (que.size()) {
        P p = que.top();
        que.pop();
        int v = p.se;
        if (d[v] < p.fi) continue;
        for (auto e : edges[v]) {
            if (d[e.fi] > d[v] + e.se) {
                d[e.fi] = d[v] + e.se;
                que.push(P(d[e.fi], e.fi));
            }
        }
    }
}

int main() {
    int a, b, x, y;
    cin >> a >> b >> x >> y;
    --a;--b;

    rep(i, 100) {
        edges[i].emplace_back(i+100, x);
        edges[i+100].emplace_back(i, x);
    }
    rep(i, 99) {
        edges[i+1].emplace_back(i+100, x);
        edges[i+100].emplace_back(i+1, x);
        edges[i].emplace_back(i+1, y);
        edges[i+1].emplace_back(i, y);
        edges[i+100].emplace_back(i+101, y);
        edges[i+101].emplace_back(i+100, y);
    }

    dijkstra(a);

    cout << d[b+100] << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define each(e, v) for(auto &e: v)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct io_setup{
    io_setup(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

int main(){
    ll B, K; cin >> B >> K;

    if(K == 1) {cout << (B == 0? 1 : 2) << '\n'; return 0;}

    B = -B;
    vector<pll> P;

    P.eb(B, B+K/2+1);
    P.eb(-B-(K-1)/2, -B+1);
    P.eb(-B, -B+(K-1)/2+1);
    P.eb(B-(K-2)/2, B+1);

    sort(all(P));
    ll R = -INF*2;
    ll ans = 0;
    each(e, P){
        ll a = e.first, b = e.second;
        chmax(a, R), chmax(b, R);
        ans += b-a;
        chmax(R, b);
    }

    cout << ans << '\n';
}


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

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

  if (a < 100) cout << 1 << endl;

  else if (a % 100 == 0) {
    a /= 100;
    cout << a << endl;
  }
  else {
    a /= 100;
    a++;
    cout << a << endl;
  }
}

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

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

	int ans=0;
	for(int a=1;a<=k;a++){
		for(int b=1;b<=k/a;b++){
			ans+=k/a/b;
		}
	}
	printf("%d\n",ans);

	return 0;
}


//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FIO ios_base::sync_with_stdio(false); cin.tie(0);
#define trav(x,a) for (auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define case(t) cout << "Case #" << (t) << ": "
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const ld eps = 1e-9;

template<class T> void read(T& x) { cin >> x; }
template<class X, class Y> void read(pair<X,Y>& a) { read(a.first), read(a.second); }
template<class T, size_t U> void read(array<T,U>& x) { for (int i = 0; i < U; i++) read(x[i]); }
template<class T> void read(vector<T>& x) { trav(y, x) read(y); }
template<class T, class... O> void read(T& x, O&... y) { read(x), read(y...); }

string to_string(const char& x) { return string(1,x); }
string to_string(const char*& x) { return (string)x; }
string to_string(const string& x) { return x; }
template<class T, class U> string to_string(const pair<T,U>& x) { return to_string(x.first) + " " + to_string(x.second); }
template<class T, size_t U> string to_string(const array<T,U>& x) { string ret = ""; for (int i = 0; i < U; i++) ret += (!i ? "" : " ") + to_string(x[i]); return ret; }
template<class T> string to_string(const vector<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; }
template<class T> string to_string(const set<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; }
void print() { cout << endl; }
template<class T> void pr(const T& x) { cout << to_string(x); }
template<class T, class... O> void print(const T& x, const O&... y) { pr(x); if (sizeof...(y)) pr(" "); print(y...); }

int main() {
  FIO
  ll n; read(n);
  ll ans = n;
  for (ll b = 0; (1ll << b) <= n; b++) {
    ll c = n % (1ll << b);
    ll a = n / (1ll << b);
    ans = min(ans, a + b + c);
  }
  print(ans);
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;

int main() {
    ll n;
    cin >> n;
    ll a = 0, b = 0, c = 0;
    ll result = LONG_LONG_MAX;
    while (n > (1ll << b)) {
        a = n / (1ll << b);
        c = n % (1ll << b);
        result = min(result, a+b+c);
        b++;
    }
    if (b == 0) cout << 1 << endl;
    else cout << result << endl;
}


//clear adj and visited vector declared globally after each test case
//check for long long overflow
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Incase of close mle change language to c++17 or c++14
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007ll //998244353ll
#define lld long double
#define mii map<int, int>
#define pii pair<int, int>
#define ll long long
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
const long long N=2000005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
int fact[N],inv[N];
void pre()
{
    fact[0]=1;
    inv[0]=1;
    for(int i=1;i<N;i++)
    fact[i]=(i*fact[i-1])%mod;
    for(int i=1;i<N;i++)
    inv[i]=power(fact[i], mod-2, mod);
}
int nCr(int n, int r, int p)
{
    if(r>n)
    return 0;
    if(n==r)
    return 1;
    if (r==0)
    return 1;
    return (((fact[n]*inv[r]) % p )*inv[n-r])%p;
}

int32_t main()
{
    IOS;
    pre();
    int n, m, k;
    cin>>n>>m>>k;
    int ans=0;
    rep(i,max(0ll, n-m),k+1)
    {
        ans+=(nCr(n+m, m+i, mod) - nCr(n+m, m+i+1, mod) + mod)%mod;
        ans%=mod;
    }
    cout<<ans;
}

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

#ifdef LOCAL
#include "debug.hpp"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

ll MOD = 1e9 + 7;
ll kai(ll n) {
  if (n == 0) return 1;
  ll ans = 1;
  for (ll i = 1; i <= n; i++) {
    ans = (ans * i) % MOD;
  }
  return ans;
}
ll pow_mod(ll x, ll a) {
  if (a == 0) return 1;
  ll temp = pow_mod(x, a / 2);
  ll ans = (temp * temp) % MOD;
  if (a % 2) ans = (ans * x) % MOD;
  return ans;
}
ll inv(ll n) {
  return pow_mod(n, MOD - 2);
}
ll nCk(ll n, ll k) {
  ll ans = kai(n);
  ans = (ans * inv(kai(k))) % MOD;
  ans = (ans * inv(kai(n - k))) % MOD;
  return ans;
}

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

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

  if (N > M + K) {
    cout << 0 << '\n';
    return 0;
  }
  ll c = N - K;
  ll ans = nCk(N + M, N);
  ll temp = nCk(N + M, M + K + 1);
  if (c == 0) temp = 0;
  ans = (ans - temp + MOD) % MOD;
  cout << ans << '\n';
  return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
using ll = long long; using ull = unsigned long long;
// #define int ll
// #define DEBUG 42
inline void nprint(){}
template <class Head, class... Tail>
inline void nprint(Head &&head, Tail &&... tail) {
    cout << head << endl;
    nprint(move(tail)...);
}
#ifdef DEBUG
  #define eprint(...) nprint(__VA_ARGS__)
#else
  #define eprint(...) if(0==1) cout << 1 << endl;
#endif
#define Yes(a) cout << (a ? "Yes" : "No") << endl
#define YES(a) cout << (a ? "YES" : "NO") << endl
#define POSSIBLE(a) cout << (a ? "POSSIBLE" : "IMPOSSIBLE") << endl
using cmp = complex<double>;
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
template<class T>inline bool maxs(T& x, T y){
  if(x >= y) return false;
  x = y; return true;
}
template<class T>inline bool mins(T& x, T y){
  if(x <= y) return false;
  x = y; return true;
}
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORS(i,a,b) FOR(i,a,b+1)
#define REPS(i,n) REP(i,n+1)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define RREPS(i,n) RREP(i,n+1)
#define RFORS(i,a,b) RFOR(i,a,b+1)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define PERM(c) sort(ALL(c)); for(bool cp = true;cp;cp = next_permutation(ALL(c)))
#define eb(val) emplace_back(val)
inline ll bitcnt(ll val) { return __builtin_popcountll(val); }
const long double PI = std::acos(-1.0l);
constexpr int dx[] = {1,0,-1,0}; constexpr int dy[] = {0,1,0,-1};
template<typename Tail> auto type_vector(Tail&& tail){return tail;}
template<typename Head, typename... Tail> auto type_vector(Head&& head, Tail&&... tail){
  head = 0; return vector<decltype(type_vector(tail...))>(head);
}
template<typename Tail> auto make_vector(Tail&& tail){return tail;}
template<typename Head, typename... Tail> auto make_vector(Head&& head, Tail&&... tail){
  return vector<decltype(type_vector(tail...))>(head, make_vector(tail...));
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p){
  return s << "(" << p.first << ", " << p.second << ")";
}
template<class T> istream& operator>>(istream &is,vector<T> &st){
  for(size_t i=0;i<st.size();++i){is >> st[i];} return is;
}
template<class T> istream& operator>>(istream &is,vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i){is >> st[i];} return is;
}
template<class T> ostream& operator<<(ostream &os, const vector<T> &st){
  for(size_t i=0;i<st.size();++i) os << st[i] << (i!=st.size()-1?" ":"");
  return os;
}
ostream& operator<<(ostream &os, const vector<string> &st){
  for(size_t i=0;i<st.size();++i) os << st[i] << (i!=st.size()-1?"\n":"");
  return os;
}
template<class T> ostream& operator<<(ostream &os, const vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i) os << st[i] << (i!=st.size()-1?"\n":"");
  return os;
}
constexpr double EPS = 1e-10;
constexpr ll MOD = 1E9+7;
// constexpr ll MOD = 998244353;
signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string s;
  cin >> s;
  int ans = 0;

  REP(i,9){
    if(s.substr(i,4) == "ZONe") ++ans;
  }
  cout << ans << endl;
}

#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <string>
#include <numeric>
#include <iterator>
#include <climits>
#include <cmath>
#include <iomanip>

using namespace std;

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

int main()
{
  int n;
  cin >> n;
  int x[n];
  for (int i = 0; i < n; i++)
  {
    int a;
    cin >> a;
    x[i] = a < 0 ? (-a) : a;
  }
  long long Manhattan = 0;
  for (int i = 0; i < n; i++)
  {
    Manhattan += (long long)x[i];
  }

  long long square_sum = 0;
  for (int i = 0; i < n; i++)
  {
    square_sum += ((long long)x[i] * (long long)x[i]);
  }
  long double Euclid = (long double)sqrt(square_sum);
  int ChebyChef = 0;
  for (int i = 0; i < n; i++)
  {
    if (ChebyChef < x[i])
    {
      ChebyChef = x[i];
    }
  }
  cout << Manhattan << endl;
  cout << fixed << setprecision(10) << Euclid << endl;
  cout << ChebyChef << endl;
  return 0;
}


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

#ifdef LOCAL
    #include "debug.h"
    #define input freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
    #define debug(...) 4
    #define input 4
#endif

using ll = long long;
const int mod = 1e9 + 7;
const int N = 2e6 + 5;

int dp[12][12];
//Beggar - C(n+r-1,r-1)
int fac[N],invf[N];
inline int add(int x, int y) {
    return x + y >= mod ? x + y - mod : x + y;
}
inline int sub(int x, int y) {
    return x - y >= 0 ? x - y : x - y + mod;
}
inline int power(int x, int y, int res = 1) {
    while(y) {
        if(y & 1)
            res = 1ll * res * x % mod;
        x = 1ll * x * x % mod;
        y >>= 1;
    }
    return res;
}
void initcombi(int n) {
    for (int i = fac[0] = 1; i <= n; i++) {
        fac[i] = 1ll * fac[i - 1] * i % mod;
    }
    invf[n] = power(fac[n], mod - 2);
    for (int i = n; i; i--) {
        invf[i - 1] = 1ll * invf[i] * i % mod;
    }
}
inline int NCR(int n, int m) {
    if (n < m)
        return 0;

    return 1ll * fac[n] * invf[m] % mod * invf[n - m] % mod;
}

signed main() {
    input;
    cin.tie(nullptr) -> sync_with_stdio(false);
    ll x, y;
    cin >> x >> y;
    for(int i = 1; i <= sqrt(y); i++) {
        ll d = y / i;
        if(i + d == x) {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";

}

// C++ (GCC9.2.1) AtCoder
/*
Ctrl+Option+N で　実行

*/

#include <bits/stdc++.h>
#define INF 100000000000
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int M,H; cin>>M>>H;
  string ans = "No";
  if(H % M == 0) ans = "Yes";
  print(ans);

  return 0;
}


#include <map>
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int n;
int o[300111];
map<ll, ll> mp;
int main(void) {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &o[i]);
	}
	for (int i = 1; i <= n; i += 2) {
		o[i] *= -1;
	}

	ll s = 0;
	for (int i = 0; i <= n; i++) {
		s += o[i];
		mp[s]++;
	}

	ll ans = 0;
	for (auto [k, v] : mp) {
		ans += v * (v - 1) / 2;
	}

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

#include <bits/stdc++.h>
//#include <atcoder/modint>
//using namespace atcoder;
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
using P = pair<ll, ll>;
using tp = tuple<ll, ll, ll>;
const ll INF = (1LL<<61);

template<class T> bool chmin(T &a, const T b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T b){
    if(a < b) {a = b; return true;}
    else return false;
}
template<class T> void my_printv(std::vector<T> v,bool endline = true){
    if(!v.empty()){
        for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" ";
        std::cout<<v.back();
    }
    if(endline) std::cout<<std::endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin>>N;
    vec a(N);
    ll sum{}, res{};
    unordered_map<ll, ll> num;
    num[0] = 1;
    rep(i, N){
        cin>>a[i];
        sum += (i&1 ? a[i] : -a[i]);
        res += num[sum];
        num[sum] += 1;
    }
    cout<<res<<endl;
}


#include <bits/stdc++.h>
using namespace std;
const int N=2e6+50;
int n,m;
int a[N],b[N];
int mex;
void add(int i){
    b[a[i]]++;
    // 变大根本没意义啊
//    if(a[i]==mex){
//        mex=a[i]+1;
        // TODO tle了
//        while(b[mex]){
//            mex++;
//        }
//    }
}
void del(int i){
    b[a[i]]--;
    if(b[a[i]]==0 && a[i]<mex){
        mex=a[i];
    }
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=m;i++){
        add(i);
    }
    for(int i=0;i<=n;i++){
        if(b[i]==0){
            mex=i;
            break;
        }
    }
    for(int i=m+1;i<=n;i++){
        add(i);
        del(i-m);
    }
    printf("%d\n",mex);
    return 0;
}

#include <bits/stdc++.h>

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

#define ll long long
#define ld long double
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mkpr make_pair
#define fi(i,a,b) for (ll i=a;i<b;i++)
#define vll vector<ll>
#define vch vector<char>
#define vst vector<string>
#define vpll vector<pll>
#define vii vector<int>
#define vvl vector<vector<ll>>
#define all(v) v.begin(),v.end()
#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(), v.rend())
#define mxe(v) *max_element(v.begin(),v.end())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define mll map<ll, ll>
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b)
#define nl "\n"
#define sp " "
#define sz(x)  (int)x.size()

using namespace std;

double PI = (acos(-1));
ll md = 1000000007;
//ll md = 998244353;
ll pw(ll a, ll b){ll c=1,m=a;while (b){if (b&1)c=(c*m);m=(m*m);b/=2;}return c;}
ll pwmd(ll a, ll b){ll c = 1, m = a;while (b){if (b & 1)c = ((c * m)) % md;m = (m * m) % md;b /= 2;}return c;}
ll modinv(ll n){return pwmd(n, md - 2);}
ll nc2(ll n){return (1ll * n * (n - 1)) / 2;}
bool prime(ll a){for(int i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ceel(ll a,ll b){if(a%b==0) return a/b;else return a/b+1;}

#define MAX_SIZE 1000005
void Sieve(vector<int> &primes){bool IsPrime[MAX_SIZE];memset(IsPrime, true, sizeof(IsPrime));
for (int p = 2; p * p < MAX_SIZE; p++){if (IsPrime[p] == true){
            for (int i = p * p; i < MAX_SIZE; i += p)IsPrime[i] = false;}}
    for (int p = 2; p < MAX_SIZE; p++)if (IsPrime[p])primes.push_back(p);}

//vector<char> sml={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vector<char> cap={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};

void solve(){
    ll n,m;
    cin>>n>>m;
    ll l[n];
    fi(i,0,n)cin>>l[i];
    map<ll,ll>mp;
    set<ll>s;
    fi(i,0,n+1)s.insert(i);
    fi(i,0,m){
        if(mp[l[i]]==0)s.erase(l[i]);
        mp[l[i]]++;
    }
    auto itr=s.begin();
    ll mx=*itr;
    fi(i,m,n){
        if(mp[l[i-m]]==1)s.insert(l[i-m]);
        mp[l[i-m]]--;
        if(mp[l[i]]==0)s.erase(l[i]);
        mp[l[i]]++;
        auto z=s.begin();
        mx=min(mx,*z);
    }
    cout<<mx;
}

int main(){
    //vector<int> primes;
    //Sieve(primes);

    fast
    ll tests=1;
    //cin>>tests;
    while(tests--){
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    ll n,m,k,ans=0;
    cin>>n>>m;
    vector<vector<ll>> a(m,vector<ll>(2));
    vector<ll> c(n+1,0);
    for(ll i=0;i<m;i++) cin>>a[i][0]>>a[i][1];
    cin>>k;
    vector<vector<ll>> b(k,vector<ll>(2));
    for(ll i=0;i<k;i++) cin>>b[i][0]>>b[i][1];
    for(ll i=0;i<(1LL<<k);i++)
    {
        ll x=0;
        for(ll j=0;j<k;j++)
        {
            if((1LL<<j)&i) c[b[j][1]]=1;
            else c[b[j][0]]=1;
        }
        for(ll j=0;j<m;j++)
        {
            if(c[a[j][0]]&&c[a[j][1]]) x++;
        }
        for(ll j=0;j<=n;j++) c[j]=0;
        ans=max(ans,x);
    }
    cout<<ans;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll LINF = 1e18;
template <class T>
void get_unique(vector<T>& x) {
    x.erase(unique(x.begin(), x.end()), x.end());
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
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...));
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (int i = 0; i < int(v.size()); i++) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (int i = 0; i < int(v.size()); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << ' ';
    }
    return os;
}
struct UnionFind {
    vector<int> data;
    vector<map<int, int>> mp;
    UnionFind(int size, vector<map<int, int>> _mp) : data(size, -1), mp(_mp) {
    }
    int root(int x) {
        return (data[x] < 0) ? x : data[x] = root(data[x]);
    }
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
            for (auto [key, num] : mp[y]) {
                mp[x][key] += num;
            }
        }
        return x != y;
    }
    bool find(int x, int y) {
        return root(x) == root(y);
    }
    int size(int x) {
        return -data[root(x)];
    }
};
int main() {
    int n, q;
    cin >> n >> q;
    vector<map<int, int>> mp(n);
    rep(i, n) {
        int c;
        cin >> c;
        mp[i][c] = 1;
    }
    UnionFind uf(n, mp);
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int a, b;
            cin >> a >> b;
            a--, b--;
            uf.unite(a, b);
        }
        if (t == 2) {
            int x, y;
            cin >> x >> y;
            x--;
            cout << uf.mp[uf.root(x)][y] << '\n';
        }
    }
}


#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

int compare_array(vector<int> a1, vector<int>a2) {
  int n1 = a1.size();
  int n2 = a2.size();
  if (n1 != n2) {
    return n1 - n2;
  }
  for (int i=0; i<n1; i++) {
    if (a1.at(i) != a2.at(i)) {
      return a1.at(i) - a2.at(i);
    }
  }
  return 0;
}

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

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
  long ans = 1;
  for (int i = n; i > n - r; --i) {
    ans = ans*i;
  }
  for (int i = 1 ; i < r + 1; ++i) {
    ans = ans / i;
  }
  return ans;
}

long modinv(long a, long m) {
  long b = m, u = 1, v = 0;
  while (b) {
    long t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

bool is_prime(int a) {
  int i = 2;
  while(i * i <= a) {
    if(a % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}

vector<vector<int>> all_comb(int n, int k) {
  vector<vector<int>> combs(nCr(n, k), vector<int>(k));
  for(int i=0; i<k; i++) {
    combs[0][i] = i;
    combs[1][i] = i;
  }

  for(long i=1; i<nCr(n, k); i++) {
    int p = 1;
    while(combs[i][k - p] == n - p) {
      p++;
      if(p > k) {
        break;
      }
    }
    combs[i][k - p]++;
    int q = combs[i][k - p];
    for(int j=1; j<p; j++) {
      combs[i][k - p + j] = q + j;
    }

    if(i < nCr(n, k) - 1) {
      for(int j=0; j<k; j++) {
        combs[i + 1][j] = combs[i][j];
      }
    }
  }

  return combs;
}

struct UnionFind {
  vector<int> parent;

  UnionFind(int n) : parent(n) {
    for(int i=0; i<n; i++) {
      parent[i] = i;
    }
  }

  int root(int x) {
    if (parent[x] == x) {
      return x;
    }
    return parent[x] = root(parent[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    parent[rx] = ry;
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

template <typename TYPE> void co(TYPE a) {
  cout << a << endl;
}

template <typename TYPE> void co_2(TYPE a, TYPE b) {
  cout << a << ' ' << b << endl;
}

template <typename TYPE> void co_l(vector<TYPE> as) {
  int n = as.size();
  for(int i=0; i<n; i++) {
    cout << as[i] << endl;
  }
}

template <typename TYPE> void co_s(vector<TYPE> as) {
  int n = as.size();
  for(int i=0; i<n; i++) {
    if(i > 0) {
      cout << ' ';
    }
    cout << as[i];
  }
  cout << endl;
}

int main() {
  std::cout << std::setprecision(9);
  long mod = 1000000007;
  int n;
  cin >> n;
  if(n % 2 == 0) {
    co("White");
  }
  else {
    co("Black");
  }
}

#include<bits/stdc++.h>
#define db double
#define reg register
#define LL long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define ull unsigned long long
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
#define erep(i,a) for(int i=head[a];i;i=e[i].nxt)

using namespace std;
bool Handsome;
inline void Mi(int &x,int y){if(x>y && (x=y));}
inline void Mx(int &x,int y){if(x<y && (x=y));}
const int M=2e5+5;
int n,a[M],b[M],c[M<<1],d[M],ct;
vector<int> ga[M<<1],gb[M<<1];
struct BIT{
	int t[M];
	void add(int x){
		for(;x;x-=x&-x)++t[x];
	}
	int ask(int x){
		int res=0;
		for(;x<=n;x+=x&-x)res+=t[x];
		return res;
	}
}bit;
bool Most;
int main(){
//	printf("%.2lfMB\n",(&Most-&Handsome)/1024.0/1024.0);
	scanf("%d",&n);
	rep(i,1,n)scanf("%d",&a[i]),c[++ct]=(a[i]+=i);
	rep(i,1,n)scanf("%d",&b[i]),c[++ct]=(b[i]+=i);
	sort(c+1,c+ct+1);ct=unique(c+1,c+ct+1)-c-1;
	rep(i,1,n)ga[lb(c+1,c+ct+1,a[i])-c].pb(i);
	rep(i,1,n)gb[lb(c+1,c+ct+1,b[i])-c].pb(i);
	rep(i,1,ct){
		sort(ga[i].begin(),ga[i].end());
		sort(gb[i].begin(),gb[i].end());
		if(ga[i].size()!=gb[i].size())return puts("-1"),0;
		rep(j,0,ga[i].size()-1){
			int x=ga[i][j],y=gb[i][j];
			d[y]=x;
		}
	}
	LL ans=0;
	rep(i,1,n)ans+=bit.ask(d[i]),bit.add(d[i]);
	printf("%lld\n",ans);
	return 0;
}


#include <iostream>
using namespace std;

int hantei(long long n);

int main(){
  long long t, n;
  cin >> t;
  for (int i = 0; i < t; i++){
    cin >> n;
    if (hantei(n) == -1) cout << "Odd" << endl;
    else if (hantei(n) == 0) cout << "Same" << endl;
    else if (hantei(n) == 1) cout << "Even" << endl;
  }
  return 0;
}

int hantei(long long n){
  if (n % 2 == 1) return -1;
  else if (n % 4 == 0) return 1;
  else return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll N;
  scanf("%lld",&N);
  vector<ll> x(N);
  ll man = 0;
  ll you = 0;
  ll che = 0;
  for(ll i = 0; i < N; i++) {
    scanf("%lld",&x.at(i));
    man += abs(x.at(i));
    you += pow(x.at(i),2);
    if(che < abs(x.at(i))) che = abs(x.at(i));
  }
  printf("%lld\n%.10f\n%lld\n",man,sqrt(you),che);
  return 0;
}


#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define setval(arr,v) memset(arr,v,sizeof(arr));
#define int long long int
#define mod 1000000007
#define v vector
#define umap unordered_map
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define fi first
#define se second
#define INF 1000000000000000
using namespace std;

void solve()
{
	int x,y;
	cin>>x>>y;
	if(x == y)
		cout<<x;
	else
	{
		for (int i = 0; i < 3; ++i)
		{
			if(x != i && y != i)
				cout<<i;
		}
	}

}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;

}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const int inf = 1 << 30;
const ll infll = 1LL << 60;
const int mod = 1000000007;
const int mod9 = 998244353;

int main(){
    int x, y;
    cin >> x >> y;

    if((x + y)%3 == 0){
        cout << 0 << endl;
    }
    else if((x + y)%3 == 1){
        cout << 2 << endl;
    }
    else{
        cout << 1 << endl;
    }
}


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

typedef long long int ll;
using ii= pair<ll,ll>;
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define all(o) (o).begin(),(o).end()
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ld long double
#define eps 0.00000000001
#define mod 1000000007

class prioritize{
    public: bool operator() (ii &p1,ii &p2){
        return p1.F<p2.F;
    }
};

auto start_time= high_resolution_clock::now();
void time()
{
    #ifndef ONLINE_JUDGE
        auto stop_time= high_resolution_clock::now();
        auto duration= duration_cast<milliseconds>(stop_time-start_time);
        cout<<"run time: "<<duration.count()<<" ms"<<"\n";
    #endif
    return;
}

void ojudge()
{
	#ifndef ONLINE_JUDGE
        freopen("input1.txt","r", stdin);
        freopen("output1.txt","w",stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    return;
}

int main()
{
    ojudge();

    ll n;
    cin>>n;

    vector<pair<ll,string>> v(n);

    fr(i,0,n){
    	cin>>v[i].S>>v[i].F;
    }

    sort(all(v));

    cout<<v[n-2].S<<"\n";

    time();
    return 0;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)

const ll INF = 1000000000000; //10^12:∞
const ll MOD = 1000000007; //10^9+7:合同式の法

void swap(ll &a, ll &b) {
    ll temp = a;
    a = b;
    b = temp;
}

int main(){
    ll N;
    cin >> N;
    vector<ll> P(N);
    for(ll &p : P) {
        cin >> p;
    }
    vector<ll> ans;
    ll target = 1;
    ll cur = 0;
    for(ll i = 1; i < N; i++) {
        if(P.at(i) == target) {
            for(ll j = i; j >= target; j--) {
                swap(P.at(j), P.at(j - 1));
                ans.push_back(j);
            }
            for(ll j = target - 1; j < i; j++) {
                if(P.at(j) != j + 1) {
                    cout << -1 << endl;
                    return 0;
                }
            }
            target = i + 1;
        }
    }
    // targetがNでない→すべてのswapを使っていない
    if(target != N) {
        cout << -1 << endl;
        return 0;
    }
    for(const ll &elm : ans) {
        cout << elm << endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

typedef long long ll;

const int MOD = 998244353;

struct Modint {
  ll val;

  Modint (ll _val = 0)
    : val(_val % MOD) {}

  Modint operator+ (Modint other) const {
    return Modint(val + other.val);
  }

  void operator+= (Modint other) {
    val += other.val;
    val %= MOD;
  }

  Modint operator- () const {
    return Modint(MOD - val);
  }

  Modint operator- (Modint other) const {
    return Modint(val + MOD - other.val);
  }

  void operator-= (Modint other) {
    val += MOD - other.val;
    val %= MOD;
  }

  Modint operator* (Modint other) const {
    return Modint(val * other.val);
  }

  void operator*= (Modint other) {
    val *= other.val;
    val %= MOD;
  }

  bool operator== (Modint other) const {
    return val == other.val;
  }

  bool operator!= (Modint other) const {
    return val != other.val;
  }
};

Modint exp (Modint a, int k) {
  if (k == 0) {
    return Modint(1);
  } else if (k % 2 == 0) {
    Modint half = exp(a, k / 2);
    return half * half;
  } else {
    return a * exp(a, k - 1);
  }
}

Modint inv (Modint a) {
  return exp(a, MOD - 2);
}

ostream& operator<< (ostream& out, Modint p) {
  out << p.val;
  return out;
}

int main () {
  int n, m;
  cin >> n >> m;

  Modint ans = Modint(n) * exp(Modint(m), n);
  Modint im = inv(Modint(m));
  for (int j = 1; j <= m; j++) {
    Modint emj (1); // (m - j) ^ (v - 1)
    Modint emnv (0);
    if (n - 2 >= 0) {
      emnv = exp(Modint(m), n - 2);
    }
    for (int v = 1; v < n; v++) {
      ans -= Modint(n - v) * emj * emnv;

      emj *= Modint(m - j);
      emnv *= im;
    }
  }

  cout << ans << endl;
}

//g++  7.4.0

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

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

    ll N,M; cin>>N>>M;
    string s[N];
    ll ans = 1;

    for(ll i=0;i<N;++i)
        cin>>s[i];

    for(ll j=0;j<M;++j)
    {
        ll i = 0;
        ll jj = j;
        ll tot_R = 0;
        ll tot_B = 0;
        while(i >= 0 && jj >= 0 && i < N && jj < M)
        {
            //cout<<i<<" "<<jj<<endl;
            if(s[i][jj] == 'R')
                tot_R++;
            else if(s[i][jj] == 'B')
                tot_B++;
            --jj;
            ++i;

        }

        //cout<<"----------"<<endl;

        if(tot_R != 0 && tot_B != 0)
        {
            cout<<0<<endl;
            return(0);
        }

        if(!tot_R && !tot_B)
            ans *= 2LL;

        ans %= MOD;
    }

    for(ll i=1;i<N;++i)
    {
        ll ii = i;
        ll j = M - 1;
        ll tot_R = 0;
        ll tot_B = 0;
        while(j >= 0 && ii >= 0 && j < M && ii < N)
        {

            if(s[ii][j] == 'R')
                tot_R++;
            else if(s[ii][j] == 'B')
                tot_B++;

            j--;
            ii++;
        }

        if(tot_R != 0 && tot_B != 0)
        {
            cout<<0<<endl;
            return(0);
        }

        if(!tot_R && !tot_B)
            ans *= 2LL;

        ans %= MOD;
    }

    cout<<ans<<endl;
}


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

void solve() {
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int c1 = 0, c2 = 0;
		for (int j = i; j < n; ++j) {
			if (s[j] == 'A')
				c1++;
			else if (s[j] == 'T')
				c1--;
			else if (s[j] == 'C')
				c2++;
			else
				c2--;
			if (c1 == 0 && c2 == 0) ans++;
		}
	}
	cout << ans << '\n';
}

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

	int tt = 1;
	// cin >> tt;
	for (int i = 1; i <= tt; ++i) {
		solve();
	}

	return 0;
}

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define N +100500
//#define M ll(998244353)
#define M ll(1e9 + 7)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e18)
#define el '\n'
#define pii pair <int, int>
#define all(x) (x).begin(), (x).end()
#define arr_all(x, n) (x + 1), (x + 1 + n)
#define vi vector <int>
#define last(x) (x).back()
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;

string s;
int n, i, c[300], mp[4], j, ans;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout << setprecision(6);
    cout << fixed;
//    in("sequence.in");
//    out("sequence.out");
//    in("D:/cpp/2/output.txt");
//    out("output.txt");

    c['A'] = 0;
    c['T'] = 1;
    c['G'] = 2;
    c['C'] = 3;

    cin >> n >> s;

    for (i = 0; i < n; i++)
    {
        mp[0] = mp[1] = mp[2] = mp[3] = 0;

        for (j = i; j < n; j++)
        {
            mp[c[s[j]]]++;

            if (mp[0] == mp[1] && mp[2] == mp[3])
                ans++;
        }
    }
    cout << ans;
}


#include<bits/stdc++.h>
using namespace std;
//#include <atcoder/lazysegtree>
//using namespace atcoder;
//using mint = modint998244353;
//using mint = modint1000000007;
#pragma region template
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define overload4(_1,_2,_3,_4,name,...) name
#define overload3(_1,_2,_3,name,...) name
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i=n;i--;)
#define rrep2(i,n) for(ll i=n;i--;)
#define rrep3(i,a,b) for(ll i=b;i-->(a);)
#define rrep(...) overload3(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define debug(var)  do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cerr << endl;int cnt = 0;for(const auto& v : vv){cerr << cnt << "th : "; view(v); cnt++;} cerr << endl;}
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}
template<class T, class K>bool chmax(T &a, const K b) { if (a<b) { a=b; return 1; } return 0; }
template<class T, class K>bool chmin(T &a, const K b) { if (b<a) { a=b; return 1; } return 0; }
const int inf = 1001001001;
const ll INF = 1001001001001001001ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll rddiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // -20 / 3 == -7
ll power(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a;} a = a * a; p >>= 1;} return ret;}
ll modpow(ll a, ll p, ll mod){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;}
ll rudiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } //  20 / 3 == 7
#pragma endregion
// const double pi = acos(-1);
//const ll mod = 998244353;
const ll mod = 1000000007;

int dp[2001][2001];
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(20);
    int h, w; cin >> h >> w;
    V<string> mp(h);
    rep(i,h) cin >> mp[i];
    rep(i,2001) rep(j,2001) dp[i][j] = -inf;
    dp[h - 1][w - 1] = 0;
    rrep(i,h){
        rrep(j,w){
            if(j - 1 >= 0){
                if(mp[i][j] == '-') chmax(dp[i][j - 1], -dp[i][j] - 1);
                else chmax(dp[i][j - 1], -dp[i][j] + 1);
            }
            if(i - 1 >= 0){
                if(mp[i][j] == '-') chmax(dp[i - 1][j], -dp[i][j] - 1);
                else chmax(dp[i - 1][j], -dp[i][j] + 1);
            }
        }
    }
    if(dp[0][0] == 0) cout << "Draw" << endl;
    else if(dp[0][0] > 0) cout << "Takahashi" << endl;
    else cout << "Aoki" << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll mod=1e9+7;
#define rep(i,n) for (int i = 0; i < (n); i++)
int n,m,a[1100],b[1100];
vector <pair<int,char>> g[1100];
ll dp[1100][1100];
int main(){
    cin >> n >> m;
    rep(i,n)rep(j,n) dp[i][j]=mod;
    rep(i,m){
        char c;
        cin >> a[i] >> b[i] >> c;
        a[i]--;b[i]--;
        g[a[i]].emplace_back(b[i],c);
        g[b[i]].emplace_back(a[i],c);
    }
    queue<P> q;
    dp[0][n-1]=0;
    q.emplace(0,n-1);
    while(!q.empty()){
        int a=q.front().first;
        int b=q.front().second;
        q.pop();
        for(auto e:g[a])for(auto f:g[b]){
            if(e.second == f.second){
                if(dp[e.first][f.first]==mod){
                    dp[e.first][f.first]=dp[a][b]+1;
                    q.emplace(e.first,f.first);
                }
            }
        }
    }
    ll ans=mod;
    rep(i,n)ans=min(ans,dp[i][i]*2);
    rep(i,m)ans=min({ans,dp[a[i]][b[i]]*2+1,dp[b[i]][a[i]]*2+1});
    if(ans==mod)cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}


// 解き直し.
// https://atcoder.jp/contests/arc105/editorial/170
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define all(x) x.begin(), x.end()
LL cW[11], bL[101010], bV[101010];

struct bridge{
    LL l, v; // 長さ, 耐荷重.
    bool operator < (const bridge& rhs) const{
        return (v != rhs.v) ? (v > rhs.v) : (l < rhs.l);
    }
};

int main(){

    // 1. 入力情報.
    int N, M;
    scanf("%d %d", &N, &M);
    LL maxW = 0, minV = 202020202020202020;
    rep(i, N){
        scanf("%lld", &cW[i]);
        maxW = max(maxW, cW[i]);
    }
    priority_queue<bridge> pq;
    rep(i, M){
        LL l, v;
        scanf("%lld %lld", &l, &v);
        minV = min(minV, v);
        pq.push({l, v});
    }

    // 2. 橋が崩落するパターンを除外.
    if(maxW > minV){
        puts("-1");
        return 0;
    }

    // 3. 橋の耐荷重に対する必要な最小間隔を保存.
    int idx = 0;
    while(!pq.empty()){
        bridge b = pq.top();
        pq.pop();
        // printf("b.l=%lld b.v=%lld\n", b.l, b.v);
        bL[idx + 1] = max(bL[idx], b.l);
        bV[idx + 1] = b.v;
        idx++;
    }
    // rep(i, M + 1) printf("l=%lld v=%lld\n", bL[i], bV[i]);

    // 4. ラクダの隊列を全探索.
    vector<int> z(N);
    iota(all(z), 0);
    LL ans = -202020202020202020;
    do{
        // 4-1. ラクダの隊列の重量(累積和).
        LL cWCum[N + 1];
        memset(cWCum, 0LL, sizeof(cWCum));
        rep(i, N) cWCum[i + 1] = cWCum[i] + cW[z[i]];
        // rep(i, N) printf("%d ", z[i]);
        // puts("");
        // rep(i, N + 1) printf("%lld ", cWCum[i]);
        // puts("");

        // 4-2. 制約.
        LL x[N][N];
        memset(x, 0LL, sizeof(x));
        rep(i, N){
            repx(j, i + 1, N){
                int at = lower_bound(bV, bV + M + 1, cWCum[j + 1] - cWCum[i]) - bV - 1;
                x[i][j] = max(x[i][j], bL[at]);
                x[j][i] = x[i][j];
            }
        }
        // rep(i, N){
        //     repx(j, i + 1, N) printf("%lld ", x[i][j]);
        //     puts("");
        // }

        // 4-3. グラフの最長路の長さは？
        // ex.
        // AtCoder Beginner Contest 022 (C - Blue Bird) を ベース に 実装.
        // https://atcoder.jp/contests/abc022/tasks/abc022_c
        // -> 具体的には, Warshall–Floyd法で,
        // repx(k, 1, N) repx(i, 1, N) repx(j, 1, N) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        // とあるものを, i = 0 に 固定するイメージで, 更新する形に変更.
        LL g[N][N], way = 0;
        memset(g, 0LL, sizeof(g));
        repx(i, 1, N){
            rep(j, i + 1){
                g[0][i] = min(g[0][i], g[0][j] - x[i][j]);
                way = min(way, g[0][i]);
                // printf("i=%d j=%d %lld \n", i, j, x[i][j]);
            }
        }

        // 4-4. 最長路の長さについて, 最小値を更新.
        ans = max(ans, way);
    }while(next_permutation(all(z)));

    // 5. 出力.
    printf("%lld\n", -ans);
    return 0;

}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll mod = 1e9 + 7;
const ll linf = 1LL << 62;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N, K;
int A[810][810];
int cnt[810][810];

int main() {
    cin >> N >> K;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            cin >> A[i][j];
        }
    }
    int lb = -1, ub = 1e9 + 1;
    while (ub - lb > 1) {
        int mid = (ub + lb) / 2;
        for (int i = 1; i <= N ; i++) {
            for (int j = 1; j <= N; j++) {
                cnt[i][j] = (A[i][j] <= mid);
            }
        }
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= N; j++) {
                cnt[i][j + 1] += cnt[i][j];
            }
        }
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= N; j++) {
                cnt[i + 1][j] += cnt[i][j];
            }
        }
        bool flag = false;
        for (int i = K; i <= N; i++) {
            for (int j = K; j <= N; j++) {
                int aa = cnt[i][j] - cnt[i - K][j] - cnt[i][j - K] + cnt[i - K][j - K];
                if (aa >= (K * K) - ((K * K) / 2)) flag = true;
            }
        }
        if (flag) ub = mid;
        else lb = mid;
    }
    cout << ub << endl;
}


#include <iostream>
#include <string>
int main()
{
    std::string S, sub, bs = "";
    std::cin >> S;
    int i = 0;
    while (!(S.substr(i, 1).empty()))
    {
        //std::cout << "a" << std::endl;
        sub = S.substr(i, 1);
        if (sub == "6")
        {
            sub = "9";
        }
        else if (sub == "9")
        {
            sub = "6";
        }
        bs = sub + bs;
        i++;
    }
    std::cout << bs << std::endl;
}

#include<bits/stdc++.h>
#define N
using namespace std;
typedef long long ll;
string s;
int main(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='.')break;
		cout<<s[i];
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <utility>
using ll = long long;
//#define rep(i, n) for(int i = 0; i < (int)(n); i++)

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
using namespace std;

ll n;
ll sum = 0;
ll m;
ll k;
ll minV;

int main() {
    vector<ll> v;
    cin >> n >> m;
    rep(i,m) {
    	cin >> k;
    	v.push_back(k);
    }
    if (m == 0) {
        cout << 1;

    	return 0;
    }

    sort(v.begin(), v.end());
    if(v[v.size()-1] != n) v.push_back(n+1);

    minV = 1000001000;
    if (v[0] - 1 < minV && v[0] != 1) minV = v[0] - 1;
    for (int i = 1; i < v.size(); i++)
    {
        if (v[i] - v[i-1] -1 < minV && (v[i] - v[i-1] -1) != 0) minV = v[i] - v[i-1] -1;
    }
    if (v[0] != 0){
        if ((v[0] - 1) % minV == 0){
        	sum += (v[0] - 1) / minV;
        }
        else{
        	sum += (v[0] - 1) / minV + 1;
        }
    }

    if (minV == 1000001000) {
        cout << 0;

    	return 0;
    }
    for (int i = 1; i < v.size(); i++)
    {
        if((v[i] - v[i-1]-1) % minV == 0){
        	sum += (v[i] - v[i-1] -1) / minV;
        }
        else{
        	sum += (v[i] - v[i-1]-1) / minV + 1;
        }
    }

    cout << sum;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1e9+7;
const int MAXN = 2e5 + 7;
int k;
ll dp[MAXN][17];
// dp[i][j] = number of possibilities up to digit i
//smaller than n, nonzero, with j distinct digits
string n;
map<char,int> mp;
int mask = 0;

int main(){
    for(char c='0'; c<='9'; c++)mp[c] = c-'0';
    for(char c='A'; c<='F'; c++)mp[c] = 10 + c-'A';

    cin >> n >> k;

    for(int i=0; i < (int)n.size(); i++){

        int aux = mp[n[i]];//current digit

        if(i > 0){
            //possibilities that were smaller before
            for(int j=1; j<=16; j++){//just add any digit
                dp[i][j] = (dp[i][j] + j*dp[i-1][j])%MOD;//already j
                dp[i][j] = (dp[i][j] + (17-j)*dp[i-1][j-1])%MOD;//was j-1, add new
            }

            //possibilities that become smaller now
            for(int digit=0; digit < aux; digit++){
                if( mask == (mask|(1<<digit)) ){//repeated
                    dp[i][__builtin_popcount(mask)] = (dp[i][__builtin_popcount(mask)] + 1)%MOD;
                }else{
                    dp[i][__builtin_popcount(mask) + 1] = (dp[i][__builtin_popcount(mask) + 1] + 1)%MOD;
                }
            }
        }
        //first nonzero digit
        if(i > 0)dp[i][1] = (dp[i][1] + 15)%MOD;
        else dp[i][1] = (dp[i][1] + aux - 1)%MOD;

        mask |= (1<<aux);
    }

    int acc = 0;
    if(__builtin_popcount(mask) == k)acc = 1;//n inclusive

    cout<<(dp[(int)n.size()-1][k]  + acc)%MOD<<endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll> ;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll inf=1LL<<60;
ll min(ll a,ll b){return a>=b ? b:a;}
ll max(ll a,ll b){return a>=b ? a:b;}

ll dist[20][20];
ll k;
vector<ll> G[100009];
vector<ll> C;

void bfs(ll st,ll cnt){
    vector<ll> cost(100009,inf);
    queue<ll> q;
    cost[st]=0;
    q.push(st);
    while (!q.empty()){
        ll x=q.front();q.pop();
        for (ll i:G[x]){
            if (cost[i]>cost[x]+1){
                cost[i]=cost[x]+1;
                q.push(i);
            }
        }
    }
    rep(i,k){
        dist[cnt][i]=cost[C[i]];
    }
}

int main(){
    ll n,m;
    cin >> n >> m;
    rep(i,m){
        ll a,b;cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    cin >> k;
    C.resize(k);
    rep(i,k){
        ll c;cin >> c;
        c--;C[i]=c;
    }
    rep(i,k){
        bfs(C[i],i);
    }
    //rep(i,k) rep(j,k) cout << dist[i][j] << endl;
    vector<vector<ll>> dp(1<<k,vector<ll>(k,inf));
    rep(i,k){
        dp[1<<i][i]=1;
    }
    for (ll bit=1;bit<(1<<k);++bit){
        rep(i,k){
            if (bit&(1<<i)){
                ll pbit=bit^(1<<i);
                rep(j,k){
                    dp[bit][i]=min(dp[bit][i],dp[pbit][j]+dist[i][j]);
                }
            }
        }
    }
    ll ans=inf;
    rep(i,k) ans=min(ans,dp[(1<<k)-1][i]);
    if (ans==inf) ans=-1;
    cout << ans << endl;
}

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <math.h>
#include <random>
#include <chrono>
#include <assert.h>
using namespace std ;
using ll = long long ;
using ld = long double ;
template<class T> using V = vector<T> ;
template<class T> using VV = V<V<T>> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
long double pie = acos(-1) ;
ll INF = 1e18 ;

void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
ll extGCD(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x = 1 ;
        y = 0 ;
        return a ;
    }
    ll d = extGCD(b,a%b,y,x) ;
    y -= a/b*x ;
    return d ;
}
void fix_cout(){cout << fixed << setprecision(20) ;}
template<class T> void chmax(T &a,T &b){if(a<b) a = b ;}
template<class T> void chmin(T &a,T &b){if(a>b) a = b ;}

int n,m,k ;

ll calc(VV<ll> &dp,VV<int> &dis,int cur,int p){
	if(~(cur>>p)&1) return INF ;
	if(dp[cur][p]!=-1){
		// cout << cur << " " << p << " " << dp[cur][p] << endl ;
		return dp[cur][p] ;
	}
	ll num = INF ;
	for(int i=0;i<k;i++){
		if((cur>>i)&1){
			num = min(num,calc(dp,dis,cur-(1<<p),i)+dis[i][p]) ;
		}
	}
	// cout << cur << " " << p << " " << num << endl ;
	dp[cur][p] = num ;
	return num ;
}

int main(){
	cin >> n >> m ;
	VV<int> g(n) ;
	for(int i=0;i<m;i++){
		int a,b ;
		cin >> a >> b ;
		a-- ; b-- ;
		g[a].push_back(b) ;
		g[b].push_back(a) ;
	}
	auto BFS = [&](V<int> &d,int s){
		queue<pair<int,int>> q ;
		q.emplace(0,s) ;
		while(!q.empty()){
			int p = q.front().second ;
			int cost = q.front().first ;
			q.pop() ;
			if(d[p]!=-1) continue ;
			d[p] = cost ;
			for(auto i:g[p]) q.emplace(cost+1,i) ;
		}
	} ;
	cin >> k ;
	V<int> c(k) ;
	for(auto &i:c) cin >> i ;
	for(auto &i:c) i-- ;
	V<int> d(n,-1) ;
	BFS(d,c[0]) ;
	for(auto i:c) if(d[i]==-1){
		cout << -1 << endl ;
		return 0 ;
	}
	// for(auto i:d) cout << i << " " ; cout << endl ;
	VV<int> dis(k,V<int>(k,-1)) ;
	for(int i=0;i<k;i++) dis[0][i] = d[c[i]] ;
	for(int i=1;i<k;i++){
		d = V<int>(n,-1) ;
		BFS(d,c[i]) ;
		for(int j=0;j<k;j++) dis[i][j] = d[c[j]] ;
	}
	VV<ll> dp(1<<k,V<ll>(k,-1)) ;
	for(int i=0;i<k;i++) dp[1<<i][i] = 1 ;
	ll ans = INF ;
	for(int i=0;i<k;i++) ans = min(ans,calc(dp,dis,(1<<k)-1,i)) ;
	cout << ans << endl ;
}


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

#define make_it_fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define ll long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second
#define imn (ll)-1e18
#define imx (ll)1e18

ld pi=3.14159265358979323846;

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

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}

template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}

void _print() {cerr << "]\n";}

template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...) 20
#endif

ll mod=1e9+7;
vector<ll> seg,fac;
ll power(ll a,ll b,ll m)
{
    a%=m;
    if(b==1)
    return a;
    if(b==0)
    return 1LL;
    ll ret=power(a,b/2,m);
    ret=(ret*ret)%m;
    if(b&1)
    ret=(ret*a)%m;
    return ret;
}

ll power(ll a,ll b)
{
    if(b==1)
    return a;
    if(b==0)
    return 1LL;
    ll ret=power(a,b/2);
    ret=(ret*ret);
    if(b&1)
    ret=(ret*a);
    return ret;
}

ll lcm(ll a,ll b)
{
    return (a*b)/(__gcd(a,b));
}

ll phi(ll n) // Euler-Totient Function
{
    ll result = n;
    for(ll i=2;i*i<=n;i++)
    {
        if (n%i==0)
        {
            while (n%i==0)
            n/=i;
            result/=i;
            result*=(i-1);
        }
    }
    if (n > 1)
    {
        result/=n;
        result*=(n-1);
    }
    return result;
}

ll findpar(ll x,vector<ll> par)
{
    while(x!=par[x])
    {
        x=par[x];
    }
    return x;
}

ll construct(ll a[],ll s,ll e,ll i)
{
    if(s==e)
    {
        seg[i]=a[s];
        return seg[i];
    }
    ll mid=s+(e-s)/2;
    seg[i]=construct(a,s,mid,2*i+1)^construct(a,mid+1,e,2*i+2);
    return seg[i];
}

void update(ll node,ll val,ll s,ll e,ll i)
{
    if(s==e)
    {
        seg[i]=val;
        return;
    }
    ll mid=s+(e-s)/2;
    if(node<=mid)
    {
        update(node,val,s,mid,2*i+1);
    }
    else
    {
        update(node,val,mid+1,e,2*i+2);
    }
    seg[i]=seg[2*i+1]^seg[2*i+2];
}

ll query(ll l,ll r,ll s,ll e,ll i)
{
    if(e<l || s>r)
    return 0;
    if(s>=l && e<=r)
    return seg[i];
    ll mid=s+(e-s)/2;
    return (query(l,r,s,mid,2*i+1)^query(l,r,mid+1,e,2*i+2));
}

void computeFac(ll mx)
{
    fac.resize(mx+10);
    fac[0]=1;
    for(ll i=1;i<mx+10;i++)
    {
        fac[i]=(fac[i-1]*i)%mod;
    }
}

ll ncr(ll a,ll b)
{
    if(a<b || b<0)
    return 0;
    ll x=(fac[a-b]*fac[b])%mod;
    return (fac[a]*power(x,mod-2,mod))%mod;
}

void answer_nikaal()
{
    ll n,i;
    cin>>n;
    ll b=0;
    ll ans=imx;
    for(i=0;i<=n;i++){
        if((1LL<<i)>n)
            break;
        ans=min(ans,i+n/(1LL<<i)+n%(1LL<<i));
    }
    cout<<ans<<endl;
}

int main()
{
    make_it_fast;
    int TEST_CASES=1;
    // cin>>TEST_CASES;
    while(TEST_CASES--)
    {
        answer_nikaal();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;

// TODO: solve without editorial

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n + 1);
    a[1] = 6;
    a[2] = 10;
    a[3] = 15;
    set<ll> s;
    for (int i = 2; i * a[1] <= 10000; ++i) {
        if (a[1] * i <= 10000) s.insert(a[1] * i);
        if (a[2] * i <= 10000) s.insert(a[2] * i);
        if (a[3] * i <= 10000) s.insert(a[3] * i);
    }
    for (int i = 4; i <= n; ++i) {
        a[i] = *s.begin();
        s.erase(s.begin());
    }
    cout << a[1];
    for (int i = 2; i <= n; ++i) {
        cout << ' ' << a[i];
    }
    cout << endl;
}


#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int n, m;
vector<pair<int, char>> edges[1000];
int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        edges[i].clear();
    for (int i = 0; i < m; ++i) {
        int from, to;
        char c;
        cin >> from >> to >> c;
        --from;
        --to;
        edges[from].push_back({ to, c });
        edges[to].push_back({ from, c });
    };
    queue<pair<int, int>> q, qq;
    q.push(make_pair(0, n - 1));
    int d = 0;
    int res = -1;
    bool visited[1000][1000] = { 0 };
    while (!q.empty()) {
        while (!q.empty()) {
            auto front = q.front();
            q.pop();
            int x = front.first;
            int y = front.second;
            for (auto edgeA : edges[x]) {
                for (auto edgeB : edges[y]) {
                    if (edgeA.second != edgeB.second)
                        continue;
                    if (visited[edgeA.first][edgeB.first])
                        continue;
                    visited[edgeA.first][edgeB.first] = true;
                    if (edgeA.first == edgeB.first) {
                        res = (res == -1 || res > 2 * (d + 1)) ? 2 * (d + 1) : res;
                    } else if (edgeA.first == y && edgeB.first == x) {
                        res = (res == -1 || res > 2 * d + 1) ? 2 * d + 1 : res;
                    } else {
                        qq.push(make_pair(edgeA.first, edgeB.first));
                    }
                }
            }
        }
        swap(q, qq);
        ++d;
    }
    cout << res << endl;
    return 0;
}

#include<bits/stdc++.h>

#define fox(i,a,b) for(int i=a;i<=b;++i)
#define ll long long

using namespace std;

int _x, _f; char _c;
inline int rd() {
	_x = 0, _f = 1, _c = getchar();
	for (; !isdigit(_c); _c = getchar()) if (_c == '-') _f = 0;
	for (; isdigit(_c); _c = getchar()) _x = _x * 10 + _c - '0';
	return _f ? _x : -_x;
}

const int N = 1010;
int n, m, g = INT_MAX;
struct edge { vector<int>tr[26];} e[N];
bool ud[N][N], lt[N][N];

struct nwp { int x, y, st;};
queue<nwp> q;

signed main() {
	n = rd(), m = rd();
	int x, y; char c;
	fox (i, 1, m) {
		x = rd(), y = rd();
		lt[x][y] = lt[y][x] = 1;
		scanf("%c", &c);
		e[x].tr[c-'a'].push_back(y);
		e[y].tr[c-'a'].push_back(x);
	}

	nwp a, b;
	a.x = 1, a.y = n, a.st = 0;
	if (lt[1][n]) {
		puts("1");
		return 0;
	}
	q.push(a);
	while (!q.empty()) {
		a = q.front(), q.pop();
		if (ud[x = a.x][y = a.y]) continue;
		ud[x][y] = 1;
		b.st = a.st + 1;
		if (b.st * 2 > g) {
			printf("%d\n", g);
			return 0;
		}
		fox (i, 0, 25) {
			for (int j = 0; j < e[x].tr[i].size(); ++j){
				for (int k = 0; k < e[y].tr[i].size(); ++k){
					b.x = e[x].tr[i][j], b.y = e[y].tr[i][k];
					if (b.x == b.y) {
						printf("%d\n", b.st * 2);
						return 0;
					}
					if (lt[b.x][b.y]) g = b.st * 2 + 1;
					if (ud[b.x][b.y]) continue;
					q.push(b);
				}
			}
		}
	} puts("-1");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i,n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a,const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a,const T &b) {if(b<a){a=b; return 1;} return 0;}
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

const int MX = 1500;
const pair<int, int> direction[4] = {
  { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 }
};

int h,w,n,m;

bool light[MX][MX];
bool wall[MX][MX];
bool ok[MX][MX];

bool visited[MX][MX];
bool memo[MX][MX];

bool f(int d, int i, int j) {
  if (i < 0 || j < 0 || h <= i || w <= j) return false;
  if (wall[i][j]) return false;
  if (light[i][j]) return true;
  if (visited[i][j]) return memo[i][j];

  visited[i][j] = true;
  int ni = i + direction[d].first;
  int nj = j + direction[d].second;

  return memo[i][j] = f(d, ni, nj);
}

int main() {
  IOS;
  cin >> h >> w >> n >> m;
  REP(i,n) {
    int a,b; cin >> a >> b;
    a--; b--; light[a][b] = 1;
  }
  REP(i,m) {
    int c,d; cin >> c >> d;
    c--; d--; wall[c][d] = 1;
  }

  REP(d,4) {
    REP(i,h) REP(j,w) visited[i][j] = 0;
    REP(i,h) REP(j,w) if(f(d,i,j)) ok[i][j] = 1;
  }

  int ans = 0;
  REP(i,h) REP(j,w) ans += ok[i][j];
  COUT(ans);
  return 0;
}

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

const int N = 2000 + 5, mod = 1e9 + 7;

int n, m, a[N][N], vis_r[N][N], vis_c[N][N];

void solve(int r, int c){
    int cc = c;
    while(cc <= m && vis_r[r][cc] == 0 && a[r][cc] != -1){
        vis_r[r][cc] = 1;
        cc++;
    }
    cc = c - 1;
    while(cc && vis_r[r][cc] == 0 && a[r][cc] != -1){
        vis_r[r][cc] = 1;
        cc--;
    }
    int rr = r;
    while(rr <= n && vis_c[rr][c] == 0 && a[rr][c] != -1){
        vis_c[rr][c] = 1;
        rr++;
    }
    rr = r - 1;
    while(rr && vis_c[rr][c] == 0 && a[rr][c] != -1){
        vis_c[rr][c] = 1;
        rr--;
    }

}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int q, q2;
    cin >> n >> m >> q >> q2;
    while(q--){
        int x, y;
        cin >> x >> y;
        a[x][y] = 1;
    }
    while(q2--){
        int x, y;
        cin >> x >> y;
        a[x][y] = -1;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(a[i][j] == 1) solve(i, j);
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(vis_r[i][j] || vis_c[i][j]) ans++;
        }
    }
    cout << ans;

    return 0;

}


#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/multiprecision/cpp_dec_float.hpp>
//using namespace boost::multiprecision;
using namespace std;

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(int i=(l);i<int(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(int i=(l);i>=int(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

const int MOD = 1000000007;
//const int MOD = 998244353;

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const int MAX_N = 200010;

string S1, S2, S3;
const char ng[] = "UNSOLVABLE";
V<> alph_id;
V<> id_alph;
int alph_size = 0;

int StrToNum(V<>& table, const string& s) {
    string ret = "";
    REP(i, s.length()) {
        char c = '0' + table[s[i] - 'a'];
        if(i == 0 && c == '0') { return -1; }
        ret += c;
    }
    return atoll(ret.c_str());
}

signed main() {
    IOS;

    cin >> S1 >> S2 >> S3;

    map<char, bool> pat;
    REP(i, S1.length()) {
        pat[S1[i]] = true;
    }
    REP(i, S2.length()) {
        pat[S2[i]] = true;
    }
    REP(i, S3.length()) {
        pat[S3[i]] = true;
    }

    if(pat.size() > 10) {
        print(ng);
        return 0;
    }

    alph_id.assign(30, -1);
    for(auto& p : pat) {
        alph_id[p.first - 'a'] = alph_size;
        id_alph.pb(p.first - 'a');
        alph_size++;
    }

    V<> num;
    REP(i, 10) {
        num.pb(i);
    }

    do {
        V<> p(30, -1);
        REP(i, alph_size) {
            int ind = id_alph[i];
            p[ind] = num[i];
        }
        int n1 = StrToNum(p, S1);
        if(n1 < 0) { continue; }
        int n2 = StrToNum(p, S2);
        if(n2 < 0) { continue; }
        int n3 = StrToNum(p, S3);
        if(n3 < 0) { continue; }
        if(n1 + n2 == n3) {
            print(n1);
            print(n2);
            print(n3);
            return 0;
        }
    } while(next_permutation(num.begin(), num.end()));
    print(ng);

    return 0;
}

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

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

   string s1, s2, s3;

   cin >> s1 >> s2 >> s3;

   if(s3.size() < s1.size() || s3.size() < s2.size()){
      cout << "UNSOLVABLE" << '\n';
      return 0;
   }
   vector<int> v(10);
   for(int i=0; i<10; i++) v[i] = i;

   int alpha[26];
   LL n1, n2, n3;
   bool ans = false, flag = false;
   do{
      if(v[0] == 0) continue;

      memset(alpha, -1, sizeof(alpha));
      int cur = 0;
      n1 = n2 = n3 = 0;

      for(int i=0; i<s1.size(); i++){
         n1 *= 10;
         int pos = s1[i] - 'a';

         if(alpha[pos] == -1){
            n1 += v[cur];
            alpha[pos] = cur++;
         }
         else
            n1 += v[alpha[pos]];
      }
      if(flag) continue;

      for(int i=0; i<s2.size(); i++){
         n2 *= 10;
         int pos = s2[i] - 'a';

         if(alpha[pos] == -1){
            if(cur == 10){
               flag = true;
               break;
            }
            n2 += v[cur];
            alpha[pos] = cur++;
         }
         else
            n2 += v[alpha[pos]];
      }
      if(flag) continue;

      for(int i=0; i<s3.size(); i++){
         n3 *= 10;
         int pos = s3[i] - 'a';

         if(alpha[pos] == -1){
            if(cur == 10){
               flag = true;
               break;
            }
            n3 += v[cur];
            alpha[pos] = cur++;
         }
         else
            n3 += v[alpha[pos]];
      }
      if(flag) continue;

      if(n1 == 0 || n2 == 0 || !v[alpha[s1[0]-'a']] || !v[alpha[s2[0]-'a']] || !v[alpha[s3[0]-'a']]) continue;
      if(n1 + n2 == n3){
         ans = true;

         for(int i=0; i<s1.size(); i++){
            int pos = s1[i] - 'a';
            cout << v[alpha[pos]];
         }
         cout << '\n';

         for(int i=0; i<s2.size(); i++){
            int pos = s2[i] - 'a';
            cout << v[alpha[pos]];
         }
         cout << '\n';

         for(int i=0; i<s3.size(); i++){
            int pos = s3[i] - 'a';
            cout << v[alpha[pos]];
         }
         cout << '\n';
         break;
      }

	}while(next_permutation(v.begin(),v.end()));

   if(!ans) cout << "UNSOLVABLE" << '\n';
   return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main (){
	int n,k;
	cin >> n >> k;
	vector<vector<int>>T(n,vector<int>(n));
	for(int i=0;i<n;i++)for(int j=0;j<n;j++){
		cin >> T[i][j];
	}

	vector<int>index;
	for(int i=0;i<n;i++)index.push_back(i);

	int ans=0;
	do{
		int time=0;
		for(int i=0;i<n;i++)time+=T[index[i]][index[(i+1)%n]];
		if(time==k)ans++;
	}while(next_permutation(index.begin()+1, index.end()));
	cout << ans;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,a,n) for(ll i=a;i<n;i++)
#define w(x) ll _t;cin>>_t;f(x,1,_t+1)
#define br cout<<"\n"
#define N 10000000
ll md=1e9+7,n;
ll h,w,m,k;
//l,d,r,u
ll x[]={0,1,0,-1};
ll y[]={1,0,-1,0};
ll mat[15][15];
bool isSafe(ll i,ll j){
    return i>=0 && i<h && j>=0 && j<w;
}
ll sol(ll x,ll sm,ll u){
    if(x==(1<<n)-1){
        if(sm+mat[0][u]==k) return 1;
        return 0;
    }
    ll ans=0;
    f(i,0,n){
        if(((1<<i) & x) == 0){
            ans += sol(x | (1<<i) ,sm+mat[u][i] ,i);
        }
    }
    return ans;
}

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

    //w(_x)
    {
        cin>>n>>k;
        f(i,0,n) f(j,0,n) cin>>mat[i][j];
        cout<<sol(1,0,0);
    }
    return 0;
}


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

const int INF=1e8;
void chmin(int& x, int y){ x=min(x,y);}

int main(){
  int n;
  cin >> n;
  vi x(n),y(n),z(n);
  rep(i,n) cin >> x[i] >> y[i] >> z[i];
  int n2=1<<n;
  vvi dist(n,vi(n));
  rep(i,n) rep(j,n) dist[i][j]=abs(x[j]-x[i])+abs(y[j]-y[i])+max(0,z[j]-z[i]);
  vvi dp(n2,vi(n,INF));
  rep(i,n){
    if(i==0) continue;
    dp[1<<i][i]=dist[0][i];
  }
  rep(i,n2){
    rep(j,n){
      if(!(i>>j&1)) continue;
      rep(k,n){
        if(i>>k&1) continue;
        chmin(dp[i|1<<k][k],dp[i][j]+dist[j][k]);
      }
    }
  }
  cout << dp[n2-1][0];
  return 0;
}

#include<bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ar array

int n;
ar<int,3> arr[20];
ll dp[18][ (1<<20) ];

ll dis(int a, int b){
    return llabs(arr[b][0] - arr[a][0]) + llabs(arr[b][1] - arr[a][1]) + max(0, arr[b][2] - arr[a][2]);
}

ll inf = (1LL<<40);

ll f(int node, int mask){
    if(mask == (1<<n)-1){
        return dis(node,0);
    }
    ll &ret = dp[node][mask];
    if(ret != -1) return ret;
    ret = inf;
    for(int i = 1; i < n; i++){
        if((mask & (1<<i)) == 0){
            ret = min(ret, f(i, mask | (1<<i)) + dis(node,i));
        }
    }
    return ret;
}

void solve(){
    cin>>n;
    for(int i = 0; i < n; i++){
        cin>>arr[i][0];
        cin>>arr[i][1];
        cin>>arr[i][2];
    }
    mem(dp,-1);
    cout << f(0, 1) << endl;

}

int main()
{
    speed;
    solve();
    return 0;
}


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

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define deb(x) cout << #x << " is " << x << "\n"
#define int long long
#define MOD 1000000007LL
#define PI acos(-1)

template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <typename T>
using max_heap = priority_queue<T>;

template <class T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename... T>
void read(T &...args) {
	((cin >> args), ...);
}

template <typename... T>
void write(T &&...args) {
	((cout << args), ...);
}

template <typename T>
void readContainer(T &t) {
	for (auto &e : t) {
		read(e);
	}
}

template <typename T>
void writeContainer(T &t) {
	for (const auto &e : t) {
		write(e, " ");
	}
	write("\n");
}

auto speedup = []() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	return nullptr;
}();

void solve(int tc) {
	int n, s, d, x, y;
	read(n, s, d);
	bool ok = false;
	while (n--) {
		read(x, y);
		if (x < s && y > d) {
			ok = true;
			break;
		}
	}
	write((ok ? "Yes" : "No"));
}

signed main() {
	int tc = 1;
	// read(tc);
	for (int curr = 1; curr <= tc; curr++) {
		solve(curr);
	}
	return 0;
}

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

int main() {
    int N;
    float D,H;
    cin >> N >> D >> H;
    float d[N],h[N];
    for (int i=0;i<N;i++){
        cin >> d[i] >> h[i];
    }
    float ka,high,max=0;
    for (int i=0;i<N;i++){
        ka=abs(H-h[i])/abs(D-d[i]);
        high=H-ka*D;
        if (high>max){
            max=high;
        }
    }
    if (max<0){
        max=0;
    }
    cout << max << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <tuple>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;}
const double eps = 1e-10;

int main() {
    ll n;
    scanf("%lld", &n);

    ll sum = 1;
    for(int i = 2; i<=n; i++) {
        int value = i;
        for(int j=i-1; j>1; j--) {
            if(value % j == 0) {
                value = value / j;
            }
        }
        if(i == 8) value = value * 2;
        if(i == 16) value = value * 2;
        if(i == 27) value = value * 3;
        sum *= value;
    }

    for(int i=2; i<=n; i++) {
        ll x = (sum+1) % i;
        if(x != 1) printf("no!!! n: %lld, %d, %lld\n", n, i, x);
    }
    cout << sum + 1 << '\n';
    return 0;

}

#include <bits/stdc++.h>

using namespace std;

const int maxn = 105;
const int mod = 998244353;

int n;
int a[maxn];
int inv[maxn];
int f[maxn][maxn][maxn * maxn];

int binpow(int x, int y) {
    int ans = 1;
    while(y) {
        if (y & 1) ans = 1ll * ans * x % mod;
        y >>= 1;
        x = 1ll * x * x % mod;
    }
    return ans;
}

void add(int &x, int y) {
    x += y;
    if (x >= mod) x -= mod;
}

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

    int sum = 0, prod = 1;

    for(int i = 1; i < maxn; ++i) {
        inv[i] = binpow(i, mod - 2);
    }

    cin >> n;
    for(int i = 0; i < n; ++i) cin >> a[i], sum += a[i], prod = 1ll * prod * (i + 1) % mod;

    if (sum % 2 == 1) {
        cout << 0 << endl;
        return 0;
    }

    f[0][0][0] = prod;

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= i; ++j) {
            for(int s = 0; s < maxn * maxn; ++s) {
                if (f[i][j][s] == 0) continue;
                add(f[i + 1][j][s], f[i][j][s]);
                add(f[i + 1][j + 1][s + a[i]], 1ll * f[i][j][s] * (j + 1) % mod * inv[n - j] % mod);
            }
        }
    }

    int ans = 0;
    for(int i = 1; i <= n; ++i) {
        ans += f[n][i][sum / 2];
        ans = (ans % mod);
    }

    cout << ans << endl;

    return 0;
}


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

    struct custom_hash {
        static uint64_t splitmix64(uint64_t x) {
            // http://x...content-available-to-author-only...i.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);
        }
    };

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

    #define IOS         ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define pb          push_back
    #define eb          emplace_back
    #define vi          vector<int>
    #define vvi         vector<vector<int>>
    #define vii         vector<pii>
    #define pii         pair<int,int>
    #define all(a)      (a).begin(),(a).end()
    #define ff          first
    #define ss          second
    #define sp(n)       setprecision(n)<<fixed
    #define endl        '\n'
    #define umap        unordered_map<long long, vii, custom_hash>

    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
      template <typename Arg1>
      void __f(const char* name, Arg1&& arg1){
          std::cerr << name << " : " << arg1 << endl;
      }
      template <typename Arg1, typename... Args>
      void __f(const char* names, Arg1&& arg1, Args&&... args){
          const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
      }

    // -------------------Standard Traversal Moves---------------------
    // vi fx = {1 ,-1 ,0, 0}, fy = {0, 0, -1, 1};
    // vi fx = {2, -2, 2, -2,  1, -1, 1, -1}, fy = {1, 1, -1, -1, 2, 2, -2, -2};
    // vi fx = {1, 1, 1, -1, -1 , -1, 0, 0}, fy = {1, -1, 0, 1, -1, 0, 1, -1};
    // ----------------------------------------------------------------

    // #define int         long long
    const int N = 2e5 + 5, K = 20, MOD = 1000000007, mod = 998244353;
    // const long long INF = LLONG_MAX/2;
    const int INF = INT_MAX/2;
    const double pi = 3.141592653589793;

    int n,m,x,y;
    int a[105][105];

    void solve(){
        cin>>n>>m;
        int sum = 0, mn = INF;;
        for(int i=1; i<=n; i++){
            for(int j=1; j<=m; j++){
                cin>>a[i][j];
                mn = min(mn, a[i][j]);
                sum += a[i][j];
            }
        }
        int ans = sum - (mn*n*m);
        cout<<ans<<endl;
    }

    int32_t main()
    {
        IOS;
        int TESTS=1;
        // cin>>TESTS;
        while(TESTS--)
        {
            solve();
        }
        return 0;
    }

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

int main() {
  int h,w;
  cin >> h >> w;
  int n = h*w;
  vector<int> a(n);
  for(int i = 0;i < n;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  int ans = 0;
  for(int i = 0;i < n;i++){
    ans += a.at(i)-a.at(0);
  }
  cout << ans << endl;
}