#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e+9+7;

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

	int left = 0, right = 1e9+1;
	while(right - left > 1){
		int mid = (left + right) / 2;
		bool flg = false;

		set<int> st;
		for(int i = 0; i < n; i++){
			int bit = 0;
			for(int j = 0; j < 5; j++){
				if(arr[i][j] >= mid) bit += (1<<j);
			}
			st.insert(bit);
		}

		for(int i : st){
			for(int j : st){
				for(int k : st){
					if((i | j | k) == (1<<5)-1){
						flg = true;
						break;
					}
				}
			}
		}

		if(flg) left = mid;
		else right = mid;
	}

	cout << left << endl;

	return 0;
}

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

#include <iostream>
#include <vector>
#include <set>

using namespace std;

void solve() {
    int N;
    cin >> N;
    int m = 5;
    vector<vector<int>> A(N, vector<int>(m, 0));
    for (auto& l : A)for (auto& op : l) cin >> op;

    auto check = [&](int x)-> bool {
        set<int> z;
        for (auto& l : A) {
            int bit = 0;
            for (auto& op : l) {
                bit <<= 1;
                if (x <= op) {
                    bit += 1;
                }
            }
            z.insert(bit);
        }
        int allok = (1 << m) - 1;
        for(auto& s1 : z)for(auto& s2 :z)for(auto& s3 :z){
            int sp = s1 | s2 | s3;
            if (sp == allok) {
                return true;
            }

        }
        return false;
    };
    int l,  r;
    l = 0;
    r = 1e9 + 1;
    bool jg;
    while ((r -l) > 1 ) {
        int m = (r + l) / 2;
        jg = check(m);
        if (jg) {
            l = m;
        }
        else r = m;
    }

    cout << l << endl;

}

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

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント:
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
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;}
constexpr int INF=1000000000;
constexpr ll llINF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-10;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    set<ll>st;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            st.insert(i);
            st.insert(n/i);
        }
    }
    for(ll i:st)cout<<i<<endl;
    return 0;
}

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

vector<int64_t> enum_divisors(int64_t N) {
    vector<int64_t> res;
    for (int64_t i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}

int main() {
  int64_t N;
  cin >> N;
  const auto &res = enum_divisors(N);
  for (int i = 0; i < res.size(); ++i) cout << res[i] << endl;
}


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

int main(){
    int a,b,x,y;
    int ans;
    cin >> a >> b >> x >> y;
    int less = x;
    if(x > y) less = y;
    int trueless = y;
    if(2*x < y) trueless = 2*x;
    int lastless = x+y;
    if(3*x < x+y) lastless = 3*x;
    if(a < b){
        int du = b-a;
        if(2*x < y){
            ans = (du-1)*trueless + lastless;
        }else{
            ans = x + du*y;
        }
    }else if(a > b){
        int du = a-b;
        if(2*x < y){
            if(x < y){
                ans = (du-1)*trueless+x;
            }else{
                ans = (du-1)*trueless-x+y;
            }
        }else{
            ans = x + (du-1)*y;
        }
    }else if(a == b){
        ans = x;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int total=a+b+c+d;
  if(total%2==1){
    cout<<"No";
  }
  else{
    total=total/2;
    if(a+b==total || a+c==total || a+d==total ||a+b+c==total ||a+b+d==total ||a+c+d==total){
      cout<<"Yes";
    }
    else{
      cout<<"No";
    }
  }
}


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

#define fill(a, b) memset(a, b, sizeof(a))

typedef long long ll;
typedef long double lld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<ii> vii;
typedef vector<pll> vll;
typedef set<int> si;
typedef map<string, int> msi;

const int N = 1000010;
const ll MOD = 1e9 + 7;

void solve() {
  ll n;
  cin >> n;
  set<ll> ans;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ans.insert(i);
      ans.insert(n / i);
    }
  }
  for (auto x : ans) cout << x << endl;
  return;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // int t;
  // cin >> t;
  // for (int i = 0; i < t; i++) {
  //   solve();
  // }
  solve();
}


#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0, length = n; i < length; i++)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ep emplace
#define epb emplace_back
#define scll static_cast<long long>
#define sz(x) static_cast<int>((x).size())
#define pfll(x) printf("%lld\n", x)
#define ci(x) cin >> x
#define ci2(x, y) cin >> x >> y
#define ci3(x, y, z) cin >> x >> y >> z
#define ci4(w, x, y, z) cin >> w >> x >> y >> z
#define co(x) cout << x << endl
#define co2(x, y) cout << x << " " << y << endl
#define co3(x, y, z) cout << x << " " << y << " " << z << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> PQ;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
typedef priority_queue<P> PQP;
typedef priority_queue<P, vector<P>, greater<P>> PQPG;

const int MAX_N = 3e5, MOD = 1e9 + 7, INF = 1e9;
int n, a[MAX_N];
map<ll, int> m;

int main() {
    ci(n);
    rep(i, n) ci(a[i]);
    ll sum = 0;
    m[0]++;
    rep(i, n) {
        sum += i % 2 ? a[i] : -a[i];
        m[sum]++;
    }
    ll ans = 0;
    for (auto &i: m) ans += scll(i.se - 1) * i.se / 2;
    co(ans);
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1e9+7LL;

int main() {
    ll N; cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    map<ll,ll> m;
    rep(i, N-1){
        A[i+1] -= A[i];
        if(i%2==1) A[i] *= -1;
        m[A[i]]++;
    }
    if((N-1)%2==1) A[N-1] *= -1;
    m[A[N-1]]++;
    m[0]++;

    ll ans = 0;
    for (auto p : m) {
        auto key = p.first;
        auto value = p.second;
        ans += value*(value-1)/2;
    }
    cout << ans << endl;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main() {
	vector<long long> a;
	queue<long long> q;
	long long n, m = 1;
	cin >> n;
	for (int i = 1; i <= n; ++i)
		m *= 2;
	n = m;
	for (int i = 0; i < n; ++i) {
		cin >> m;
		a.push_back(m);
		q.push(m);
	}long long b, c;
	while (q.size() != 2) {
		long long x = q.size();
		for (int i = 1; i <= x; i += 2) {
			b = q.front(); q.pop();
			c = q.front(); q.pop();
			q.push(max(c, b));
		}
	}
	b = q.front(); q.pop();
	c = q.front(); q.pop();
	b = min(b, c);
	for (int i = 0; i < n; ++i) {
		if (b == a[i]) {
			cout << i + 1;
			return 0;
		}
	}
	return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define vec vector
using namespace std;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	#ifdef LOCAL
//		freopen("in1.txt", "r", stdin);
//		freopen("in1.txt", "w", stdout);
	#endif
	int n;
	cin >> n;
	int m = 1<<n;
	vec<int> a(m);
	for (int& x : a) cin >> x;

	vec<vec<int>> b(2);
	for (int i=0; i<m; i++) b[0].push_back(i);
	for (int t=0; t<n-1; t++) {
		bool p = t&1;
		bool q = 1-p;
		sort(b[p].begin(), b[p].end());
		for (int i=0; i<b[p].size(); i+=2) {
			if (a[b[p][i]] < a[b[p][i+1]]) b[q].push_back(b[p][i+1]);
			else b[q].push_back(b[p][i]);
		}
		b[p].clear();
	}

	bool p = (n-1)&1;
	if (a[b[p][0]] < a[b[p][1]]) cout << b[p][0]+1;
	else cout << b[p][1]+1;
	cout << '\n';
}


/*input
2
4 1
2 4
*/

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

int main() {
  int n;
  cin >> n;
  vector<int> in(n*2), out(n*2), c(n*2);
  bool ok = true;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    if (a == 2*n || b == 1) {
      ok = false;
      continue;
    }
    --a; --b;
    if (a >= 0) {
      if (in[a]) ok = false;
      if (b < 0) in[a] = 1;
      else in[a] = -1;
    }
    if (b >= 0) {
      if (out[b]) ok = false;
      if (a < 0) out[b] = 1;
      else out[b] = -1;
    }
    if (a >= 0 && b >= 0) {
      int nc = b-a;
      for (int i = a; i <= b; ++i) {
        if (c[i] != 0 && c[i] != nc) ok = false;
        c[i] = nc;
      }
    }
  }
  auto f = [&] {
    rep(i, n*2-1) {
      if (in[i] == 1) {
        int j = i+1;
        for (; j < n*2; ++j) {
          if (c[j] > 0) {
            j = i+c[j];
            if (out[j] == 1) ok = false;
            break;
          }
          else if (out[j] == 0 && in[j] == 0) {
            out[j] = 1;
            break;
          }
        }
        if (j == n*2) {
          ok = false;
          continue;
        }
        for (int k = i; k <= j; ++k) {
          if (c[k] != 0 && c[k] != j-i) ok = false;
          c[k] = j-i;
        }
      }
    }
  };
  reverse(in.begin(), in.end());
  reverse(out.begin(), out.end());
  reverse(c.begin(), c.end());
  swap(in, out);
  f();
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

const int maxN=100;

int n;

int arr[2*maxN+1];
int type[2*maxN+1]={0};

int main() {
	// your code goes here

	int n;
	cin>>n;

    memset(arr,-1,sizeof(arr));

    int a,b;

    int rem=0;

    for(int i=0;i<n;i++)
    {
        cin>>a>>b;

        if(a==-1 && b==-1)
        {
            rem++;
        }
        else if(a==-1 && type[b]==0)
        {
            type[b]=1;
        }
        else if(b==-1 && type[a]==0)
        {
            type[a]=2;
        }
        else if(b>a && type[a]==0 && type[b]==0)
        {
            type[a]=3;
            type[b]=3;

            arr[a]=b;
            arr[b]=a;
        }
        else
        {
            cout<<"No"<<endl;
            return 0;
        }
    }

    bool dp[2*n+2];
    dp[2*n+1]=true;

    int temp[2*n+1];

    for(int i=2*n;i>=1;i--)
    {
        dp[i]=false;

        for(int j=i;j<=2*n;j++)
        {
            if(j%2!=i%2 && dp[j+1])
            {
                int mid=(i+j)/2;

                int len=(j-i+1)/2;

                for(int k=i;k<=mid;k++)
                {
                    temp[k]=k+len;
                    temp[k+len]=k;
                }

                bool ff=1;

                for(int k=i;k<=j;k++)
                {
                    if(type[k]==0)
                    {
                        continue;
                    }
                    else if(type[k]==1)
                    {
                        if(type[temp[k]]!=0 || k<=mid)
                        {
                            ff=0;
                        }
                    }
                    else if(type[k]==2)
                    {
                        if(type[temp[k]]!=0 || k>mid)
                        {
                            ff=0;
                        }
                    }
                    else
                    {
                         if(arr[k]!=temp[k])
                         {
                             ff=0;
                         }
                    }
                }

                dp[i] |=ff;
            }
        }
    }

    cout<<(dp[1] ? "Yes" : "No")<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
void update(lli index,lli value,lli BIT[],lli n)
{
    for(;index<=n;index+=(index&(-index)))
    {
        BIT[index]^=value;
    }
}
lli query(lli index,lli BIT[])
{
    lli sum=0;
    for(;index>0;index-=(index&(-index)))
    {
        sum^=BIT[index];
    }
    return sum;
}
int main(){
	ios_base::sync_with_stdio(false);  cin.tie(NULL); //cout.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("error.txt", "w", stderr);
	freopen("output.txt", "w", stdout);
	#endif
	long long i,j,t=1;	//cin>>t;
	while(t--){
		lli n,q;
	    cin>>n>>q;
	    lli a[n+1];
	    lli BIT[n+1]={0};
	    for(lli i=1;i<=n;i++)
	    {
	        cin>>a[i];
	        update(i,a[i],BIT,n);
	    }
	    //for(int i=1;i<=n;i++)
	    //cout<<query(i,BIT)<<endl;
	    while(q--)
	    {
	        lli t,x,y;
	        cin>>t>>x>>y;
	        if(t==1)
	        {
	            update(x,y,BIT,n);
	        }
	        if(t==2)
	        {
	            lli z=query(y,BIT)^query(x-1,BIT);
	            cout<<z<<endl;
	        }
    	}
	}
	return 0;
}

#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#ifdef DEBUG
#define line() cout << "[" << __LINE__ << "] ";
#define dump(i) cout << #i ": " << i << " ";
#define dumpl(i) cout << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

template <typename Monoid>

struct SegmentTree
{
    using F = function<Monoid(Monoid, Monoid)>;
    int sz;
    vector<Monoid> seg;

    const F f;
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1)
    {
        sz = 1;
        while (sz < n)
            sz *= 2;
        seg.assign(2 * sz, M1);
    }
    void set(int k, const Monoid &x)
    {
        seg[k + sz] = x;
    }
    void build()
    {
        for (int k = sz - 1; k > 0; k++)
        {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }
    void update(int k, const Monoid &x)
    {
        k += sz;
        seg[k] = x;
        while (k >>= 1)
        {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }
    Monoid query(int a, int b)
    {
        Monoid L = M1, R = M1;
        for (a += sz, b += sz; a < b; a >>= 1, b >>= 1)
        {
            if (a & 1)
                L = f(L, seg[a++]);
            if (b & 1)
                R = f(seg[--b], R);
        }
        return f(L, R);
    }
    Monoid operator[](const int &k) const
    {
        return seg[k + sz];
    }
};

int f(int a, int b)
{
    return a ^ b;
}

int main()
{
    int N, Q;
    cin >> N >> Q;
    SegmentTree<int> seg(N, f, 0);
    rep(i, N)
    {
        int tmp;
        cin >> tmp;
        seg.update(i, tmp);
    }
    rep(i, Q)
    {
        int t, x, y;
        cin >> t >> x >> y;
        if (t == 1)
        {
            x--;
            seg.update(x, seg.query(x, x + 1) ^ y);
        }
        else
        {
            x--;
            y--;
            cout << seg.query(x, y + 1) << endl;
        }
    }
    return 0;
}


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

LL M;
map<LL, LL> memo;
LL solve(LL N) {
    if (N == M) return 0;
    if (N-M<M-(N/2)+1) return abs(N-M);
    if (memo.count(N)) return memo[N];
	if (N < M) return M - N;
    LL l2 = (N/2)*2;
    LL r2 = ((N+1)/2)*2;

    LL res = 1e18;
    if (N < res) res = N;
    res = min(res, llabs(l2-N) + 1 + solve(l2/2));
    res = min(res, llabs(r2-N) + 1 + solve(r2/2));

	memo[N] = res;

    return res;
}

int main() {
	LL N;
	cin >> M >> N;
	cout << solve(N) << "\n";
}

#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<list>
#include<string.h>
#include<math.h>
#include<set>
#include<string>
#include<queue>
#include<map>
#include<unordered_map>
#include<stack>
//#include<unordered_set>
//#pragma GCC optimize (3)

//#define segmenttree true

#ifdef segmenttree
#define lc (rt<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#endif

#define reg register

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<double, double> pdd;
typedef pair<char, char> pcc;
typedef pair<ll, bool> plb;

const int MAX = 2005;
const ll INF = 1e10;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535;
const double EPS = 1e-5;

ll n, m, a, Sum;

inline ll pow_mod(ll a, ll b, ll mod){
    ll ans = 1;
    a %= mod;
    while(b)
    {
        if(b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}

inline ll inv(ll num, ll mod){
    return pow_mod(num, mod - 2, mod) % mod;
}

ll C(ll x, ll y){
	ll temp = 1;
	for(int i = 1; i <= y; ++i){
		temp = temp * (x - i + 1) % MOD;
		temp = temp * inv(i, MOD) % MOD;
	}
	return temp;
}

int main(){
//	ios::sync_with_stdio(false);
	scanf("%lld %lld", &n, &m);
	for(int i = 1; i <= n; ++i){
		scanf("%lld", &a);
		Sum += a;
	}
	printf("%lld", C(m + n, n + Sum));
	return 0;
}


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

typedef long double ld;

int n;
ld res;

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n - 1; i++)
		res += ld(n) / (n - i);
	cout << fixed << setprecision(10) << res << endl;
    return 0;
}

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

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

	cin >> N;
	cout << N - 1 << endl;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;

/* [💭] [💡] [🎈] */

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

#ifdef _SHIFTPSH
    freopen("_run/in.txt", "r", stdin), freopen("_run/out.txt", "w", stdout);
#endif

    int n, m;
    cin >> n >> m;

    map<int, vector<int>> v;

    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        v[x].emplace_back(y);
    }

    vector<vector<int>> r;
    for (const auto &kv : v) r.emplace_back(kv.second);

    set<int> pos;
    pos.emplace(n);

    for (auto &x : r) {
        queue<int> erq, emq;
        for (auto &y : x) {
            if (pos.count(y)) {
                erq.emplace(y);
            }
            if (pos.count(y - 1) || pos.count(y + 1)) {
                emq.emplace(y);
            }
        }
        while (erq.size()) pos.erase(erq.front()), erq.pop();
        while (emq.size()) pos.emplace(emq.front()), emq.pop();
    }

    cout << pos.size() << endl;

    return 0;
}

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

std::vector<std::vector<int> > hen;
std::vector<int> dist;
std::vector<int> stack;
std::vector<int> stack_res;
void dfs0(int i, int prev, int goal = -1) {
	stack.push_back(i);
	if (i == goal) stack_res = stack;
	for (auto j : hen[i]) if (j != prev) {
		dist[j] = dist[i] + 1;
		dfs0(j, i, goal);
	}
	stack.pop_back();
}

int cnt = 0;
std::vector<int> res;
std::vector<int> avoid;

void dfs1(int i, int prev) {
	res[i] = cnt;
	for (auto j : hen[i]) if (j != prev) {
		if (avoid[i] == j) continue;
		cnt++;
		dfs1(j, i);
		cnt++;
	}
	for (auto j : hen[i]) if (j != prev) {
		if (avoid[i] != j) continue;
		cnt++;
		dfs1(j, i);
		cnt++;
	}
}

int main() {
	int n = ri();
	hen.resize(n);
	for (int i = 1; i < n; i++) {
		int a = ri() - 1;
		int b = ri() - 1;
		hen[a].push_back(b);
		hen[b].push_back(a);
	}
	dist.assign(n, 0);
	dfs0(0, -1);
	int t0 = std::max_element(dist.begin(), dist.end()) - dist.begin();
	dist.assign(n, 0);
	dfs0(t0, -1);
	int t1 = std::max_element(dist.begin(), dist.end()) - dist.begin();

	dist.assign(n, 0);

	dfs0(t0, -1, t1);

	auto tmp = stack_res;
	avoid.resize(n, -1);
	for (int i = 0; i + 1 < (int) tmp.size(); i++) avoid[tmp[i]] = tmp[i + 1];

	/*
	for (auto i : tmp) std::cerr << i << std::endl;
	*/
	res.resize(n);
	dfs1(tmp[0], -1);

	for (int i = 0; i < n; i++) {
		if (i) printf(" ");
		printf("%d", res[i] + 1);
	}
	puts("");

	return 0;
}


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

#define pb push_back
#define FOR(i,f,n) for(int i=f;i<n;i++)
#define FORI(i,f,n) for(int i=f;i>=n;i--)
#define sz(a) ((int)(a).size())
#define ff first
#define ss second
#define all(a) (a).begin(),(a).end()
#define alli(a) (a).rbegin(),(a).rend()
#define approx(a) fixed<<setprecision(a)
#define trav(a,x) for(auto& a : x)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,bool> pib;
typedef pair<ll,bool> plb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template <class T> void ckmin(T &a, const T &b) { a = min(a, b); }
template <class T> void ckmax(T &a, const T &b) { a = max(a, b); }

template <class T> void read(vector<T> &v);
template <class F, class S> void read(pair<F, S> &p);
template <class T> void read(T &x) {cin>>x;}
template <class R, class... T> void read(R& r, T&... t){read(r); read(t...);};
template <class T> void read(vector<T> &v) {trav(x, v) read(x);}
template <class F, class S> void read(pair<F, S> &p) {read(p.ff, p.ss);}

template <class F, class S> void pr(const pair<F, S> &x);
template <class T> void pr(const T &x) {cout<<x;}
template <class R, class... T> void pr(const R& r, const T&... t) {pr(r); pr(t...);}
template <class F, class S> void pr(const pair<F, S> &x) {pr("{", x.ff, ", ", x.ss, "}");}
void ps() {pr("\n");}
template <class T> void ps(const T &x) {pr(x); ps();}
template <class T> void ps(vector<T> &v) {trav(x, v) pr(x, ' '); ps();}
template <class F, class S> void ps(const pair<F, S> &x) {pr(x.ff, ' ', x.ss); ps();}
template <class R, class... T> void ps(const R& r, const T &...t) {pr(r, ' '); ps(t...);}

void solve(){
    string s; read(s);
    int cnt = 0;
    FOR(i,0,sz(s)){
        if(s[i] == 'o') cnt++;
    }
    set<string> ans;
    FOR(i,0,10){
        FOR(j,0,10){
            FOR(k,0,10){
                FOR(l,0,10){
                    vb v(10);
                    string t = "....";
                    t[0] = ('0'+i);
                    t[1] = ('0'+j);
                    t[2] = ('0'+k);
                    t[3] = ('0'+l);
                    bool id=0;
                    int check=0;
                    FOR(m, 0, 4){
                        if(s[t[m]-'0'] == 'o' && !v[t[m]-'0']){
                            v[t[m]-'0'] = 1;
                            check++;
                        }else if(s[t[m]-'0'] == 'x') id=1;
                    }
                    if(id) continue;
                    if(check == cnt) ans.insert(t);
                }
            }
        }
    }
    ps(sz(ans));
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}

#include <iostream>
#include <cassert>
#include <numeric>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <stdio.h>
#include <string>
using namespace std;
using Graph = vector<vector<int>>;
using ll=long long;
using pa=pair<ll,ll>;
using tup=tuple<ll,ll,ll>;

int main() {
ll n;
cin>>n;
vector<ll> a(n);
vector<ll> b(n);
vector<ll> c(n);
vector<ll> anum(n+1);
vector<ll> bnum(n);
for (int i = 0; i < n; i++)
{
  cin>>a[i];
  anum[a[i]]++;
}
for (int i = 0; i < n; i++)
{
  cin>>b[i];
}
for (int i = 0; i < n; i++)
{
  cin>>c[i];

  bnum[c[i]-1]++;
}
ll ans=0;
for (int i = 0; i < n; i++)
{
  ans+=bnum[i]*anum[b[i]];

}
cout<<ans<<endl;
}


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

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

const int SZ = 2010;
class UF {
public:
	int P[SZ + 1];
	UF() : P() {
		rep1(i, SZ) P[i] = -1;
	}
	int find(int A) {
		if (P[A] < 0) return A;
		return P[A] = find(P[A]);
	}
	bool unite(int A, int B) {
		int a = find(A);
		int b = find(B);
		if (a == b) return false;
		if (P[a] > P[b]) swap(a, b);
		P[a] += P[b];
		P[b] = a;
		return true;
	}

} uf;

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

	int H, W;
	cin >> H >> W;

	uf.unite(1, 1001);
	uf.unite(1, W + 1000);
	uf.unite(H, 1001);
	uf.unite(H, W + 1000);

	rep1(i, H) {
		string S;
		cin >> S;
		rep(j, W) {
			if (S[j] == '#') {
				uf.unite(i, j + 1001);
			}
		}
	}

	int kotae = 1000;

	unordered_set<int> ST;
	rep1(i, H) {
		ST.insert(uf.find(i));
	}
	kotae = ST.size() - 1;
	ST.clear();
	rep1(j, W) {
		ST.insert(uf.find(j + 1000));
	}
	chmin(kotae, int(ST.size()) - 1);

	co(kotae);

	Would you please return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for(ll i = (ll)(m); i < (ll)(n); i++)
#define rep_inv(i, n, m) for(ll i = (ll)(n); i > (ll)(m); i--)

int main(){
  ll H, W, X, Y;
  cin >> H >> W >> X >> Y;

  vvc F(H, vc(W));
  string S;

  rep(i, H){
    cin >> S;

    rep(j, W) F[i][j] = S[j];
  }

  ll ans = 1;

  X--;
  Y--;

  rep2(i, 1, H){
    if(X - i < 0)
      break;
    if(F[X - i][Y] == '#')
      break;

    ans++;
  }

  rep2(i, 1, H){
    if(X + i >= H)
      break;
    if(F[X + i][Y] == '#')
      break;

    ans++;
  }

  rep2(i, 1, W){
    if(Y - i < 0)
      break;
    if(F[X][Y - i] == '#')
      break;

    ans++;
  }

  rep2(i, 1, W){
    if(Y + i >= W)
      break;
    if(F[X][Y + i] == '#')
      break;

    ans++;
  }

  cout << ans << "\n";

  return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e18;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}
ll ceilll(ll a, ll b) {return (a + b-1) / b;} // if(a%b != 0) (a/b) + 1
ll get_digit(ll a) {ll digit = 0; while(a != 0){a /= 10; digit++;} return digit;} // a != 0
template<typename T> void vecdbg(vector<T>& v){ rep(i, v.size()){cout << v[i] << " ";} br;}
template<typename T> void vecvecdbg(vector<vector<T>>& v){ rep(i, v.size()){rep(j, v[i].size()){cout << v[i][j] << " ";} br;}}
ll POW(ll a, ll n){ ll res = 1; while(n > 0){ if(n & 1){ res = res * a; } a *= a; n >>= 1; } return res; }
using P = pair<ll, ll>;

// 0 false, 1 true
// string number to int : -48 or - '0'
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp
// global vector -> 0 initialization
// DONT FORGET TO INTIALIZE
// The type of GRID is CHAR. DONT USE STRING
// If the result in local and judge is different, USE CODETEST!!
// (a * b)over flow?   if(a > INF / b){ /* overflow */}

const long double PI = (acos(-1));

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ld n; cin >> n;
    ld x, y; cin >> x >> y;
    ld x2, y2; cin >> x2 >> y2;

    //中心
    ld xm = (x + x2) / 2;
    ld ym = (y + y2) / 2;

    //cout << xm << " " << ym << endl;

    ld tmp_x = x - xm, tmp_y = y - ym;

    ld rotate = 180 - (180 * (n-2) / n);
    //cout << rotate << endl;

    ld rad = (rotate / 180) * PI;

    ld new_x = tmp_x * cos(rad) - tmp_y * sin(rad);
    ld new_y = tmp_x * sin(rad) + tmp_y * cos(rad);

    cout << new_x + xm << " " << new_y + ym << endl;

}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll x,y,a,b;
    cin>>x>>y;
    cin>>a>>b;
    ll ans=0;
    while(x<b)
    {
        x=x*a;
        if(x>=y)
            break;
        ans++;
    }
    if(x>=y)
    {
        cout<<ans;
        return 0;
    }
    ans=ans+(y-x+b-1)/b;
    cout<<ans-1;
}


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

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

     n=sqrt(8*n+1);
     n=(n-1)/2;

     int x=n;
     if(n>x)
     x++;
     cout<<x<<endl;
}

#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <set>
using namespace std;
int main(){
  int n;
  cin >> n;
  int pb = 1;
  int add = 2;
  for(int i = 1; i <= n; i++){
  if(pb >= n){
    cout << i;
    break;
  }else {
 pb = pb + add;
 add++;
  }
  }
}


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

typedef long long LL;

const LL INF = 1e18 + 7;
const LL N = 2e5 + 7;

LL x, y, ans;
map<LL, LL> dp;

LL dfs(LL v) {
    LL &res = dp[v];
    if (res) return res;
    if (v <= x) return res = x - v;
    res = v - x;
    if (v % 2 == 0) {
        res = min(res, dfs(v / 2) + 1);
    }
    else {
        res = min(res, min(dfs(v - 1), dfs(v + 1)) + 1);
    }
    return res;
}

int main()
{
    cin >> x >> y;
    ans = dfs(y);
    cout << ans << endl;
    return 0;
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}
template<unsigned MOD_> struct ModInt {
    static constexpr unsigned MOD = MOD_;
    unsigned x;
    void undef() { x = (unsigned)-1; }
    bool isnan() const { return x == (unsigned)-1; }
    inline int geti() const { return (int)x; }
    ModInt() { x = 0; }
    ModInt(int y) { if (y<0 || (int)MOD<=y) y %= (int)MOD; if (y<0) y += MOD; x=y; }
    ModInt(unsigned y) { if (MOD<=y) x = y % MOD; else x = y; }
    ModInt(long long y) { if (y<0 || MOD<=y) y %= MOD; if (y<0) y += MOD; x=y; }
    ModInt(unsigned long long y) { if (MOD<=y) x = y % MOD; else x = y; }
    ModInt &operator+=(const ModInt y) { if ((x += y.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(const ModInt y) { if ((x -= y.x) & (1u<<31)) x += MOD; return *this; }
    ModInt &operator*=(const ModInt y) { x = (unsigned long long)x * y.x % MOD; return *this; }
    ModInt &operator/=(const ModInt y) { x = (unsigned long long)x * y.inv().x % MOD; return *this; }
    ModInt operator-() const { return (x ? MOD-x: 0); }

    ModInt inv() const { return pow(MOD-2); }
    ModInt pow(long long y) const {
	ModInt b = *this, r = 1;
	if (y < 0) { b = b.inv(); y = -y; }
	for (; y; y>>=1) {
	    if (y&1) r *= b;
	    b *= b;
	}
	return r;
    }

    friend ModInt operator+(ModInt x, const ModInt y) { return x += y; }
    friend ModInt operator-(ModInt x, const ModInt y) { return x -= y; }
    friend ModInt operator*(ModInt x, const ModInt y) { return x *= y; }
    friend ModInt operator/(ModInt x, const ModInt y) { return x *= y.inv(); }
    friend bool operator<(const ModInt x, const ModInt y) { return x.x < y.x; }
    friend bool operator==(const ModInt x, const ModInt y) { return x.x == y.x; }
    friend bool operator!=(const ModInt x, const ModInt y) { return x.x != y.x; }
};

constexpr LL MOD = 998244353;
using Mint = ModInt<MOD>;
const int MAX = 1000011;
Mint inv[MAX], fact[MAX], fact_inv[MAX];

bool _auto_init() {
    fact[0] = 1;
    for (int i=1; i<MAX; i++) fact[i] = fact[i-1] * i;
    fact_inv[MAX-1] = fact[MAX-1].inv();
    for (int i=MAX-2; i>=0; i--) fact_inv[i] = fact_inv[i+1] * (i+1);
    inv[0] = 0;
    for (int i=1; i<MAX; i++) inv[i] = fact_inv[i] * fact[i-1];
    return true;
}
const bool _auto_init_done = _auto_init();

Mint nCk(int n, int k) {
    return fact[n] * fact_inv[k] * fact_inv[n-k];
}

int N, K;
int A[200011];

Mint ans[611];
Mint S[611];

void MAIN() {
    scanf("%d%d", &N, &K);
    REP (i, N) scanf("%d", A+i);

    REP (i, N) {
	Mint p = 1;
	REP (k, K+1) {
	    S[k] += p;
	    p *= A[i];
	}
    }

    REP (x, K+1) REP (y, K+1-x) {
	ans[x+y] += S[x] * S[y] * nCk(x+y, x);
    }

    REP (i, N) {
	Mint p = 1;
	Mint t = 1;
	REP (k, K+1) {
	    ans[k] -= p * t;
	    S[k] += p;
	    p *= A[i];
	    t += t;
	}
    }

    Mint inv2 = Mint(1)/2;
    REP (k, K+1) ans[k] *= inv2;
    for (int k=1; k<=K; k++) {
	printf("%d\n", ans[k].geti());
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}


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

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

    string s, t, r;
    cin >> s;
    string::size_type i = 0;
    for(string::size_type j; (j = s.find('R', i)) != string::npos; i = j + 1) {
        t.append(s, i, j - i);
        swap(t, r);
    }
    t.append(s, i);
    reverse(begin(r), end(r));
    s = ' ';
    for(char c: r + t) {
        if(s.back() == c) {
            s.pop_back();
        } else {
            s.push_back(c);
        }
    }

    cout << s << '\n';

    return 0;
}

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

typedef vector<long long int> vi;
typedef long long ll;

int main(){

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

  float n;cin>>n;
  if(floor(n*1.08)<206)cout<<"Yay!";
  else if(floor(n*1.08)==206)cout<<"so-so";
  else if(floor(n*1.08)>206)cout<<":(";

}


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

int main() {
    string x;
    cin >> x;
    ll m;
    cin >> m;

    if (x.size() == 1){
        if(stoi(x) <= m) cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    }

    ll d = 0;
    for(char c: x) d = max(d, ll(c - '0'));

    ll ac = d;
    ll wa = m + 1;

    while(wa - ac > 1){
        ll wj = (wa + ac) / 2;
        ll v = 0;
        for(char c: x){
            if (m/wj < v){
                v = m + 1;
                break;
            }
            else v = v * wj + ll(c - '0');
        }
        if (v <= m) ac = wj;
        else wa = wj;
    }
    cout << ac - d << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

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

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

void solve(std::vector<int64_t> X, int64_t M) {
  int64_t d = *max_element(X.begin(), X.end());
  int L = X.size();

  auto convert_base = [](int64_t K, int64_t base) -> vector<int64_t> {
    vector<int64_t> digits;
    while (K) {
      digits.push_back(K % base);
      K /= base;
    }
    reverse(digits.begin(), digits.end());
    return digits;
  };

  auto calc = [&](int64_t K, int64_t base) -> bool {
    vector<int64_t> Y = convert_base(K, base);
    if (X.size() < Y.size()) {
      return true;
    } else if (X.size() > Y.size()) {
      return false;
    }

    for (int i = 0; i < X.size(); i++) {
      if (X[i] < Y[i]) {
        return true;
      } else if (X[i] > Y[i]) {
        return false;
      }
    }
    return true;
  };

  if (L == 1) {
    if (calc(M, d + 1)) {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
    return;
  }

  if (!calc(M, d + 1)) {
    cout << 0 << endl;
    return;
  }

  int64_t ok = d + 1;
  int64_t ng = M + 1;
  while (ok + 1 < ng) {
    int64_t base = (ok + ng) / 2;
    if (calc(M, base)) {
      ok = base;
    } else {
      ng = base;
    }
  }
  cout << ok - d << endl;
}

int main() {
  std::string X;
  std::cin >> X;
  vector<int64_t> x;
  for (char c : X) {
    x.push_back(c - '0');
  }
  int64_t M;
  scanf("%ld", &M);
  solve(x, M);
  return 0;
}


#include <iostream>
#include"bits/stdc++.h"

using namespace std;

int dx[] ={0,0,1,-1};
int dy[]={1,-1,0,0};
int cost[2001][2001];
char g[2001][2001];
int H,W;
vector<vector<pair<int,int>>>v(26);

bool valid(int x , int y ){
return x<H && y<W && x>=0 && y>=0 && g[x][y] != '#' && cost[x][y] == -1;

}
void bfs(int bx, int by){
memset(cost,-1, sizeof cost);
queue<pair<int ,int>>q;
q.push({bx,by});
cost[bx][by]= 0;

while(!q.empty()){
    int x = q.front().first, y = q.front().second;
    q.pop();

    if(g[x][y]== 'G')
        return;
    for(int i =0;i<4;++i){
        int nX = x + dx[i], nY = y+ dy[i];
        if(valid(nX,nY)){
            cost[nX][nY] = 1 + cost[x][y];
            q.push({nX,nY});
        }

    }
    if(g[x][y] >= 'a' && g[x][y] <= 'z'){
            int cur = g[x][y] - 'a' ;
    for(int i=0;i<(int)v[ cur].size();++i){
        if(v[cur][i].first ==x && v[cur][i].second ==y)continue;
        int nX = v[cur][i].first, nY = v[cur][i].second;
        if(cost[nX][nY] == -1 ){
            cost[nX][nY] = 1 + cost[x][y];
            q.push({nX,nY});
        }

    }

        v[cur].clear();

    }

}

}
int main()
{
   // ios_base::sync_with_stdio(0);
   // cin.tie(0);
    cin>>H>>W;
    int sx,sy,ex,ey;
    for(int i=0;i<H;++i)
    for(int j=0;j<W;++j){
       //cin>>g[i][j];
       scanf(" %c",&g[i][j]);

          if(g[i][j] >= 'a' && g[i][j] <= 'z'){
            int cur = g[i][j] - 'a' ;
            v[cur].push_back({i,j});

          }
        if(g[i][j]== 'S')
            sx=i,sy=j;
        else if (g[i][j]== 'G')
            ex=i,ey=j;
    }
    bfs(sx,sy);

    cout << cost[ex][ey] << endl;
    return 0;
}

#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define SIZE 200005

int N,M;
ll A[SIZE];
vector<int> G[SIZE];

int main(){

	scanf("%d %d",&N,&M);

	for(ll i = 0; i < N; i++){

		scanf("%lld",&A[i]);
	}

	int from,to;

	for(ll i = 0; i < M; i++){

		scanf("%d %d",&from,&to);
		from--;
		to--;

		G[to].push_back(from);
	}

	ll ans = -HUGE_NUM;

	for(int i = 1; i < N; i++){
		ll minimum = HUGE_NUM;
		for(int k = 0; k < G[i].size(); k++){

			minimum = min(minimum,A[G[i][k]]);
		}
		ans = max(ans,A[i]-minimum);
		A[i] = min(A[i],minimum);
	}

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

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
template<class T> inline int  sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
//----------------------------
// 抽象化セグ木
// 二項演算と単位元を渡して使ってね
///****例****************************
//  auto f = [&](int a,int b){ return a+b;}; // 二項演算:和
//  int id = 0; //単位元:0
//  SegTree<decltype(f),int> seg(f,id);
//************************************
//----------------------------

template <typename F,typename T>
struct SegTree{
  // 二項演算merge,単位元identify
  T identity;
  F merge;
  int size;
  vector<T> dat;

  // 二項演算fと単位元idを渡して宣言する
  SegTree(F f,T id):merge(f),identity(id){}

  // データの要素の数nを渡して初期化、sizeはnより大きい2の冪乗
  void init(int n){
    size = 1;
    while(size<=n) size *= 2;
    dat.resize(size*2-1,identity);
  }

  // 配列を渡して0(n)で初期化
  void build(vector<T> vec){
    rep(i,vec.size()) dat[size-1+i] = vec[i];
    dfs(0);
  }

  T dfs(int k){
    if(k>=size-1) return dat[k];
    else return dat[k] = merge(dfs(2*k+1),dfs(2*k+2));
  }

  // index kの要素をaに変更
  void update(int k,T a){
    k += size - 1;
    dat[k] = a;
    while(k > 0){
      k = (k-1)/2;
      dat[k] = merge(dat[2*k+1],dat[2*k+2]);
    }
  }

  // index kの要素にaを加算
  void add(int k,T a){
    k += size - 1;
    dat[k] += a;
    while(k > 0){
      k = (k-1)/2;
      dat[k] = merge(dat[2*k+1],dat[2*k+2]);
    }
  }

  // 区間[a,b)に対するクエリに答える。(k,l,r)=(0,0,size)
  T query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return identity;

    if(a<=l&&r<=b) return dat[k];
    else return merge(query(a,b,2*k+1,l,(l+r)/2),query(a,b,2*k+2,(l+r)/2,r));
  }

  T query(int a,int b){
    return query(a, b, 0, 0, size);
  }

  // デバッグ用
  void show(){
    int index = 0;
    int num = 1;
    while(index<size){
      rep(i,num){
	if(dat[i+index]==identity) cout << "e ";
	else cout << dat[i+index] << " ";
      }
      cout << "\n";
      num *= 2;
      index = index*2+1;
    }
  }

};

int main()
{
  string s; cin >> s;
  int n = sz(s);
  auto f = [&](ll a,ll b){ return a+b;}; // 二項演算:和
  ll id = 0; //単位元:0
  vector<SegTree<decltype(f),ll>> seg(26, SegTree<decltype(f),ll>(f,id));
  rep(i,26) seg[i].init(n);
  rep(i,n) {
    int c = s[i] - 'a';
    seg[c].add(i, (ll)1);
  }
  ll res = 0;
  ll right = n;
  int ch = 26;
  for(ll i = n-1; i > 0; --i) {
    if(s[i] == s[i-1]) {
      int c = s[i] - 'a';
      res += right - (i+1) - seg[c].query(i+1, right);
      if(ch != c) res += n - right;
      ch = c;
      right = i-1;
      i--;
    }
//    cout << i << res << "\n";
  }
  cout << res << "\n";

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define bit(n,k) ((n>>k)&1) //nのk　bit目
#define vec(T) vector<T>
#define vvec(T) vector<vector<T>>
using ll = long long;
using P = pair<int,int>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll llINF = 1LL << 60;
const int iINF = 1e9;

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

struct Solver{
    // 最大公約数
    int gcd(int a, int b){
    if (a%b == 0) return(b);
    else return(gcd(b, a%b));
    }

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

        map<int,int> mp;

        auto mpadd = [&](int ai, int xi){
            int p = mp[xi];
            mp[xi] = gcd(p,ai);
        };

        int amin=iINF;
        rep(i,N){
            int A; cin >> A;
            chmin(amin,A);
            for(int x=1; x*x <=A ; x++){
                if(A%x) continue;
                mpadd(A,x);
                mpadd(A,A/x);
            }
        }

        int ans = 0;
        for(auto mi:mp){
            if(mi.first <= amin && mi.first == mi.second ) ans++;
        }
        cout << ans << endl;

    }
};

int main(){
    int testcasenum=1;
    //cin >> testcasenum;
    rep1(ti,testcasenum){
        Solver solver;
        solver.solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
struct point
{
    ll x, y;
};
ll h, w, n, m;
ll travel(ve<ve<ll>> &arr, ll &x, ll &y, ll inc_x, ll inc_y)
{
    x = x + inc_x, y = y + inc_y;
    if (x < 1 || x > h)
    {
        return 1;
    }
    if (y < 1 || y > w)
    {
        return 1;
    }
    if (arr[x][y] == -1)
    {
        return 1;
    }
    return 2;
}
void light_up1(ve<ve<ll>> &arr, ve<ve<ll>> &visit, ll x1, ll y1)
{
    if (visit[x1][y1] == 1)
    {
        return;
    }
    visit[x1][y1] = 1;
    ll x = x1, y = y1;
    while (true)
    {
        ll val = travel(arr, x, y, 0, 1);
        if (val == 1 || visit[x][y] == 1)
        {
            break;
        }
        else if (val == 2)
        {
            visit[x][y] = 1;
            cc;
        }
    }
    x = x1, y = y1;
    while (true)
    {
        ll val = travel(arr, x, y, 0, -1);
        if (val == 1 || visit[x][y] == 1)
        {
            break;
        }
        else if (val == 2)
        {
            visit[x][y] = 1;
            cc;
        }
    }
}
void light_up2(ve<ve<ll>> &arr, ve<ve<ll>> &visit, ll x1, ll y1)
{
    if (visit[x1][y1] == 1)
    {
        return;
    }
    ll x = x1, y = y1;
    while (true)
    {
        ll val = travel(arr, x, y, 1, 0);
        if (val == 1 || visit[x][y] == 1)
        {
            break;
        }
        else if (val == 2)
        {
            visit[x][y] = 1;
            cc;
        }
    }
    x = x1, y = y1;
    while (true)
    {
        ll val = travel(arr, x, y, -1, 0);
        if (val == 1 || visit[x][y] == 1)
        {
            break;
        }
        else if (val == 2)
        {
            visit[x][y] = 1;
            cc;
        }
    }
}
int main()
{
    FAST
            cin >>
        h >> w >> n >> m;
    ve<ve<ll>> arr(h + 1, ve<ll>(w + 1, 0));
    ve<ve<ll>> visit1(h + 1, ve<ll>(w + 1, 0)), visit2(h + 1, ve<ll>(w + 1, 0));
    rep(i, 0, n)
    {
        ll x, y;
        cin >> x >> y;
        arr[x][y] = 1;
    }
    rep(i, 0, m)
    {
        ll x, y;
        cin >> x >> y;
        arr[x][y] = -1;
    }
    rep(i, 1, h + 1)
    {
        rep(j, 1, w + 1)
        {
            if (arr[i][j] == 1 && visit1[i][j] == 0)
            {
                light_up1(arr, visit1, i, j);
            }
        }
    }
    rep(i, 1, h + 1)
    {
        rep(j, 1, w + 1)
        {
            if (arr[i][j] == 1 && visit2[i][j] == 0)
            {
                light_up2(arr, visit2, i, j);
            }
        }
    }
    ll ans = 0;
    rep(i, 1, h + 1)
    {
        rep(j, 1, w + 1)
        {
            if (visit1[i][j] == 1 || visit2[i][j] == 1)
            {
                ans++;
            }
        }
    }
    cout << ans << "\n";
}

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

int main() {
	// your code goes here
	int h,w,cnt=0;
	cin>>h>>w;
	char wi[101][101];
	for(int i=0;i<h;i++){
	   for(int j=0;j<w;j++){
	       cin>>wi[i][j];
	   }
	}
	for(int i=0;i<h;i++){
	   for(int j=0;j<w;j++){
	       if(wi[i][j]=='.' && wi[i+1][j]=='.')
	        cnt++;
	       if(wi[i][j]=='.' && wi[i][j+1]=='.')
	        cnt++;
	   }
	}
	cout<<cnt<<endl;
	return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <limits.h>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ll T;cin >> T;
  rep(QQQ,T){
    ll N;cin >> N;
    map<ll,ll> M;
    rep(i,N){
      ll X;cin >> X;
      M[X]++;
    }
    if(N%2==1){
      cout << "Second" << endl;
      continue;
    }
    ll Z=0;
    for (auto P : M){
      if(P.sc%2==1){
        Z=1;
      }
    }
    if(Z){
      cout << "First"<<  endl;
    }
    else{
      cout << "Second" << endl;
    }
  }
}

#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
#define INF 2000000000000000000
#define ll long long
#define ld long double
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll T;
  cin >> T;
  for (ll testcase = 0; testcase < T; ++testcase) {
    ll N;
    cin >> N;
    vector<ll> A(N);
    map<ll, ll> mp;
    for (ll i = 0; i < N; ++i) {
      cin >> A.at(i);
      mp[A.at(i)] += 1;
    }
    bool even = true;
    for (const auto& [key, value] : mp){
      if (value % 2 != 0) {
        even = false;
      }
    }
    if (N % 2 == 1) {
      cout << "Second" << "\n";
    }
    else {
      if (even) {
        cout << "Second" << "\n";
      }
      else {
        cout << "First" << "\n";
      }
    }
  }
}


//By Whisper_Rain
#include <iostream>
#include <cstdio>

using namespace std;

#define rep(i,x,y) for(int i=(x);i<=(y);i++)
#define per(i,x,y) for(int i=(x);i>=(y);i--)

int n;

signed main(){
    scanf("%d",&n);
    rep(i,1,n)
    {
        int link1=(i<<1)%n+1,link2=((i<<1)|1)%n+1;
        printf("%d %d\n",link1,link2);
    }
    return 0;
}

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

using ll = long long;
using Vi = std::vector<int>;
using Vl = std::vector<ll>;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

constexpr int I_INF = std::numeric_limits<int>::max();
constexpr ll L_INF = std::numeric_limits<ll>::max();

template <typename T1, typename T2>
inline bool chmin(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <std::ostream& os = std::cout>
class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        auto operator()(const Args&... args) const -> decltype((os << ... << std::declval<Args>()), void()) { print(args...); }
        template <typename T>
        auto pvec(const T& vec, size_t sz) const -> decltype(os << std::declval<decltype(std::declval<T>()[0])>(), void()) {
            for (size_t i = 0; i < sz; i++)
                os << vec[i] << (i == sz - 1 ? term : sep);
        }
        template <typename T>
        auto pmat(const T& mat, size_t h, size_t w) -> decltype(os << std::declval<decltype(std::declval<T>()[0][0])>(), void()) {
            for (size_t i = 0; i < h; i++)
                for (size_t j = 0; j < w; j++)
                    os << mat[i][j] << (j == w - 1 ? term : sep);
        }

    private:
        const char *sep, *term;
        void print() const { os << term; }
        void print_rest() const { os << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { os << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { os << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints<> prints;
Prints<std::cerr> prints_err;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    int N;
    cin >> N;
    vector<Pii> ans(N);
    for (ll i = 0; i < N; i++) {
        ans[i].first = 2 * (i + 1) % N;
        ans[i].second = (2 * (i + 1) + 1) % N;
    }
    for (auto [a, b] : ans) {
        prints()(a + 1, b + 1);
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    std::ifstream ifs("./in_out/input.txt");
    std::cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    std::ofstream ofs("./in_out/output.txt");
    std::cout.rdbuf(ofs.rdbuf());
#endif
    std::cout << std::setprecision(18) << std::fixed;
    solve();
    std::cout << std::flush;
    return 0;
}


#define LOCAL
#include <bits/stdc++.h>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int& x : a) {
    cin >> x;
  }
  int nax = 0;
  int answer = -1;
  for (int i = 2; i <= 1000; i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++) {
      if (a[j] % i == 0) cnt++;
      if (cnt > nax) {
        nax = cnt;
        answer = i;
      }
    }
  }
  cout << answer << "\n";
}

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

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#include "atcoder/all"

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

bool equal(double a, double b) {
//    return fabs(a - b) < DBL_EPSILON;
    return fabs(a - b) < EPS;
}

template<class T>
std::istream &operator>>(std::istream &in, set<T> &o) {
    T a;
    in >> a;
    o.insert(a);
    return in;
}

template<class T>
std::istream &operator>>(std::istream &in, queue<T> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

template<class T>
bool contain(set<T> &s, T a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

map<ll, int> factorize(ll n) {
    map<ll, int> res;

    for (ll i = 2; i * i <= n; i++) {
        if (n % i != 0) {
            continue;
        }
        res[i] = 0;
        while (n % i == 0) {
            n /= i;
            res[i]++;
        }
    }

    if (n != 1) res[n] = 1;
    return res;
}

int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    rep(i, n) cin >> v[i];

    vector<map<ll, int>> f(n);
    rep(i, n) f[i] = factorize(v[i]);

    map<int, int> m;
    rep(i, n) {
        for (auto &e: f[i]) {
            m[e.first]++;
        }
    }

    int ma = 0;
    for (auto &e : m) cmax(ma, e.second);

    for (auto &e : m) {
        if (ma == e.second) {
            cout << e.first << endl;
            ret();
        }
    }

}


#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
// #define MOD 998'244'353
// #define MOD 1'000'000'007
#define INF 100'000'000'000'000'000
using namespace std;
// using namespace atcoder;
typedef long long ll;

int main(){
    int N;
    cin >> N;
    ll A[N+1];
    rep1(i, N) cin >> A[i]; // A[0]は使わない

    ll sum[N+1];
    sum[0] = 0;
    for(int i = 1; i <= N; i++){
        sum[i] = sum[i-1] + A[i];
    }

    ll sumsum[N+1];
    ll maxsumsum[N+1];
    sumsum[0] = sum[0];
    maxsumsum[0] = sumsum[0];
    for(int i = 1; i <= N; i++){
        sumsum[i] = sumsum[i-1] + sum[i];
    }

    maxsumsum[N-1] = sumsum[N-1];
    for(int i = N - 2; i >= 0; i--){
        maxsumsum[i] = max(maxsumsum[i+1], sumsum[i]);
    }
    // for(int i = 2; i < N; i++){
    //     maxsumsum[i] = max(maxsumsum[i-1], sumsum[i-1]);
    //     // cout << i << sumsum[i] << " : " << maxsumsum[i] << endl;
    // }

    ll ans = -INF;

    ll temp;
    for(int i = 1; i <= N; i++){
        temp = sumsum[i];
        // cout << temp << endl;
        temp += (maxsumsum[i-1] - sumsum[i-1]);
        if (temp > ans){
            ans = temp;
        }
        // cout << i << " : " << temp << endl;
    }

    if (ans < 0) ans = 0;

    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using ll = long long;
int mod = 1000000007;
const int INF = 1001001001;
template<class T> void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> void chmax(T& a, T b) {if (a < b) a = b;}
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using Graph = vector<vector<int>>;

int main() {
    string n; cin >> n ;
    ll x = n.size();
    if (x % 2 == 1) {
        ll oans = 0;
        ll y = x / 2;
        rep(i,y) {
            oans += 9 * pow(10, i);
        }
        cout << oans << endl;
        return 0;
    }
    ll A = 0, B = 0;
    for (int i = 0; i < x/2; i++) {
        A += (n[i] - '0') * pow(10, x/2-1-i);
    }
    for (int i = 0; i < x/2; i++) {
        B += (n[x/2+i] - '0') * pow(10, x/2-1-i);
    }
    if (A > B) cout << A - 1 << endl;
    else cout << A  << endl;
    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <functional>
#include <iomanip>
#include <cstdint>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tpiii tuple<int,int,int>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector
#define vi vec<int>
#define vl vec<ll>
#define vivi vec<vi>
#define vlvl vec<vl>
#define vpii vec<pii>
#define vpll vec<pll>
#define vbl vec<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
#define D(x) cout << (#x) << " is " << x << endl;
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}
void drop(string s){cout<<s<<endl; exit(0);}
void drop(int x){cout<<x<<endl; exit(0);}
void drop(ll x){cout<<x<<endl; exit(0);}
void drop(double x){cout<<x<<endl; exit(0);}

ll F(ll a,ll b){
    return a xor b;
}
using namespace std;

template<class T,class M>
class SegTreeLazy{
    int n;
    vector<T> data,lazy;
    const T defT; //初期値かつ単位元
    const M defM;
    function<T(T,T)> ftt;
    function<T(T,T)> update;
    function<T(T,M)> ftm;
    function<M(M,M)> fmm;

    public:
    SegTreeLazy(size_t _n, T _defT, M _defM, function<T(T,T)> _ftt, function<T(T,T)> _update, function<T(T,M)> _ftm, function<T(M,M)> _fmm)
        :defT(_defT),defM(_defM),ftt(_ftt),update(_update),ftm(_ftm),fmm(_fmm){
        n = 1;
            while(n < _n)n*=2;
            data = vector<T>(2*n-1,defT);
            lazy = vector<M>(2*n-1,defM);
    }

    //初期値代入
    void set(int i,T x){
        data[i+n-1] = x;
    }
    void build(){ //セグ木を一通り作ったらこれをする！！！
        for(int i = n-2; i>=0; i--) data[i] = ftt(data[i*2+1],data[i*2+2]);
    }

    //遅延評価
    void eval(int k){
        if(lazy[k]==defM) return;
        if(k < n-1){
            lazy[k*2+1] = fmm(lazy[k*2+1], lazy[k]);
            lazy[k*2+2] = fmm(lazy[k*2+2], lazy[k]);
        }
        data[k] = ftm(data[k],lazy[k]);
        lazy[k] = defM;
    }
    T _query(int a,int b,int k,int l,int r){
        eval(k);
        if(r<=a || b<=l)return defT;
        if(a <= l && r <= b)return data[k];
        else{
            T c1 = _query(a,b,2*k+1,l,(l+r)/2);
            T c2 = _query(a,b,2*k+2,(l+r)/2,r);
            return ftt(c1,c2);
        }
    }

    //sum of [a,b)
    T query(int a,int b){
        return _query(a,b,0,0,n);
    }

    //change of a range
    void _change(int a,int b,M x,int k,int l,int r){
        eval(k);
        if(a <= l && r <= b){
            lazy[k] = fmm(lazy[k],x);
            eval(k);
        }else if (a < r && l < b){
            _change(a,b,x,k*2+1,l,(l+r)/2);
            _change(a,b,x,k*2+2,(l+r)/2,r);
            data[k] = ftt(data[k*2+1],data[k*2+2]);
        }
    }
    void change(int a,int b,M x){
        _change(a,b,x,0,0,n);
    }
    //access : SegTreeLazy型の変数stlについて、stl[i]でi番目の葉の値を返す
    T operator[](int i){
        return query(i,i+1);
    }
};
int main(){
    int n=in(),q=in();
    SegTreeLazy<ll,ll> tree(n,0,0,F,F,F,F);
    rep(i,n){
        tree.set(i,in());
    }
    tree.build();
    rep(i,q){
        int t=in(),x=in()-1,y=in();
        if(t==1){
            tree.change(x,x+1,y);
        }else{
            cout<<tree.query(x,y)<<endl;
        }
    }
}

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

template <typename T>
class SegmentTree
{
    std::vector<T> arr;
    const std::size_t size;
    const std::function<T(const T, const T)> operation;
    const T initial_value;

    std::size_t calc_size(const std::size_t N) const
    {
        std::size_t n = 1;
        while (n < N + 1)
        {
            n *= 2;
        }
        return n;
    }

    void initialize_array()
    {
        this->arr = std::vector<T>(2 * this->size - 1, this->initial_value);
    }

    T query(const std::size_t a, const std::size_t b, const std::size_t k, const std::size_t l, const std::size_t r) const
    {
        if (r <= a || b <= l)
        {
            return this->initial_value;
        }
        if (a <= l && r <= b)
        {
            return this->arr[k];
        }
        else
        {
            return this->operation(
                this->query(a, b, 2 * k + 1, l, (l + r) / 2),
                this->query(a, b, 2 * k + 2, (l + r) / 2, r));
        }
    }

public:
    SegmentTree(const std::size_t N, const std::function<T(const T, const T)> func, const T init) : size(this->calc_size(N)), operation(func), initial_value(init)
    {
        this->initialize_array();
    }

    void update(const std::size_t idx, const T value)
    {
        std::size_t modify_idx = idx;
        modify_idx += this->size - 1;
        this->arr[modify_idx] = value;
        while (modify_idx > 0)
        {
            modify_idx = (modify_idx - 1) / 2;
            this->arr[modify_idx] = this->operation(this->arr[modify_idx * 2 + 1], this->arr[modify_idx * 2 + 2]);
        }
    }

    T query(const std::size_t idx) const
    {
        return this->arr[idx + this->size - 1];
    }

    // [idx_a, idx_b)
    T query(const std::size_t idx_a, const std::size_t idx_b) const
    {
        return this->query(idx_a, idx_b, 0, 0, this->size);
    }

    T operator[](const std::size_t idx) const
    {
        return this->arr[idx + this->size - 1];
    }
};

int main()
{
    size_t N, Q;
    cin >> N >> Q;
    SegmentTree<int> st(
        N + 1, [](int a, int b) { return a ^ b; }, 0);

    int A;
    for (size_t i = 1; i <= N; i++)
    {
        cin >> A;
        st.update(i, A);
    }

    int T, X, Y;
    for (size_t i = 0; i < Q; i++)
    {
        cin >> T >> X >> Y;
        if (T == 1)
        {
            st.update(X, st[X] ^ Y);
        }
        if (T == 2)
        {

            cout << st.query(X, Y + 1) << endl;
        }
    }
}


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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
#define all(v) (v).begin(),(v).end()
#define MAXN 300005
int MOD = 1e9 + 7;
ll power(ll a, ll b) { //a^b
    ll res = 1;
    a = a % MOD;
    while (b > 0) {
        if (b & 1) {res = (res * a) % MOD; b--;}
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}
ll fermat_inv(ll y) {return power(y, MOD - 2);}
ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}
ll min(ll a, ll b) {return (a > b) ? b : a;}
ll max(ll a, ll b) {return (a > b) ? a : b;}

struct node{
    ll s,c;
    node(){
        c=s=0;
    }
    node operator +(const node& other){
        node sum=node();
        sum.s=s+other.s;
        sum.c=c+other.c;
        return sum;
    }
};
struct SegTree {
    vector<node>t;
    ll n;
    SegTree(ll n){
        this->n = n;
        t.assign(4*n+10,node());
    }
    node sum(ll v,ll tl,ll tr,ll l,ll r)
    {
        if(l>r)
            return node();
        if(l==tl&&r==tr)
            return t[v];
        ll tm=(tl+tr)/2;
        return sum(v*2,tl,tm,l,min(r,tm))+sum(v*2+1,tm+1,tr,max(l,tm+1),r);
    }
    ll sum(ll l,ll r){
        return sum(1,1,n,l,r).s;
    }
    ll cnt(ll l,ll r){
        return sum(1,1,n,l,r).c;
    }
    void update(ll v,ll tl,ll tr,ll pos,ll new_val,ll cnt)
    {
        if(tl==tr)
            t[v].s+=new_val,t[v].c+=cnt;
        else{
            ll tm=(tl+tr)/2;
            if(pos<=tm)
                update(2*v,tl,tm,pos,new_val,cnt);
            else
                update(2*v+1,tm+1,tr,pos,new_val,cnt);
            t[v]=t[2*v]+t[2*v+1];
        }
    }
    void update(ll idx,ll a,ll c){
        update(1,1,n,idx,a,c);
    }
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int te = 1;
    //cin >> te;
    //SieveOfEratosthenes(1000000);
    //factorial(1000005);
    while (te--) {
        int n,m,q;
        cin>>n>>m>>q;
        ll ans=0,t[q],x[q],y[q],a[n+1]={0},b[m+1]={0};
        map<int,int>mp;
        for(int i=0;i<q;i++){
            cin>>t[i]>>x[i]>>y[i];
            mp[y[i]]++;
        }
        int c=1;
        for(auto i:mp)
            mp[i.ff]=c++;
        SegTree S(c+5),T(c+5);
        for(int i=0;i<n;i++)
        	S.update(mp[a[i+1]],a[i+1],1);
        for(int i=0;i<m;i++)
        	T.update(mp[b[i+1]],b[i+1],1);
        for(int i=0;i<q;i++){
            if(t[i]==1){
                ans-=T.sum(mp[a[x[i]]]+1,c);
                ans-=a[x[i]]*T.cnt(1,mp[a[x[i]]]);
                //cout<<ans<<' ';
                S.update(mp[a[x[i]]],-a[x[i]],-1);
                a[x[i]]=y[i];
                S.update(mp[a[x[i]]],a[x[i]],1);
                ans+=T.sum(mp[a[x[i]]]+1,c);
                ans+=a[x[i]]*T.cnt(1,mp[a[x[i]]]);
            }
            else{
                ans-=S.sum(mp[b[x[i]]]+1,c);
                ans-=b[x[i]]*S.cnt(1,mp[b[x[i]]]);
                ///cout<<ans<<' ';
                T.update(mp[b[x[i]]],-b[x[i]],-1);
                b[x[i]]=y[i];
                T.update(mp[b[x[i]]],b[x[i]],1);
                ans+=S.sum(mp[b[x[i]]]+1,c);
                ans+=b[x[i]]*S.cnt(1,mp[b[x[i]]]);
            }
            cout<<ans<<'\n';
        }
    }
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)

template <typename T>
class Seg_Tree{
public: // 0-index
	vector<T> dat;
	T initial,M;
	int n;
	T unite(T a,T b){//
		return a + b;
	}
	void initsize(int n0,T initial_,T M_){
		M = M_;
		initial = initial_;
		int k=1;
		while(1){
			if(n0<=k){
				n=k;
				dat.resize(2*n-1);
				for(int i=0;i<2*n-1;i++)dat[i]=initial;
				break;
			}
			k*=2;
		}
	}

	//i banme wo x nisuru
	void update(int i,T x){
		i += n-1;
		dat[i] = x;
		while(i>0){
			i = (i-1) / 2;
			dat[i] = unite(dat[i*2+1],dat[i*2+2]);
		}
	}

	//[a,b)
	T query0(int a,int b,int k,int l,int r){
		if(r<=a || b<=l)return initial;
		if(a<=l && r<=b)return dat[k];
		else{
			T vl = query0(a,b,k*2+1,l,(l+r)/2);
			T vr = query0(a,b,k*2+2,(l+r)/2,r);
			return unite(vl,vr);
		}
	}

	//return [a,b)
	T query(int a,int b){
		return query0(a,b,0,0,n);
	}
};

map<ll,int> ma;
int index_ = 1;
ll ind(ll y){
	if(ma[y]) return ma[y];
	ma[y] = index_;
	index_++;
	return ma[y];
}

int main(){

	int N,M,Q;
	cin >> N >> M >> Q;
	vector< vector<ll> > A(2);
	A[0].resize(N,0);
	A[1].resize(M,0);

	vector<ll> T(Q),X(Q),Y(Q);

	FOR(i,0,Q) cin >> T[i] >> X[i] >> Y[i];
	vector<ll> useY;
	useY.push_back(0);
	FOR(i,0,Q) useY.push_back(Y[i]);

	sort(useY.begin(),useY.end());
	FOR(i,0,useY.size()) ind(useY[i]);

	vector< Seg_Tree<ll> > num(2);//個数
	vector< Seg_Tree<ll> > sum(2);//和
	num[0].initsize(index_+3,0,0);
	num[1].initsize(index_+3,0,0);
	sum[0].initsize(index_+3,0,0);
	sum[1].initsize(index_+3,0,0);
	num[0].update(1,N);
	num[1].update(1,M);

	ll ans = 0;

	FOR(i,0,Q){
		int change = T[i]-1;
		int stay = (change+1) % 2;
		int j = X[i] - 1;

		ll min_num = num[stay].query( 0 , ind(A[change][j]) );
		ll from = A[change][j];
		A[change][j] = Y[i];
		ll to = Y[i];
		ans -= min_num * from;
		ans -= sum[stay].query( ind(from) , 400003 );
		min_num = num[stay].query( 0 , ind(to) );
		ans += min_num * to;
		ans += sum[stay].query( ind(to) , 400003);

		int index = ind(from);
		ll cnt = num[change].query(index,index+1);
		num[change].update(index , cnt-1);
		sum[change].update(index , cnt*from-from);

		index = ind(to);
		cnt = num[change].query(index,index+1);
		num[change].update(index , cnt+1);
		sum[change].update(index , (cnt+1)*to);
		cout << ans << endl;
	}
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<vector<long long>> a(n, vector<long long>(n));
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  for (long long i = 1; i < n; i++) {
    for (long long j = 1; j < n; j++) {
      if (((a[i][j] - a[i][j - 1]) != (a[i - 1][j] - a[i - 1][j - 1])) || ((a[i][j] - a[i - 1][j]) != (a[i][j - 1] - a[i - 1][j - 1]))) {
        return cout << "No\n", 0;
      }
    }
  }
  long long mn = 1e18 + 9, si = 0, sj = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      if (a[i][j] < mn) {
        si = i; sj = j;
        mn = a[i][j];
      }
    }
  }
  vector<long long> aa(n), bb(n);
  bb[0] = 0;
  for (long long j = 1; j < n; j++) {
    bb[j] = a[0][j] - a[0][j - 1] + bb[j - 1];
  }
  mn = *min_element(bb.begin(), bb.end());
  for (int i = 0; i < n; i++) bb[i] -= mn;
  for (long long i = 0; i < n; i++) {
    aa[i] = a[i][0] - bb[0];
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      assert(aa[i] >= 0 && bb[j] >= 0 && a[i][j] == bb[j] + aa[i]);
    }
  }
  cout << "Yes\n";
  for (long long i = 0; i < n; i++) {
    if (i > 0) {
      cout << " ";
    }
    cout << aa[i];
  }
  cout << '\n';
  for (long long i = 0; i < n; i++) {
    if (i > 0) {
      cout << " ";
    }
    cout << bb[i] << " ";
  }
  cout << '\n';
  return 0;
}

#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2")
#pragma GCC optimize("unroll-loops")
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define req(i,a,b) for(int i=(a);i>=(b);--i)
#define rep_(i,a,b) for(int i=(a);i<(b).size();++i)
#define F(a) rep(a,1,n)
#define M(a,b) memset(a,b,sizeof a)
#define DC int T;cin>>T;while(T--)
#define ll long long
#define Z(a,b) sort(a+1,a+b+1)
using namespace std;
const unsigned _mod=998244353;
const unsigned mod=3;
const ll infi=0x3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
void rd(auto &x){x=0;int f=1;char ch=getchar();while(ch<48||ch>57){if(ch==45)f=-1;ch=getchar();}while(ch>=48&&ch<=57)x=x*10+ch-48,ch=getchar();x*=f;}
ll ksm(ll x,ll y=mod-2,ll m=mod){ll ret=1;while(y){if(y&1)ret=ret*x%m;y>>=1ll;x=x*x%m;}return ret;}
ll qpow(ll x,ll y=2){ll ret=1;while(y>0){if(y&1ll)ret=ret*x;y>>=1ll;x=x*x;}return ret;}
/*
    [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
    [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
    [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
*/
int n,dep[200010],rt,cnt,E[200010],dis[200010];
vector<int> T[200010];
bool vis[200010];
bool cmp(int x,int y){return dep[x]<dep[y];}
void getdis(int u,int fa) {for (int v:T[u]) if (v!=fa) dis[v]=dis[u]+1,getdis(v,u);}
void _dfs(int x){
	if (T[x].size()==1) dep[x]=1;
	for (int u:T[x]) if (!vis[u]) vis[u]=1,_dfs(u),dep[x]=max(dep[u]+1,dep[x]);
}
void dfs(int x){
	cnt++,E[x]=cnt;
	for(int u:T[x]) if (!vis[u]) vis[u]=1,dfs(u),cnt++;
}
int main()
{
	cin>>n;
	rep(i,1,n-1)
	{
		int a,b;
		rd(a),rd(b);
		T[a].push_back(b),T[b].push_back(a);
	}
	getdis(1,0);rt=1;
	F(i) if (dis[i]>=dis[rt]) rt=i;
	vis[rt]=1;
	_dfs(rt);
	F(i) sort(T[i].begin(),T[i].end(),cmp);
	M(vis,0);
	vis[rt]=1;
	dfs(rt);
	F(i) cout<<E[i]<<' ';
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define vi vector<int>
#define vvi vector<vector<int> >
#define mii map<int,int>
#define pb push_back
#define pii pair<int,int>
#define mkp make_pair
#define scan(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define loop(i,n) for (int i = 0; i < n; i++)
#define loop1(i,n) for (int i = 1; i < n; i++)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION std::cout.unsetf ( std::ios::floatfield );std::cout.precision(15)
#define PI 3.14159265
#define endl '\n'
using namespace std;
int mod = 1000000007;
int m_inf = INT_MIN;

void init_code()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE
}

void solve()
{
    string s;
    cin>>s;
    ll n=s.length();
    ll ans=0;
    vector<ll> cnt(26,0);
    for(ll i=n-1,j=0;i>0;--i,++j)
    {
        if(i<n-1 && i>0 && s[i]==s[i-1] && s[i]!=s[i+1])
        {
            ans+=j-cnt[s[i]-'a'];
            cnt.assign(26,0);
            cnt[s[i]-'a']=j;
        }
        cnt[s[i]-'a']++;
    }
    cout<<ans;
}

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

// Hail god Yato

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

#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
void solve(){
    string str;
    cin>>str;
    int arr[26] = {0};
    ll n = str.length(), ans = 0;
    for(int i = n-1; i >= 1; i--){
        if(str[i] == str[i-1]){
            ans += n-i-1-arr[str[i] - 'a'];
            // cout<<ans<<"\n";
            for(int i = 0; i < 26; i++)
                arr[i] = 0;
            arr[str[i] - 'a'] = n-i+1;
            --i;
        }
        else
            ++arr[str[i] - 'a'];
    }
    cout<<ans;
}
signed main(){
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
set<int> have;

int main() {
	cin >> n;
	for (int i = 0; i <= n; i++)
		have.insert(i);

	for (int i = 1; i <= n; i++) {
		int nr;
		cin >> nr;
		have.erase(nr);
		cout << *have.begin() << '\n';
	}
}

/*
このコード、と～おれ!
Be accepted!
∧＿∧
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define repeat(i, n, m) for(int i = n; i < (m); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
inline T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

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

////atcoder library
//#include <atcoder/all>
//using namespace atcoder;

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int n;
	scanf("%d", &n);
	int ans = 0, a;
	set<int> st;
	rep(i, 200001)st.insert(i);
	rep(i, n) {
		scanf("%d", &a);
		st.erase(a);
		printf("%d\n", *st.begin());
	}

	Please AC;
}


#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define eps (double)(1e-9)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

ll cost(ll a, ll b, ll c, ll p, ll q, ll r){
    return abs(a-p) + abs(b-q) + max(0LL, r-c);
}

int main() {
    int n;
    cin >> n;
    vector<ll> x(n), y(n), z(n);
    rep(i, n)cin >> x[i] >> y[i] >> z[i];
    vector<vector<ll>> dp(1<<n, vector<ll>(n, inf));
    dp[0][0] = 0;
    rep(i, (1<<n)-1){
        rep(j, n){
            if(i & (1<<j) == 0)continue;
            rep(k, n){
                chmin(dp[i|(1<<k)][k], dp[i][j] + cost(x[j],y[j],z[j],x[k],y[k],z[k]));
            }
        }
    }
    vector<vector<ll>> mn(n, vector<ll>(n, inf));
    rep(i, n)rep(j, n)mn[i][j] = cost(x[i],y[i],z[i],x[j],y[j],z[j]);
    rep(k, n)rep(i, n)rep(j, n){
        chmin(mn[i][j], mn[i][k] + mn[k][j]);
    }
    ll ans = inf;
    rep(i, n)chmin(ans, dp[(1<<n)-1][i] + mn[i][0]);
    cout << ans << endl;
}

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

#define N               25
#define ff              first
#define ss              second
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define mii             map<ll,ll>
#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define inp(arr,n)      for(ll x=0;x<n;x++) cin>>arr[x];
#define w(x)            ll x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

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

ll n, done;
vector<vi> xyz;
ll dist[N][N], dp[1<<20][20];

ll f(ll mask, ll pos){
    if(mask == done) return dist[pos][0];

    if(dp[mask][pos] != -1) return dp[mask][pos];

    ll ans = inf;
    for(ll x=0;x<n;x++){
        if(! (mask & (1 << x))){
            ans = min(ans, f(mask|(1<<x), x) + dist[pos][x]);
        }
    }

    return dp[mask][pos] = ans;
}

int main(){
    fio();

    cin>>n;
    done = (1 << n) - 1;
    xyz.resize(n, vi(3));
    memset(dp, -1, sizeof dp);
    for(ll x=0;x<n;x++){
        cin>>xyz[x][0]>>xyz[x][1]>>xyz[x][2];
    }

    for(ll x=0;x<n;x++){
        for(ll y=0;y<n;y++){
            ll d = abs(xyz[x][0] - xyz[y][0]) + abs(xyz[x][1] - xyz[y][1]) + max(0ll, xyz[y][2] - xyz[x][2]);
            dist[x][y] = d;
        }
    }

    cout<<f(1, 0);

    return 0;
}


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

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
//main関数内に extGCD(a, b, x, y); でx, yに解が格納
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;
}

signed main() {
	//input
	ll t; cin >> t;
	rep(zz, t) {
		//n(x) - k(y) = s
		ll n, s, k; cin >> n >> s >> k; ll g = gcd(n, k);
		if (s % g != 0) { cout << "-1\n"; continue; }
		ll x, y; extGCD(n, k, x, y);
		//cout << x << ' ' << y << endl;
		x *= (s / g); y *= (s / g); y = 0 - y;
		k /= g; n /= g;
		if (y > 0) { y -= n * min(x / k, y / n); }
		else { y += n * max((0 - x + k - 1) / k, (0 - y + n - 1) / n); }
		cout << y << endl;
	}
	return 0;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define ad(a,b) a=(a+b)%mod;
ll po(ll x,ll y){
	ll res=1;
	for(;y;y>>=1){
		if(y&1)res=res*x%mod;
		x=x*x%mod;
	}
	return res;
}
ll gcd(ll a,ll b){
	return (b?gcd(b,a%b):a);
}
#define X 200010
ll fac[X],ivf[X];
void initfac(){
	fac[0]=1;
	for(ll i=1;i<X;i++)fac[i]=fac[i-1]*i%mod;
	for(ll i=0;i<X;i++)ivf[i]=po(fac[i],mod-2);
}
ll C(ll n,ll k){
	return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	ll n,p[200010],place[200010];
	cin>>n;
	rep(i,n){
		cin>>p[i]; p[i]--;
		place[p[i]]=i;
	}
	vector<ll> v;
	bool ok=1;
	ll s=0;
	while(1){
		ll i=place[s]-1;
		if(i<s){ok=0;break;}
		for(;i>=s;i--){
			v.push_back(i);
			swap(p[i+1],p[i]);
		}
		s=place[s];
		if(s==n-1)break;
	}
	rep(i,n)ok&=(p[i]==i);
	if(ok){
		rep(i,v.size())cout<<v[i]+1<<"\n";
	}
	else cout<<-1<<endl;
}


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

int ri(){
  int n;
  scanf("%d", &n);
  return n;
}

int main(){
  int h = ri();
  int w = ri();
  int x = ri() - 1;
  int y = ri() - 1;
  string s[h];
  for(auto &i : s) cin >> i;

  int cnt = -3;
  for(int i = x; i < h && s[i][y] != '#'; i++) cnt++;
  for(int i = x; i >= 0 && s[i][y] != '#'; i--) cnt++;
  for(int j = y; j < w && s[x][j] != '#'; j++) cnt++;
  for(int j = y; j >= 0 && s[x][j] != '#'; j--) cnt++;
  printf("%d\n", cnt);
  return 0;
}

/**
*    author:  Takeda Takumi
*    created: 27.03.2021 21:02:59
**/

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

int h, w;

ll find(int x, int y, int map[][101])
{
    ll res = 1;
    int i, j;

    i = x - 1;
    j = y;
    while (1 <= i && map[i][j] == 0)
    {
        res++;
        i--;
    }
    //cout << res << endl;

    i = x;
    j = y + 1;
    while (j <= w && map[i][j] == 0)
    {
        res++;
        j++;
    }
    //cout << res << endl;

    i = x + 1;
    j = y;
    while (i <= h && map[i][j] == 0)
    {
        res++;
        i++;
    }
    //cout << res << endl;

    i = x;
    j = y - 1;
    while (1 <= j && map[i][j] == 0)
    {
        res++;
        j--;
    }
    //cout << res << endl;

    return res;
}

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

    int map[101][101];
    for (int i = 1; i <= h; ++i)
    {
        for (int j = 1; j <= w; ++j)
        {
            map[i][j] = 0;
        }
    }
    for (int i = 1; i <= h; i++)
    {
        string s;
        cin >> s;
        for (int j = 1; j <= w; j++)
        {
            if (s[j - 1] == '#')
            {
                map[i][j] = 1;
            }
        }
    }
    /*
    for (int i = 1; i <= h; ++i)
    {
        for (int j = 1; j <= w; ++j)
        {
            cout << map[i][j];
        }
        cout << endl;
    }
    */
    cout << find(x, y, map) << endl;

    return 0;
}


#include<bits/stdc++.h>
#include<cstring>
//#define Mfc_Tanzim
#define   ll         long long
#define   ull        unsigned long long
#define   pb         push_back
#define   ff         first
#define   ss         second
#define   all(v)     (v.begin(), v.end())
#define   rall(v)    (v.rbegin(), v.rend())
#define   pi         acos(-1.0)
#define   FastRead   ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define   bug(a)     cerr << #a << " : " << a << endl
using namespace std;
const ll mod = 1e9+7;
const ll mx = 2e6+10;

int posx[] = {1,-1, 0, 0};
int posy[] = {0, 0, 1,-1};
ll x, y, arr[mx], arr2[mx];
vector<ll>graph[mx];
map<ll, bool>vis;

void Dfs(int src)
{
    x+=arr[src], y+=arr2[src];
    vis[src] = true;
    for(auto x: graph[src]){
              if(!vis[x]){
                      Dfs(x);
              }
    }
}

int main()
{
    FastRead

#ifdef Mfc_Tanzim
    freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
#endif /// Mfc_Tanzim

    ll t=1, n, k, m;
    //cin >> t;

    while(t--){
             cin >> n >> m;

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

             while(m--){
                       ll u, v;
                       cin >> u >> v;
                       graph[u].pb(v);
                       graph[v].pb(u);
             }
             bool ok = true;
             for(int i=1; i<=n; i++){
                       if(!vis[i]){
                               x = y = 0;
                               Dfs(i);
                               if(x!=y) ok = false;
                       }
             }
             cout << (ok? "Yes" : "No") << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int MOD = 1e9+7;
typedef pair<ll, ll> pairs;
typedef vector<pairs> p;
// #define ALL(obj) (obj).begin(),(obj).end()
struct edge{
    ll to, cost;
};

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

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

// 数字の桁数
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// べき乗の余り
ll modpow(ll a, ll n){
    ll res = 1;
    while(n){
        if(n & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        n = n >> 1;
    }
    return res;
}

// コンビネーション
ll MAXN = 2e5+10;
vector<ll> inv(MAXN);
ll nCk(ll n, ll k) {
	ll res = 1;
	for(ll i = 1; i <= k; i++) {
		res = res*(n-i+1) % MOD;
	}

	for(ll i = 1; i <= k; i++) {
		res = res*inv[i] % MOD;
	}
	return res;
}

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

int main(){
    ll n, m;
    cin>>n>>m;
    vector<ll> a(n), b(n);
    for(ll i=0;i<n;++i){
        cin>>a[i];
    }
    for(ll i=0;i<n;++i){
        cin>>b[i];
    }
    vector<ll> g[n];
    for(ll i=0;i<m;++i){
        ll c, d;
        cin>>c>>d;
        c--; d--;
        g[c].push_back(d);
        g[d].push_back(c);
    }

    vector<bool> d(n, false);
    queue<ll> q;
    string ans = "Yes";
    for(ll i=0;i<n;++i){
        ll sum = 0;
        if(d[i] == false){
            d[i] = true;
            q.push(i);
            sum += b[i] - a[i];
        }else{
            continue;
        }
        while(!q.empty()){
            ll x = q.front();
            q.pop();
            for(auto val : g[x]){
                if(d[val] == true){
                    continue;
                }
                q.push(val);
                sum += b[val] - a[val];
                d[val] = true;
            }
        }
        if(sum != 0){
            ans = "No";
            break;
        }
    }
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mpi map<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define pl pair<ll,ll>
#define pi pair<int,int>
#define forn(i,n) for(ll i=0;i<n;i++)
#define ff first
#define ss second
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inf       1000000000000
#define MOD       1000000007
ll binpow(ll a,ll b,ll m){
    a%=m;
    ll res=1;
    while(b>0){
        if(b&1)
            res=res*a%m;
        a=a*a%m;
        b>>=1;
    }
    return res;
}
vl edge[100005];
ll c[100005];
ll vis[100005];
vl ans;
map<ll,ll> mp;
void dfs(ll n){
    vis[n]=1;
    forn(i,edge[n].size()){
        if(vis[edge[n][i]]==0){
            if(mp[c[edge[n][i]]]==0){
                ans.pb(edge[n][i]);
            }
            mp[c[edge[n][i]]]++;
            dfs(edge[n][i]);
            mp[c[edge[n][i]]]--;
        }
    }
}
void solve(){
    ll n;
    cin>>n;
    forn(i,n)
    cin>>c[i+1];
    forn(i,n-1){
        ll x,y;
        cin>>x>>y;
        edge[x].pb(y);
        edge[y].pb(x);
    }
    forn(i,n)
    vis[i+1]=0;
    ans.pb(1);
    mp[c[1]]++;
    dfs(1);
    sort(ans.begin(),ans.end());
    forn(i,ans.size())
    cout<<ans[i]<<endl;
}

int main() {

    ll t=1;
    while(t--)
	{
        solve();
		cout<<endl;
    }

    return 0;
}

// Problem: B - Reversible Cards
// Contest: AtCoder - AtCoder Regular Contest 111
// URL: https://atcoder.jp/contests/arc111/tasks/arc111_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> g[400002];
int vis[400002];
pair<int, int> dfs1(int u, int v) {
  if (vis[u]) return {0, 0};
  vis[u] = true;
  int res1 = 1;
  int res2 = g[u].size();
  for (int x : g[u]) {
    if (x == v || x == u) continue;
    auto c = dfs1(x, u);
    res1 += c.first;
    res2 += c.second;
  }
  return {res1, res2};
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int sum = 0;
  for (int i = 0; i < 400002; i++) {
    if (g[i].size() && vis[i] == 0) {
      auto c = dfs1(i, 0);
      if (c.second / 2 < c.first) {
        sum--;
      }
      sum += c.first;
    }
  }

  cout << sum << endl;
}


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

ll solve(vl& A, map<P, ll>& m, ll x, int i) {
    if (i == int(A.size()) - 1) return 1;
    if (m.count(P(x, i))) return m[P(x, i)];
    ll d = x % A[i + 1];
    ll ret = solve(A, m, x - d, i + 1);
    if (d > 0) ret += solve(A, m, x + (A[i + 1] - d), i + 1);
    return m[P(x, i)] = ret;
}

int main() {
    // input
    ll N, X;
    cin >> N >> X;
    vl A(N);
    rep(i, N) cin >> A[i];

    // solve
    map<P, ll> m;
    ll ans = solve(A, m, X, 0);
    cout << ans << endl;
}