#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <vector>
#include <array>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <limits>
#include <numeric>
#include <iomanip>
#include <string>
#include <sstream>
using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define chmin(x, y) x = std::min(x, y)
#define chmax(x, y) x = std::max(x, y)
#define all(v) v.begin(), v.end()
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

template <typename T>
void dump(const vector<T>& v) {
	for (const T& n : v) {
		cout << n << " ";
	}
	cout << endl;
}

template <typename T>
void dump(const vector<vector<T>>& v) {
	for (const vector<T>& ns : v) {
		for (const T& n : ns) {
			cout << n << " ";
		}
		cout << endl;
	}
}

const int INF = (numeric_limits<int>::max)() / 2;
const ll INF_LL = (numeric_limits<ll>::max)() / 2;
const ll MOD = 1000000007;

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

	vector<P> a(n);
	rep(i, n) {
		cin >> a[i].first;
		a[i].second = i;
	}

	vector<vector<ll>> ls(n);
	rep(i, m) {
		ll x, y;
		cin >> x >> y;
		x--;
		y--;
		ls[y].push_back(x);
	}

	vector<ll> dp(n, INF_LL);

	for (int i = 1; i < n; i++) {
		for(ll j : ls[i]) {
			dp[i] = min({ dp[i], dp[j], a[j].first });
		}
	}

	ll ans = -INF_LL;
	rep(i, n) {
		chmax(ans, a[i].first - dp[i]);
	}
	cout << ans << endl;
}

int main() {
	int t = 1;
	while (t--) {
		solve();
	}
	return 0;
}

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

vector<vector<int>> t;
int ans=0;
int k;
int n;

void cal(int s,int cnt,vector<bool>ok,int sum){
  for(int i=1;i<n;++i){
    if(ok[i]==true || s==i)continue;
    //int tmp=sum;
    ok[i]=true;
    sum+=t[s][i];
    cal(i,cnt+1,ok,sum);
    ok[i]=false;
    sum-=t[s][i];
  }
  //cout << s << endl;
  if(cnt==n){
    //cout << s << endl;
    sum+=t[s][0];
    //cout << sum << endl;
    if(sum==k)ans++;
  }
  return;
}

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

  vector<bool> ok(n,false);

  ok[0]=true;

  int sum=0;

  cal(0,1,ok,sum);

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


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

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

typedef long long ll;

int main(){
    //input, initialize
    int a, b, c; cin >> a >> b >> c;
    if(a == b){
        cout << c << endl;
    } else if(b == c){
        cout << a << endl;
    } else if(c == a){
        cout << b << endl;
    } else{
        cout << 0 << endl;
    }
    //solve
    //output
}

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define LL_MAX LLONG_MAX

#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define lb(v,x) lower_bound(v.begin(),v.end(),x)

#define mod 1000000007
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}
int fac[1000009];int ncr_mod(int n,int k){int ans=fac[n];ans*=modinv(fac[k]);ans%=mod;ans*=modinv(fac[n-k]);ans%=mod;return ans;}

vector<int>v_prime;void Sieve(int n){bool prime[n + 1];memset(prime,true,sizeof(prime));for (int p = 2; p*p <=n;p++){if(prime[p] ==true) {for(int i = p*p; i<= n; i += p)prime[i]=false;}}for(int p = 2;p<= n;p++)if (prime[p])v_prime.pb(p);}
vector<int>v_factor;void factor(int n){ for (int i=1; i<=sqrt(n); i++) {if (n%i == 0) {if (n/i == i) v_factor.pb(i);else { v_factor.pb(i),v_factor.pb(n/i);};} } sort(all(v_factor)); }

int power(int x, int y){int temp;if( y == 0)return 1; temp = power(x, y / 2);if (y % 2 == 0) return temp * temp;else return x * temp * temp;}
int gcd(int a, int b){if (b == 0)return a; return gcd(b, a % b);}
int log2n( int n){ return (n > 1) ? 1 + log2n(n / 2) : 0;}

void out(vector<int>&a){for(int i=0;i<a.size();i++) cout<<a[i]<<" ";  cout<<endl;}
void sout(set<int>s){for(auto it=s.begin();it!=s.end();++it)cout<<*it<<" ";  cout<<endl;}
void mout(map<int,int>mm){for(auto it=mm.begin();it!=mm.end();++it) cout<<it->fi<<" "<<it->se<<endl;}

#define ms(a,x)  memset(a, x, sizeof(a));

#define decimal(n,k) cout<<fixed<<setprecision(k)<<n<<endl
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

// In binary search always report l-1

signed main()
{

      run;

/*
open for mod factorial

     fac[0]=1;
      for(int i=1;i<1000009;i++)
      {
          fac[i]=mul(fac[i-1],i);

      }
*/

/*
  for sieve open this and use v_prime

          int pp=pow(10,6)+100000;
               Sieve(pp);
*/

 // factor(n)  &&   USE v_factor For calculating factors && don't forget v_factor.clear();

int  t=1;

while(t--)
{
             //  map<int,int>mm; // it->second-->frequency

             int  n,i,x,y,ok=0,sum=0,ans=0,j,k,cnt=0,m,c=0,q,z;
             int  h[100009]={0};

                 n=3;

                 string s;
                //cin>>s;

            vector<int>a(n,0),v;

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

              sort(all(a));

              if(a[0]==a[1])
              {
                  cout<<a[2]<<endl;
              }
              else
              {
                  if(a[1]==a[2])
                    cout<<a[0]<<endl;
                    else
                    cout<<0<<endl;
              }

}
}


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

#define fi first
#define se second
#define rng(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); --i)
#define per(i, b) gnr(i, 0, b)
#define all(obj) begin(obj), end(obj)
#define allr(obj) rbegin(obj), rend(obj)
#define cinv(a) rep(i, (int)a.size()) cin >> a[i]
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<Pi> vp;
typedef vector<vp> vvp;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;

template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, 1, 0, -1};
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e15;
const long double eps = 1e-10;
const char nl = '\n';

ll power(ll a, ll b) { return b ? power(a * a % MOD, b / 2) * (b % 2 ? a : 1) % MOD : 1; }

ll nCk(int n, int k)
{
	ll x = 1, y = 1;
	for (int i = 1; i <= k; ++i)
	{
		x = x * (n - i + 1) % MOD;
		y = y * i % MOD;
	}
	return x * power(y, MOD - 2) % MOD;
}

struct UF
{
	vi d;
	UF(int n) : d(n, -1) {}
	int root(int x)
	{
		if (d[x] < 0)
			return x;
		return d[x] = root(d[x]);
	}
	bool unite(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (d[x] > d[y]) swap(x, y);
		d[x] += d[y];
		d[y] = x;
		return true;
	}
	bool same(int x, int y) { return root(x) == root(y); }
	int size(int x) { return -d[root(x)]; }
};

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	vi A(n); cinv(A);
	vvi mp(200);
	auto show = [](vi &vec) -> void {
		cout << sz(vec);
		for (int &i : vec) cout << " " << i;
		cout << nl;
	};
	n = min(n, 8);
	rng(bit, 1, 1<<n)
	{
		int a = 0;
		vi s;
		rep(i, n)
		{
			if (bit >> i & 1)
			{
				a += A[i];
				a %= 200;
				s.pb(i+1);
			}
		}
		if (sz(mp[a]) != 0)
		{
			cout << "Yes" << nl;
			show(mp[a]);
			show(s);
			return 0;
		}
		mp[a] = s;
	}
	cout << "No" << nl;
}

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

#define MAXN (int)(2 * 1e5 + 5)
#define MAXL 20
#define F first
#define S second
#define endl "\n"
#define MOD (lli)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
#define DEBUG if (0) cout << "aqui" << endl;
#define PI 2 * acos(0.0)
typedef pair<int, int> ii;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};

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

  int n;
  cin >> n;
  cout << max(0, n) << endl;

  return 0;
}


#include<iostream>
#include<map>
#include<vector>
using namespace std;
typedef long long li;
#define maximize(a,b) (a<(b)?a=(b),1:0)
#define rep(i,n) for(li i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
};

// pair 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const pair<T,S>& p){
  cout << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(){
  int n,m; cin >>n >>m;
  vector<pair<int,int>> cond(m);
  rep(i,m){
    int a,b; cin >>a >>b; a--; b--;
    cond[i]={a,b};
  }

  auto ts=[&](vector<int>& sara){
       int cnt=0;
       rep(i,m){
         int f=cond[i].first,s=cond[i].second;
         cnt+=sara[f]&sara[s];
       }
       return cnt;
     };

  int k ; cin >>k;
  vector<int> c(k),d(k);
  rep(i,k){
    int cc,dd; cin >>cc >>dd; cc--; dd--;
    c[i]=cc; d[i]=dd;
  }
  li lim=1LL<<k;
  int ans=0;
  rep(bs,lim){
    vector<int> sara(n,0);
    rep(i,k){
      if(bs&(1LL<<i)){
        sara[c[i]]|=1;
      }else{
        sara[d[i]]|=1;
      }
    }
    if(maximize(ans,ts(sara))){
      if(df)(print(sara,ans));
    }
  }

  print(ans);
}

#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

ll f[110],n;
int m;
vi ans,a;

int main()
{
    f[0]=1;f[1]=1;m=88;
    rep(i,2,m) f[i]=f[i-2]+f[i-1];
    //rep(i,1,10) cout << f[i] << " ";cout << endl;
    n=readll();
    per(i,m,1)
    {
        if (n>=f[i]) {n-=f[i];a.pb(i);}
    }
    int siz=a.size();
    int len=(a[0]+1)/2,pos=siz-1;
    //rep(i,0,siz-1) printf("%d ",a[i]);puts("");
    rep(i,1,len)
    {
        ans.pb(3);ans.pb(4);
        while ((pos>=0) && ((a[pos]+1)/2==i))
        {
            if (a[pos]&1) ans.pb(2);else ans.pb(1);pos--;
        }
    }
    len=ans.size();
    printf("%d\n",len);
    per(i,len-1,0) printf("%d\n",ans[i]);
    return 0;
}


#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
#define int long long
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}
#define fi first
#define se second
#define mkp make_pair
#define pb push_back
typedef pair<int,int>pii;
#define maxn 200005
int b,c;
inline int cross(int l1,int r1,int l2,int r2){
	if(l1>l2)swap(l1,l2),swap(r1,r2);
	//cout<<l1<<' '<<r1<<' '<<l2<<' '<<r2<<endl;
	if(l2<=r1)return max(r1,r2)-l1+1;
	return r2-l2+1+r1-l1+1;
}
signed main()
{
	b=read(),c=read();
	if(b>=0){
		int l1=-b-(c-1)/2,r1=-b+(c-1)/2;
		int l2=b-c/2,r2=b;
		if(c>2)r2=max(r2,b+(c-2)/2);
		cout<<cross(l1,r1,l2,r2);
	}else{
		int l1=b-c/2,r1=b+(c-2)/2;
		int l2=-b-(c-1)/2,r2=-b+(c-1)/2;
		cout<<cross(l1,r2,l2,r2);
	}
	return 0;
}

#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <unordered_map>
#include <math.h>
#define mod 1000000007
#define PI 3.141592653589

typedef long long ll;
const long long INF=1e18;
const long long inf=1e5 + 5;

using namespace std;

ll power(ll a, ll b)
{   ll result =1;
    while(b)
    {   if(b%2) result=(result*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return result;
}
void solve()
{
    ll n,i,j;
    ll sum=0;
    cin>>n;
    vector <ll> a(n);
    for(auto &x : a)
    {
        cin>>x;
        sum+=x;
    }
    //Bottom up approach check whether given sum can be made or not
    bool dp[n+1][sum+1];

    for(i=0;i<=n;i++) //if sum is 0 answer is true
    {
        dp[i][0]=true;
    }
    for(i=1;i<=sum;i++) //if sum>0 and set is empty
    {
        dp[0][i]=false;
    }
    //bottom up approach
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=sum;j++)
        {
            if(dp[i-1][j])
            {
                dp[i][j]=true;
            }
            else
            {
                if(j>=a[i-1] && dp[i-1][j-a[i-1]])
                {
                    dp[i][j]=true;
                }
                else
                {
                    dp[i][j]=false;
                }
            }
        }
    }
    ll init=(sum+1)/2;
    for(i=init;i<=sum;i++)
    {
        if(dp[n][i])
        {
            cout<<i;
            return;
        }
    }

}

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

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

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


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

const int K = 18;
const int N = 100005;
const int INF = 1e9;

int n, m;
vector<int> edges[N];
int k;
int c[K];

int dist[K][N];

void bfs(int u, int dist[]) {
  queue<int> q;
  for (int i = 0; i < n; ++i) dist[i] = -1;

  q.push(u);
  dist[u] = 0;
  while (q.size()) {
    int u = q.front();
    q.pop();

    for (int v : edges[u]) {
      if (dist[v] != -1) continue;
      dist[v] = dist[u] + 1;
      q.push(v);
    }
  }
}

int dp[K][1 << K];
int f(int x, int mask) {
  if ((mask + 1) == (1 << k)) return 0;
  if (~dp[x][mask]) return dp[x][mask];

  int ret = INF;
  for (int i = 0; i < k; ++i) {
    if (mask >> i & 1) continue;
    if (dist[x][c[i]] == -1) continue;
    ret = min(ret, dist[x][c[i]] + f(i, mask | 1 << i));
  }

  return dp[x][mask] = ret;
}

int solve() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    --u, --v;

    edges[u].push_back(v);
    edges[v].push_back(u);
  }

  scanf("%d", &k);
  for (int i = 0; i < k; ++i) {
    scanf("%d", &c[i]);
    --c[i];

    bfs(c[i], dist[i]);
  }

  memset(dp, -1, sizeof dp);

  int ans = INF;
  for (int i = 0; i < k; ++i) {
    ans = min(ans, 1 + f(i, 1 << i));
  }

  if (ans >= INF) ans = -1;
  printf("%d\n", ans);
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  for (int tc = 0; tc < t; ++tc) {
    solve();
  }
  return 0;
}

#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll n,m,k,c[maxn],d[25][25],dis[25][maxn],dp[25][maxn],vis[maxn],pos[maxn];
queue <int> q;
vector <int> mp[maxn];

inline void wk(int nw,int s)
{
	rep(i,1,n) vis[i]=0; vis[s]=1; dis[nw][s]=0; q.push(s);
	while(!q.empty())
	{
		int u=q.front(); q.pop();
		for(int i=0;i<mp[u].size();i++)
		{
			int v=mp[u][i]; if(vis[v]) continue;
			dis[nw][v]=dis[nw][u]+1;
			if(pos[v]) d[nw][pos[v]]=dis[nw][v];
			vis[v]=1; q.push(v);
		}
	}
}

int main()
{
	n=read(); m=read();
	rep(i,1,m)
	{
		int u=read(),v=read();
		mp[u].pb(v); mp[v].pb(u);
	}
	rep(i,1,20) rep(j,1,n) dis[i][j]=inf;
	k=read(); rep(i,1,k) c[i]=read(),pos[c[i]]=i;

	rep(i,1,k) rep(j,1,k) if(i!=j) d[i][j]=inf;
	rep(i,1,k) wk(i,c[i]);

	int ed=(1<<k)-1;
	rep(i,0,k) rep(j,0,ed) dp[i][j]=inf;

	dp[0][0]=0;
	rep(i,1,k) d[0][k]=1,d[k][0]=1;
	rep(i,1,k) dp[i][1<<(i-1)]=1;

	rep(i,1,ed)
	{
		rep(j,1,k)
		{
			if(i&(1<<(j-1)))
			{
				rep(K,1,k)
				{
					if(!(i&(1<<(K-1))))
						dp[K][i|(1<<(K-1))]=min(dp[K][i|(1<<(K-1))],dp[j][i]+d[j][K]);
				}
			}
		}
	}

	ll ans=inf;
	rep(i,1,k) ans=min(ans,dp[i][ed]);
	if(ans==inf) puts("-1");
	else cout<<ans<<endl;

	return 0;
}


#include<stdio.h>
#include<math.h>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
int main(){
	ll N;
	scanf("%lld",&N);
	vector<ll> a(N);
	for(ll i = 0; i < N; i++) scanf("%lld",&a.at(i));
	sort(a.begin(),a.end());
	for(ll i = 0; i < N - 1; i++){
		if(a.at(i) == a.at(i + 1)){
			a.erase(a.begin() + i);
			N--;
			i--;
		}
	}
	ll b = a.at(0);
	if(N == 1) printf("%lld\n",a.at(0));
	else {
		ll c = a.at(1);
		vector<pair<ll,bool>> lcd;
		pair<ll,bool>p;
		for(ll i = 1; i < sqrt(a.at(0)); i++){
			if(b % i == 0){
				if(c % i == 0){
					p.first = i;
					p.second = true;
					lcd.push_back(p);
				}
				if(c % (b / i) == 0){
					p.first = b / i;
					p.second = true;
					lcd.push_back(p);
				}
			}
		}
		sort(lcd.begin(),lcd.end());
		for(ll i = 0; i < lcd.size(); i++){
			for(ll j = 0; j < N; j++){
				if(a.at(j) % lcd.at(i).first){
					lcd.at(i).second = false;
				       	break;
				}
			}
		}
		for(ll i = lcd.size() - 1; i > -1; i--){
			if(lcd.at(i).second) {
				printf("%lld\n",lcd.at(i).first);
				break;
			}
		}
	}
	return 0;
}

#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;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

pll operator+(pll a,pll b){
  return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
  return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
  return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

void solve(long long N, std::vector<long long> a){
  ll ans=a[0];
  REP(N){
    ans=gcd(ans,a[i]);
  }
  cout<<ans<<endl;
}

int main(){
  cout<<setprecision(1000);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


#include <cstdio>

using namespace std;

const int mod = 998244353;
int a[50][50];
int par[100];
int cnt[100];
long long fact[51];

int find(int x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);

    if (x == y) return;

    par[x] = y;
}

int main() {
    int n, k, i, j, l;
    long long ans = 1;

    scanf("%d %d", &n, &k);

    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            scanf("%d", &a[i][j]);
        }
    }

    for (i = 0; i < n * 2; i++) par[i] = i;

    for (i = 0; i < n; i++) {
        for (j = i + 1; j < n; j++) {
            for (l = 0; l < n; l++) {
                if (a[i][l] + a[j][l] > k) break;
            }

            if (l == n) unite(i, j);

            for (l = 0; l < n; l++) {
                if (a[l][i] + a[l][j] > k) break;
            }

            if (l == n) unite(n + i, n + j);
        }
    }

    for (i = 0; i < n * 2; i++) cnt[find(i)]++;

    fact[0] = 1;
    for (i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;

    for (i = 0; i < n * 2; i++) ans = ans * fact[cnt[i]] % mod;

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

    return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 998244353
#define PI 3.14159265358979323846
#define INF 1 << 30

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

class UnionFind {
private:
	vector<int> p, n;

public:
	UnionFind(int num) {
		p.resize(num + 1);
		n.resize(num + 1);
		fill(n.begin(), n.end(), 1);
		for (int i = 0; i < p.size(); i++)
			p[i] = i;
	}

	int Parent(int n) {
		if (p[n] == n)
			return n;
		return p[n] = Parent(p[n]);
	}

	void Union(int a, int b) {
		a = Parent(a);
		b = Parent(b);
		if (a == b)
			return;
		p[a] = b;
		n[b] += n[a];
		return;
	}

	int Same(int a, int b) {
		return Parent(a) == Parent(b);
	}

	int Size(int a) {
		return n[Parent(a)];
	}
};

// d[n] = n! の配列初期化
void Ini_fact(vector<ll>& d) {
	d[1] = 1;
	for (ll i = 2; i < d.size(); i++)
		d[i] = d[i - 1] * i % MOD;
	return;
}

int main(void) {
	int num, k, i, j, s, t;
	ll ans = 1, a = 0, b = 0;
	cin >> num >> k;
	vector<ll> kai(num + 10);
	vector<vector<int>> d(num, vector<int>(num));
	UnionFind x(num), y(num);
	Ini_fact(kai);
	rep(i, num) {
		rep(j, num)
			cin >> d[i][j];
	}
	rep(s, num) {
		for (t = s + 1; t < num; t++) {
			int ok1 = 1, ok2 = 1;
			rep(i, num) {
				if (d[s][i] + d[t][i] > k) {
					ok1 = 0;
				}
				if (d[i][s] + d[i][t] > k) {
					ok2 = 0;
				}
			}
			if (ok1)
				x.Union(s, t);
			if (ok2)
				y.Union(s, t);
		}
	}
	rep(i, num) {
		if (i == x.Parent(i)) {
			ans *= kai[x.Size(i)];
		}
		if (i == y.Parent(i)) {
			ans *= kai[y.Size(i)];
		}
		ans %= MOD;
	}
	cout << ans << "\n";
	return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}

const ll INF=1e18;
const int mx=200005;
//abc192

int main(){
    //オーバーフローは大丈夫ですか？？
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    ll ans=n;
    rep(i,k){
        ll tmp=ans;
        string s=to_string(tmp);
        string t=s;
        string u=s;
        sort(all(t));
        sort(all(u));
        reverse(all(u));
        ans=stoll(u)-stoll(t);
    }
    out(ans);
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！

//  /Applications/Geany.app/Contents/MacOS/geany
#include<bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define pairii pair<int,int>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()

const int NUM=1000030;
const int N = 10000000;
vector<int> lp, sieve;
vector<int> pr;
void primefactor();
int binpow(int a, int b);
int binpow(int a, int b, int mod);
int gcd(int a, int b);
int lcm (int a, int b);
bool comp(int a, int b);
int inversemod(int a, int mod);
void calc_sieve();

string getstring(int n)
{
	string s;
	while(n>0)
	{
		s.pb('0'+n%10);
		n/=10;
	}
	sort(all(s));
	return s;
}

int getnum(string s)
{
	//reverse(all(s));
	int ans=0;
	for(int i=0;i<s.size();i++)
	{
		ans=ans*10+s[i]-'0';
	}
	return ans;
}

void test()
{
	int n,k,i,j;
	cin>>n>>k;

	for(i=1;i<=k;i++)
	{
		string s=getstring(n);
		string s1=s;
		reverse(all(s1));

		n=getnum(s1)-getnum(s);
	}

	cout<<n<<endl;

}

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

void calc_sieve() //credits: Anish_Sofat
{
	sieve.resize(NUM+1,0);
	for (int x = 2; x <= NUM; x++)
    	{
        	if (sieve[x]) continue;
        	for (int u = x; u <= NUM; u += x)
        	{
            		sieve[u] = x ;
        	}
    	}
}

void primefactor()
{
	lp.resize(N+1,0);
	for (int i=2; i<=N; ++i) {
		if (lp[i] == 0) {
			lp[i] = i;
			pr.push_back (i);
		}
		for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
			lp[i * pr[j]] = pr[j];
	}
}

int binpow(int a, int b)
{
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int binpow(int a, int b, int mod)
{
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res%mod;
}

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

int lcm (int a, int b)
{
    return ((a / gcd(a, b)) * b);
}

bool comp(int a, int b)
{
	return a>b;
}

int inversemod(int a, int mod)
{
	return binpow(a,mod-2, mod);
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    string enc = "BWR";
    int N; cin >> N;
    string S; cin >> S;
    VL A(N);
    REP(i,N){
        int a = -1;
        if(S[i] == 'B') a = 0;
        if(S[i] == 'W') a = 1;
        if(S[i] == 'R') a = 2;

        A[i] = a;
    }
    VL f(N+1); // f[x]: x!を3で何回割れるか
    VL g(N+1); // g[x]: g!を3で割り切れなくなるまで割ったとき、残った整数を3で割った余り
    f[0] = 0;
    g[0] = 1;
    FOR(i,1,N+1){
        int x = i;
        int cnt = 0;
        while(x % 3 == 0){
            x /= 3;
            cnt++;
        }
        f[i] = f[i-1] + cnt;
    }

    FOR(i,1,N+1){
        int x = i;
        while(x % 3 == 0){
            x /= 3;
        }
        g[i] = (g[i-1] * (x % 3) ) % 3;
    }

    LL ans = 0;
    REP(i,N){
        LL nCi = -1;
        if(f[N-1] - f[i] - f[(N-1)-i] > 0){
            nCi = 0;
        }else{
            if(g[N-1] == 1 && g[i] * g[N-1-i] == 1) nCi = 1;
            if(g[N-1] == 1 && g[i] * g[N-1-i] == 2) nCi = 2;
            if(g[N-1] == 1 && g[i] * g[N-1-i] == 4) nCi = 1;
            if(g[N-1] == 2 && g[i] * g[N-1-i] == 1) nCi = 2;
            if(g[N-1] == 2 && g[i] * g[N-1-i] == 2) nCi = 1;
            if(g[N-1] == 2 && g[i] * g[N-1-i] == 4) nCi = 2;
        }

        ans += nCi * A[i];
        ans %= 3;
    }
    if(N%2 == 0){
        ans = (-ans+3) % 3;
    }

    cout << enc[ans] << endl;

}

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

const int f[3][3] = {
    {1, 0, 0},
    {1, 1, 0},
    {1, 2, 1}
};
const int mod = 3;

int lucas(int x, int y) {
    int res = 1;
    while (x) {
        res = res * f[x % mod][y % mod] % mod;
        x /= mod, y /= mod;
    }
    return res;
}

int mp[200];
void solve() {
    mp['B'] = 0, mp['W'] = 1, mp['R'] = 2;
    int n, res = 0; cin >> n; --n;
    for (int i = 0; i <= n; ++i) {
        char c; cin >> c;
        int x = mp[c];
        res = (res + lucas(n, i) * x) % mod;
    }
    if (n & 1) res = -res;
    res = (res + mod) % mod;
    if (res == 0) putchar('B');
    if (res == 1) putchar('W');
    if (res == 2) putchar('R');
}

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


/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#ifdef ONLINE_JUDGE
#define debug(x)
#define debug2(x, y)
#define debug3(x, y, z)
#define dbg(v)
#else
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
#endif

// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

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

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

// End of template.

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

    int n, k;
    cin >> n >> k;
    vector<int64> a(n, 0), m(n, 0);
    rep(i, n) {
        int a0;
        cin >> a0;
        a[a0] += 1;
    }

    m[0] = a[0];
    rep(i, n - 1) m[i + 1] = min(m[i], a[i + 1]);

    int64 ans = 0;
    int c = 0;
    for (int i = n - 1; i >= 0 && k > 0;) {
        if (m[i] > c) {
            ans += i + 1;
            k--;
            c++;
        } else {
            i--;
        }
    }

    print(ans);

    return 0;
}

/*
 _
| |__   ___ _ __  _ __
| '_ \ / __| '_ \| '_ \
| |_) | (__| |_) | |_) |
|_.__(_)___| .__/| .__/
           |_|   |_|
*/

#include<bits/stdc++.h>
using namespace std;
#define int long long
int cnt[300005],k,n;
signed main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
	    int x;
	    cin>>x;
	    cnt[x]++;
	}
	int ans=0;
	for(int i=0;i<n;i++){
	    if(cnt[i]<k){
	        ans+=i*(k-cnt[i]);
	        k=cnt[i];
	    }
	}
	cout<<ans<<endl;
}


//int a = s - '0'; 文字から数字
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
#define PI 3.14159265358979323846264338327950L
using namespace std;

//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

ll RS(ll N, ll P, ll M) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RS(N, P / 2, M);
		return t * t % M;
	}
	return N * RS(N, P - 1, M);
}

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

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

	ll ans = 1e10;
	int flag = 0;
	rep(i,N){
		if(X[i] - A[i] >= 1){
			ans = min(P[i],ans);
			flag = 1;
		}
	}

	if(flag == 1) cout << ans << endl;
	else cout << -1 << endl;
}

#include <iostream>
using namespace std;
const int INF = 0x3fffffff;
void chmin(int& a, int b){ if(a > b) a = b; }
int main(){
    int N;
    cin >> N;
    int ans = INF;
    for(int i = 0; i < N; i++){
        int A, P, X;
        cin >> A >> P >> X;
        if(X > A) chmin(ans, P);
    }
    if(ans == INF) ans = -1;
    cout << ans << endl;
}


#ifdef LOCAL
#pragma warning(disable:4996)
#pragma warning(disable:4244)
#pragma warning(disable:4554)
#define gets gets_s

#endif
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<stack>
#include<queue>
#include<cmath>
#include<vector>
#include<string>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<assert.h>
#include<unordered_map>
#include<ctime>
#define ll long long
#define cl(a,x) memset((a),(x),sizeof(a))
#define lson 2*i
#define rson 2*i+1
#define sf scanf
#define ull unsigned long long
#define lowbit(x) (x)&(-x)
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define ti tree[i]
#define mp make_pair
#define debug cerr <<"flag" << endl;
ll q_pow(ll x, ll n, ll mod) { ll ret = 1; while (n) { if (n & 1) ret = x * ret%mod; x = x * x%mod; n >>= 1; }return ret; }
ll __gcd(ll x, ll y) { if (!y) return x; return __gcd(y, x%y); }
ll getbit(ll now) { int cnt = 0; while (now) { cnt++; now -= lowbit(now); }return cnt; }
int dx[] = { -1,1,0,0 };//上下左右
int dy[] = { 0,0,-1,1 };//
using namespace std;
const ll maxn = 2e5 + 10;
const ll INF = 0x3f3f3f3f;
const ll IINF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
const int mod = 1e9 + 7;

int dp[maxn];
char s[maxn];

void solve() {
	sf("%s", s + 1);
	int n = strlen(s + 1);

	int cnt = n;
	ll ans = 0;
	int last = -INF;
	for (int i = 1; i <= n; i++) {
		if (s[i] == s[i + 1] and s[i] != s[i + 2] and last != s[i]) {
			if (last != s[i]) ans += n - i, last = s[i];
		}
		else if (last == s[i]) ans--;
	}

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

signed main(int argc, char *argv[]) {
	if (argc == 2 && strcmp("-debug", argv[1]) == 0) {
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	}

	int t = 1;
	///cin >> t;

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

	return 0;
}

#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define pb push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
const int MOD = 1000000007;
#define PI = acos(-1)
using namespace std ;
signed main(){
   fastio ;
   int n ;
   cin >> n ;
   vector<int> v ;
   for(int i  = 0 ; i < 61 ; i++){
   	    v.pb(1LL << i);
   }
   //for(auto x : v) cout << x << endl;
   int ans = 1e18;
   for(auto x : v){
   	   int b = x ;
   	   int c = n%b ;
   	   int a = (n - c)/b ;
   	   ans = min(ans , a + (int)log2(b) + c);
   }
   cout << ans ;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ui unsigned int
#define ull unsigned ll
#define foi(n) for(ll i=0;i<n;i++)
#define foj(n) for(ll j=0;j<n;j++)
#define fok(n) for(ll k=0;k<n;k++)
#pragma GCC optimize("O3", "unroll-loops")
#define fixed(); cout << fixed << setprecision(20);
#define fast(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

/*****************************************************************************/

#define graph          vector<vector<int>>
#define V              vector
typedef pair<int, int> pii;
typedef pair<ll, ll>   pll;
typedef V<int>         vi;
typedef V<ll>          vll;
typedef V<string>      vs;
typedef V<double>      vd;
typedef V<pii>         vpii;
typedef V<pll>         vpll;
typedef pair<int,pii>  piii;
typedef priority_queue<pii, vector<pii>, greater<pii> > pqq;

/*****************************************************************************/

#define mp                   make_pair
#define eb                   emplace_back
#define pb                   push_back
#define pf                   push_front
#define popb                 pop_back
#define popf                 pop_front
#define hashmap              unordered_map
#define hashset              unordered_set
#define lb                   lower_bound
#define ub                   upper_bound
#define all(a)               (a).begin(), (a).end()
#define rall(a)              (a).rbegin(), (a).rend()
#define ff                   first
#define ss                   second
#define lbpos(v,x)           (int)(lower_bound(all(v),x)-v.begin())//=v.size()==>No LB
#define ubpos(v,x)           (int)(upper_bound(all(v),x)-v.begin())//=v.size()==>No UB

/*****************************************************************************/

//for declaring most used global variables and constants
ll mod=1e9+7;

//for string with space use std::getline(cin,string_name);
//*****************UVAISH ZAFRI(Rush_For_AC)**********************

int32_t main() {
  fast(); fixed();
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif

      ll a[4];
      bool is=false;
      foi(4) cin>>a[i];
      for(ll i=0;i<=15;i++){
        ll od=0,ev=0;
        foj(4) if(i&1<<j) od+=a[j];
        else ev+=a[j];
        if(ev==od) is=true;
      }

    if(is) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define op1 freopen("C:\\acm\\Cproj\\in.txt","r",stdin);
#define pr freopen("C:\\acm\\Cproj\\out.txt","w",stdout)
#define pr2 freopen("C:\\acm\\Cproj\\std.txt","w",stdout)
#define pii pair<int,int>
#define Please return
#define AC 0
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
template <class T>
void read(T &val) { T x = 0; T bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int mod=998244353;
const int maxn = 1e6+10;

int n,m,a[maxn],q,t;
char s[maxn];

int main(){
    read(t);
    while(t--){
        read(n);
        fo(i,1,n) read(a[i]);
        if(n==1) {
            puts("Second");
        }
        else if(n&1){
            puts("Second");
        }
        else{
            unordered_map<int,int>mpp;
            fo(i,1,n) mpp[a[i]]++;
            int same = 1;
            for(auto to:mpp) if(to.second&1) same = 0;

            if(same) puts("Second");
            else puts("First");
        }
    }
    Please AC;
}


#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template <typename T>
bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int n = 50;
const int vi[] = {0, 1, 0, -1};
const int vj[] = {1, 0, -1, 0};
chrono::steady_clock::time_point sTime;
char vtoc(int v) {
	string s = "RDLU";
	return s[v];
}
void mainSolve(string &ans, int si, int sj, const vector<vector<int>> &t, const vector<vector<int>> &p) {
	mt19937 mt(04252021);
	uniform_int_distribution<int> rdV(0, 3);
	const int TL = 2 * 1000 - 25;
	auto passTime = [&]() {
		return chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - sTime).count();
	};
	auto passTimeNow = passTime();
	int bestScore = 0;
	while (passTimeNow < TL) {
		passTimeNow = passTime();
		string tans;
		int ni = si, nj = sj;
		set<int> visit = {t[ni][nj]};
		int score = p[ni][nj];
		for (int tt = 0; tt < 1000; tt++) {
			int v = rdV(mt);
			int ei = ni + vi[v], ej = nj + vj[v];
			if (0 > ej || ej >= n || 0 > ei || ei >= n) continue;
			if (!visit.count(t[ei][ej])) {
				ni = ei, nj = ej;
				score += p[ei][ej];
				tans += vtoc(v);
				visit.insert(t[ei][ej]);
			}
		}
		if (chmax(bestScore, score)) {
			ans = tans;
		}
	}
}
int main() {
	sTime = chrono::steady_clock::now();
	int si, sj;
	cin >> si >> sj;
	vector<vector<int>> t(n, vector<int>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> t[i][j];
		}
	}
	vector<vector<int>> p(n, vector<int>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> p[i][j];
		}
	}
	string ans;
	mainSolve(ans, si, sj, t, p);
	cout << ans << endl;
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> x(N);
  vector<int> y(N);
  for(int i=0;i<N;i++){
    cin >> x.at(i);
    cin >> y.at(i);
  }

  int num = 0;
  float delx = 0;
  float dely = 0;
  for(int j=0;j<N;j++){
    for(int k=j+1;k<N;k++){
      dely = y.at(j) - y.at(k);
      delx = x.at(j) - x.at(k);
      if((dely / delx )>=-1){
        if((dely / delx )<=1){
          num ++;
        }
      }
    }
  }
  cout << num;
}

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;

int64_t solve(int n, const std::vector<int64_t> &a) {
    int64_t ans = 0;
    int64_t b = 0;
    map<int64_t, int> c;
    c[0] += 1;
    REP (i, n) {
        b += (i % 2 == 0 ? a[i] : - a[i]);
        ans += (c.count(b) ? c[b] : 0);
        c[b] += 1;
    }
    return ans;
}

// generated by oj-template v4.8.0 (https://github.com/online-judge-tools/template-generator)
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N;
    std::cin >> N;
    std::vector<int64_t> A(N);
    REP (i, N) { std::cin >> A[i]; }
    auto ans = solve(N, A);
    std::cout << ans << '\n';
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

/**************************************************/
#define int long long
#define fr(i,st,c)          for(int i=st;i<c;i++)
#define rfr(i,e,c)          for(int i=e;i>=c;i--)
#define i_output(f1)        cout<<(f1?"YES":"NO")<<endl;
#define vi                  vector<int>
#define pb                  push_back
#define print(n)            cout<<n<<endl
#define thor                ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define N                   1e9+7

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

/***************************************************/

signed main(){

    thor

    double a,b;
    cin>>a>>b;

    double ans=((a - b)/ a )*100;

    cout<<setprecision(20)<<ans<<endl;

    return 0;
}

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

const ll MOD = 998244353; //10^9+7:合同式の法

int main(){
  ll H, W, p, ans, i, j,last;
  cin >> H >> W;
  vector<string> S(H);
  for(string &s : S) {
    cin >> s;
  }
  ans=1;i=0;j=0;last=0;
  while(true){
    p=-1;
    ll now=i;j=0;
    while(now>=0){
      //cout<<now<<" "<<j<<endl;
      if(now>=H||j>=W){j++;now--;continue;}
      if(now==H-1&&j==W-1){last=-1;}
      if(p==-1){
        if(S[now][j]=='R'){p=1;}
        else if(S[now][j]=='B'){p=2;}
      }else{
        if(S[now][j]=='R'&&p==2){p=0;}
        else if(S[now][j]=='B'&&p==1){p=0;}
      }
      if(last==-1){break;}
      j++;now--;
    }
    if(p==-1){
      ans*=2;
      ans=ans%MOD;
    }else if(p==0){
      ans=0;break;
    }
    if(last==-1){break;}
      //cout<<i<<" "<<ans<<endl;
    i++;
  }
  cout<<ans<<endl;
}


#include<iostream>
using namespace std;

int main(void){
    int N;
    cin>>N;
    int A[N];
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    int k,gcd=0;
    for(int i=2;i<=1000;i++){
        int gcd2=0;
        for(int j=0;j<N;j++){
            if(A[j]%i==0){
                gcd2++;
            }
        }
        if(gcd2>gcd){
            gcd=gcd2;
            k=i;
        }
    }
    cout<<k<<endl;
    return 0;
}

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

int main()
{

    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    vector<ll> gcdd(1000);
    rep(i, n)
    {
        rep(j, 1000)
        {
            if (a[i] % (j + 1) == 0 && (j + 1) <= a[i])
                gcdd[j]++;
        }
    }
    gcdd[0] = 0;
    ll maxid = 0;
    ll maxval = 0;
    rep(i, 1000)
    {
        maxval = max(maxval, gcdd[i]);
        if (maxval == gcdd[i])
            maxid = i + 1;
    }
    cout << maxid;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n);  for(auto& a : v) init(a, x, m...); }
int n;
vector<ll> a, b;
map<pair<ll, int>, ll> H;
ll cc(ll x, ll q){
    if (x>=0) return (x+q-1)/q;
    else return x/q;
}
ll ff(ll x, ll q){
    if (x>=0) return x/q;
    else return (x-q+1)/q;
}
ll solve(ll x, int i){
    auto key = make_pair(x, i);
    if (H.count(key))
        return H[key];

    if (abs(x) > b[i])
        return 0;
    if (i==0)
        return abs(x) <= b[0];
    ll ret = 0;
    ret += solve(x, i-1);
    //-b[i-1] <= x + q * a[i] <= b[i-1]
    ll q1 = cc(-b[i - 1] - x, a[i]);
    ll q2 = ff(b[i - 1] - x, a[i]);
    ll lim = 1e18;
    if (i+1 < n)
        lim = a[i+1] / a[i];
    if (q1 == q2 && abs(q1) < lim && q1)
        ret += solve(x + q1 * a[i], i - 1);
    else if (q1 < q2) {
        if (q1 && abs(q1) < lim)
            ret += solve(x + q1 * a[i], i - 1);
        if (q2 && abs(q2) < lim)
            ret += solve(x + q2 * a[i], i - 1);
    }
//    cout << x << " " << i << " " << ret << endl;
    return H[key] = ret;
}

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    ll x;
    cin >> n >> x;
    a.resize(n); b.resize(n);
    FOR(i, n) cin >> a[i];
    FOR(i, n-1) b[i] = a[i+1]-1;
    b[n-1] = 1e18;
    cout << solve(x, n-1) << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

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

using ll  = long long;
using ull = unsigned long long;
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=int(a);i<=(int)(b);i++)
#define per(i,a,b) for(int i=int(a);i>=(int)(b);i--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod  = 1e9+7;
const int inf  = 0x3f3f3f3f;
const int maxn = 1e5+10;
struct edge {
    int to;
    ll c,d;
};
int main() {
#ifndef WA_DEBUG
    ios::sync_with_stdio(false);cin.tie(nullptr);
#endif
    int n,m;
    cin>>n>>m;
    vector<vector<edge>> g(n+1);
    rep(i,1,m) {
        int a,b;
        ll c,d;
        cin>>a>>b>>c>>d;
        g[a].pb({b,c,d});
        g[b].pb({a,c,d});
    }
    auto gett=[&](ll x) {
        if(x==0) return 1ll;
        ll tmp=sqrt(x);
        while(tmp*(tmp+1)<=x) tmp++;
        return tmp;
    };
    vector<ll> dis(n+1,ll(1e18));
    dis[1]=0;
    priority_queue<pair<ll,int>> q;
    q.push({0,1});
    while(!q.empty()) {
        auto now=q.top();q.pop();
        now.fi=-now.fi;
        if(now.fi!=dis[now.se]) continue;
        for(auto x:g[now.se]) {
            ll t=gett(x.d),val;
            if(now.fi+1<t) val=t-1+x.c+x.d/t;
            else val=now.fi+x.c+x.d/(now.fi+1);
            if(dis[x.to]>val) {
                dis[x.to]=val;
                q.push({-val,x.to});
            }
        }
    }
    if(dis[n]>9e17) cout<<-1<<'\n';
    else cout<<dis[n]<<'\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  int D = abs(r1-r2) + abs(c1-c2);
  int64_t Ap = r1 + c1;
  int64_t Am = r1 - c1;
  int64_t Bp = r2 + c2;
  int64_t Bm = r2 - c2;
  //0回
  if(r1 == r2 && c1 == c2){
    cout << 0 << endl;
    return 0;
  }
  //1回？
  if(Ap == Bp || Am == Bm){
    cout << 1 << endl;
    return 0;
  }
  if(D <= 3){
    cout << 1 << endl;
    return 0;
  }
  //2回？
  for(int i=-3; i<=3; i++){
    for(int j=-3; j<=3; j++){
      if(abs(i) + abs(j) > 3){
        continue;
      }
      if(Ap == Bp + i + j || Am == Bm + i + j){
        cout << 2 << endl;
        return 0;
      }
    }
  }
  if(Ap %2 == Bp %2){
    cout << 2 << endl;
    return 0;
  }
  if(D <= 6){
    cout << 2 << endl;
    return 0;
  }
  //3回
  cout << 3 << endl;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll LINF = 1e18;
template <class T>
void get_unique(vector<T>& x) {
    x.erase(unique(x.begin(), x.end()), x.end());
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (int i = 0; i < int(v.size()); i++) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (int i = 0; i < int(v.size()); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << ' ';
    }
    return os;
}
int main() {
    int n;
    ll w;
    cin >> n >> w;
    vector<ll> v(200200);
    rep(i, n) {
        int s, t;
        ll p;
        cin >> s >> t >> p;
        v[s] += p;
        v[t] -= p;
    }
    rep(i, 200200 - 1) v[i + 1] += v[i];
    if (*max_element(all(v)) <= w)
        cout << "Yes\n";
    else
        cout << "No\n";
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = ll(998244353);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (b) - 1; (i) >= (a); --(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

int multipf(vector<string>& s){
    cout << s[0];
    rep1(i, s.size() - 1)cout << " " << s[i];
    cout << endl;
    return 0;
}

int multipf(vector<ll>& n){
    cout << n[0];
    rep1(i, n.size() - 1)cout << " " << n[i];
    cout << endl;
    return 0;
}

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

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

//modの値の確認をすること
int main(){
    vl a(4);
    rep0(i, 4)cin >> a[i];
    sort(all(a));
    if(a[0] + a[1] + a[2] == a[3] || a[0] + a[3] == a[1] + a[2])yes;
    else no;
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define pb push_back
#define B begin()
#define E end()
#define F first
#define S second
#define loop(z, v) for(auto &z: v)
#define nl "\n"
#define fat 1000000007

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

    vi a(n - 1);
    loop(z, a) cin >> z;

    ll sum = accumulate(a.B, a.E, 0);

    int ans = m*n - sum;
    if(ans < 0) cout << 0 << nl;
    else if(ans <= k) cout << ans << nl;
    else cout << -1 << nl;
    return 0;
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>

#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}

template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}

struct solve
{
	solve(){}
	ll operator()() {
		return 0;
	}
};

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

	for(;;)
	{
		int n;
		cin >> n;
		if(cin.fail()) break;
		vi a(n);
		for(auto&m:a) cin >> m;
		for(;;)
		{
			n=a.size();
			sort(a.begin(), a.end());

			int a_min=a[0];
			int a_max=a.back();
			if(a_min==a_max) break;
			vi t;
			t.push_back(a[0]);
			for(int i=1;i<n;i++)
			{
				if(a[i]!=a[i-1])
				{
					if(a[i]%a_min) t.push_back(a[i]%a_min);
				}
			}
/*
for(auto&m:t) cout << m << " ";
cout << "\n";
*/
			a.swap(t);
		}
		cout << a[0] << "\n";
	}
	return 0;
}

#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

int n,a[100010];

int main(){
	n=read();
	For(i,1,n) a[i]=read();
	int ans=a[1];
	For(i,2,n) ans=__gcd(a[i],ans);
	printf("%d\n",ans);
}


/* � Ashiq Uddin Pranto
   Department of Computer Science and Engineering
   BATCH 27
   University Of Rajshahi,Bangladesh
*/
#include<bits/stdc++.h>

#define ll long long
#define ld long double
#define FOR(x,y) for(ll i=x;i<=y;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define matrix(x) vector<vector<x>>
#define vss vector<string>
#define PI (2*acos(0.0))
#define sqr(x) ((x)*(x))
#define sf(a)   scanf("%d",&a)
#define sfl(a)  scanf("%lld",&a)
#define sff(a,b)    scanf("%d %d",&a,&b)
#define sffl(a,b)   scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
#define ms(a,b) memset(a, b, sizeof(a))
#define ff  first
#define ss  second
#define lcm(a, b)   ((a)*((b)/__gcd(a,b)))
#define all(a)  a.begin(),a.end()
#define readfile freopen("input.txt","r",stdin);
#define writefile freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define gap " "
#define mx 104
#define inf (ll)1e9
#define WHITE 1
#define GRAY 2
#define BLACK 3
#define EMPTY_VALUE -1
#define mod 1000000007
#define MOD(a,b) (a%b + b)%b

using namespace std;

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

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

void eff()
{
    ll a,b,x,y;
    sffl(a,b);
    sffl(x,y);
    ll ans = 0;
    if(a==b)
    {
        ans = x;
        printf("%lld\n",ans);
        return ;
    }
    ans = inf;
    ll temp;
    temp = abs(a-b)*y;
    temp+=x;
    ans = min(ans,temp);
    if(a>b)
    {
        temp = abs(a-b)*2*x;
        temp -= x;
        ans = min(ans,temp);
        temp = abs(a-b)*2*x;
        temp-=x*2;
        temp+=y;
        ans = min(ans,temp);
        temp = abs(a-b)*y;
        temp+=x;
        ans = min(ans,temp);
        temp = (abs(a-b)-1)*y;
        temp+=x;
        ans = min(ans,temp);
    }
    else
    {
        temp = abs(a-b)*2*x;
        temp+=x;
        ans = min(ans,temp);
        temp = abs(a-b)*y;
        temp+=x;
        ans = min(ans,temp);

    }

    // if((x*2)<y){
    //     if(a>b)
    //     {
    //         ans = abs(a-b)*2*x;
    //         ans-=x;
    //     }
    //     else
    //     {
    //         ans = abs(a-b)*2*x;
    //         ans+=x;
    //     }

    // }
    // else
    // {
    //     ans = abs(a-b)*y;
    //     ans+=x;
    // }
    printf("%lld\n",ans);
    return ;
}

int main()
{
    //fastio
    // ll test ;
    // sfl(test);
    // for(ll i=0;i<test;i++)
    // {
        // printf("Case %lld: ",i+1);
        eff();
    // }
//    cout<<check(81);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define repl(i, a, b) for(int i = a; i < int(b); i++)
#define rep(i, n) repl(i, 0, n)
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int turn = c;
    while(1) {
        if(turn == 0) {
            if(a > 0) {
                a--;
            } else {
                cout << "Aoki\n";
                return 0;
            }
        } else {
            if(b > 0) {
                b--;
            } else {
                cout << "Takahashi\n";
                return 0;
            }
        }
        turn = 1 - turn;
    }
}


#include <stdio.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <algorithm>
using namespace std;

//check if points are collinear or not
bool check_collinear(int x1, int y1, int x2, int y2, int x3, int y3){
    int a = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2);
    if (a == 0)
        return true;
    else
        return false;
}
bool solve(string n, int l)
{

    // Less than three digit number
    // can be checked directly.
    if (l < 3) {
        if (stoi(n) % 8 == 0)
            return true;

        // check for the reverse of a number
        reverse(n.begin(), n.end());
        if (stoi(n) % 8 == 0)
            return true;
        return false;
    }

    // Stores the Frequency of characters in the n.
    int hash[10] = { 0 };
    for (int i = 0; i < l; i++)
        hash[n[i] - '0']++;

    for (int i = 104; i < 1000; i += 8) {

        int dup = i;

        int freq[10] = { 0 };
        freq[dup % 10]++;
        dup = dup / 10;
        freq[dup % 10]++;
        dup = dup / 10;
        freq[dup % 10]++;

        dup = i;

        if (freq[dup % 10] > hash[dup % 10])
            continue;
        dup = dup / 10;

        if (freq[dup % 10] > hash[dup % 10])
            continue;
        dup = dup / 10;

        if (freq[dup % 10] > hash[dup % 10])
            continue;

        return true;
    }

    // when all are checked its not possible
    return false;
}

int main(){
    string number;
    getline(cin, number);
    int l = number.length();

    if (solve(number, l))
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

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

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

  string S; cin >> S;

  string ans = "No";
  vector<ll> d(10, 0);
  for (ll i = 0; i < S.size(); i++) {
    d[S[i] - '0']++;
  }

  if (S.size() == 1) {
    if (S[0] == '8') ans = "Yes";

  } else if (S.size() == 2) {
    if (S == "16") ans = "Yes";
    if (S == "24") ans = "Yes";
    if (S == "32") ans = "Yes";
    if (S == "48") ans = "Yes";
    if (S == "56") ans = "Yes";
    if (S == "64") ans = "Yes";
    if (S == "72") ans = "Yes";
    if (S == "88") ans = "Yes";
    if (S == "96") ans = "Yes";
    if (S == "61") ans = "Yes";
    if (S == "42") ans = "Yes";
    if (S == "23") ans = "Yes";
    if (S == "84") ans = "Yes";
    if (S == "65") ans = "Yes";
    if (S == "46") ans = "Yes";
    if (S == "27") ans = "Yes";
    if (S == "69") ans = "Yes";
  } else {
    for (ll x = 1; x < 125; x++) {
      ll eight = 8 * x;
      vector<ll> d2(10, 0);
      for (ll i = 0; i < 3; i++) {
        d2[eight % 10]++;
        eight /= 10;
      }
      bool ok = true;
      for (ll i = 0; i < 10; i++) {
        if (d[i] < d2[i]) ok = false;
      }
      if (ok) {
        ans = "Yes";
      }
    }
  }

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


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

#define MOD 1000000007

long long pows(long long a, long long b) {
  if (a == 0) return 0;
  long long left = b;
  long long ks = a;
  long long ans = 1;
  while (left > 0) {
    if (left%2 == 1) {
      ans = ans*ks%MOD;
    }
    ks = ks*ks%MOD;
    left /= 2;
  }
  return ans;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n,p;
  cin >> n >> p;
  long long ans = p-1;
  ans *= pows(p-2,n-1);
  ans %= MOD;
  if (n == 1 && p == 2) ans = 1;
  cout << ans << endl;
}


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

int main()
{
    ll n;
    cin >> n;
    ll cnt = 0;
    unordered_set<ll> d={};
    n += n;
    for (ll i = 1; i <= sqrt(n); i++)
    {
        if (n%i==0){
            if (i%2!=(n/i)%2){
                cnt++;
            }
        }
    }
    cout << 2*cnt << endl;
}

/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ?
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define pf push_front
#define F first
#define S second
#define SS stringstream
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define CC(x) cout << (x) << endl
#define AL(x) x.begin(),x.end()
#define pw(x) (1ull<<(x))
#define NMSL cout << "NMSL" << endl;
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x, y) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define debug3(x, y, z) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define debug4(a, b, c, d) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define fio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define in128 __int128_t
using namespace std;
const int N = 2e5+10;
const int INF = numeric_limits<int>::max() / 4;
const double EPS = 1e-3;
const long double PI = 3.14159265358979323846;
signed main()
{
    fio
    int n;
    cin>>n;
    int ans=0;
    int base=0,a=0;
    while(1)
    {
        int nx=base*1000+999;
        if(n>=nx)
        {
           ans+=(nx-base)*a;
        }
        else
        {
            ans+=a*(n-base);
            break;
        }a++;base=nx;
    }cout<<ans;
    return 0;
}


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

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

    ll N, M; cin >> N >> M;
    VLL X(M),Y(M),Z(M); REP(i,M) cin >> X[i] >> Y[i] >> Z[i];

    VVLL E(N+1);
    REP(i,M) {
        E[X[i]].push_back(i);
    }

    VLL dp(1<<N, 0); dp[0] = 1;
    REP(S,1<<N) {
        ll p = PCNT(S);

        bool ok = true;
        for (ll id : E[p]) {
            ll cnt = 0;
            REP(i,N) if (BIT(S,i)) {
                if (i+1 <= Y[id]) cnt++;
            }
            if (cnt > Z[id]) ok = false;
        }
        if (!ok) continue;

        REP(u,N) if (BIT(S,u)) {
            dp[S] += dp[S ^ (1<<u)];
        }
    }
    ll ans = dp[(1<<N)-1];
    COUT(ans);

    return 0;
}

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2021.04.29 06:43:59
**/

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

int main() {
    int n,m;cin >> n >> m;
    vector<vector<pair<int,int>>> a(n+1);
    for (int i = 0; i < m; i++) {
        int x,y,z;cin >> x >> y >> z;
        a[y].push_back({x,z});
    }
    vector<ll> dp(1<<n);
    dp[0]=1;
    for (int i = 1; i < 1<<n; i++) {
        bool ok = true;
        for(auto [x,z] : a[__builtin_popcount(i)]) {
            if (__builtin_popcount((1<<x)-1&i) > z) {
                ok=false;
                break;
            }
        }
        if (!ok) { dp[i]=0; continue; }
        for (int j = 0; j < n; j++) if (i&1<<j) dp[i] += dp[i^(1<<j)];
    }
    cout << dp[(1<<n)-1] << endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    string x,z = "";
    cin>>x;
    for(int i = 0; i < x.length(); i++)
    {
        if(x[i] == '.')
            break;
        z += x[i];
    }
    cout<<z;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define re register int
#define inf 0x7fffffffffffffff
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f==1?x:-x;
}
signed main()
{
	while(1)
	{
		char x=getchar();
		if(x=='.' || x=='\n')break;
		printf("%c",x);
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>
#include<deque>
#include<math.h>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<=n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll modq=998244353;
const ll INF=1e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}

ll modpow(ll a,ll n) {
    ll res = 1;
    while (n>0) {
        if(n&1) res=res*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return res;
}

// a^{-1} mod を計算する
ll modinv(ll a) {
    return modpow(a, mod - 2);
}

ll nCk(ll n,ll k){
    ll nck=1;
    rep(i,k){
        nck=(nck*(n-i))%mod;
        nck=(nck*modinv(k-i))%mod;
    }
    return nck;
}

int main(void){
    ll N,M,Asum=0;
    cin>>N>>M;
    rep(i,N){
        ll A;
        cin>>A;
        Asum+=A;
    }
    if(M<Asum){
        cout<<0<<endl;
        return 0;
    }
    cout<<nCk(M+N,N+Asum)<<endl;
    return 0;
}

#include <iostream>
#include <cmath>
#include <stdio.h>
#include <string.h>
#include <bits/stdc++.h>
#include <vector>
#include <array>
#include <tuple>
#include <algorithm>
using namespace std;

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

int main() {
  long long N, M, S, x, P, C;
  cin >> N >> M;
  S=0;
  for (int i=0; i<N; i++){
    cin >> x;
    S=S+x;
  }
  P=1;
  C=1000000007;
  for (int i=0; i<S+N; i++){
    P=(P*(M+N-i))%C;
    P=(P*modinv(S+N-i, C))%C;
  }
  cout << P << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define F(i,l,r) for(int i=l;i<=r;i++)
#define ll long long
char p[10000];
int res=0;
int main()
{
    int m,t,n;
    cin >> n >> m >> t;
    int vt=0;
    int cnt=n;
    F(i,1,m)
    {
        int x,y;
        cin >> x >> y;
        cnt-=(x-vt);
        if(cnt<=0) break;
        cnt=min(n,cnt+(y-x));
        vt=y;
    }
    cnt-=(t-vt);
 //   cout << n << endl;
    if(cnt>0) cout << "Yes";
    else cout << "No";
    return 0;
}

#include <bits/stdc++.h>
#define N 200005
#define M 400005
#define inf 1e18
#define mp make_pair
#define int long long
using namespace std;
int n,m;
int head[N],v[M],C[M],D[M],nxt[M],tot;
priority_queue<pair<int,int> > q;
int dis[N];
bool vis[N];
int read()
{
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=(x<<1)+(x<<3)+(c^48);
		c=getchar();
	}
	return x*f;
}
inline void add(int x,int y,int c,int d)
{
	tot++;
	v[tot]=y;
	C[tot]=c;
	D[tot]=d;
	nxt[tot]=head[x];
	head[x]=tot;
}
inline int Dij(int s)
{
	for(int i=2;i<=n;i++) dis[i]=inf;
	dis[s]=0;
	q.push(mp(0,s));
	while(!q.empty())
	{
		int x=q.top().second,s=q.top().first;q.pop();
		if(x==n) return -s;

		if(vis[x]) continue;
		vis[x]=1;
		for(int i=head[x];i;i=nxt[i])
		{
			if(dis[v[i]]>((dis[x]>floor(sqrt(D[i]+1))-1)?dis[x]+C[i]+(D[i]/(dis[x]+1)):floor(sqrt(D[i]+1))-1+C[i]+(D[i]/(floor(sqrt(D[i]+1))))))
		    {
				dis[v[i]]=((dis[x]>floor(sqrt(D[i]+1))-1)?dis[x]+C[i]+(D[i]/(dis[x]+1)):floor(sqrt(D[i]+1))-1+C[i]+(D[i]/(floor(sqrt(D[i]+1)))));
				q.push(mp(-dis[v[i]],v[i]));
			}
		}
	}
	return -1;
}
signed main()
{
	n=read();
	m=read();
	int a,b,c,d;
	for(int i=1;i<=m;i++)
	{
		a=read();
		b=read();
		c=read();
		d=read();
		//if(a==b) continue;
		add(a,b,c,d);
		add(b,a,c,d);
	}
	printf("%lld\n",Dij(1));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
char c2,c1,c3;
int main()
{
	c1=getchar(),c2=getchar(),c3=getchar();
	if (c1==c2&&c2==c3) printf("Won\n");
	else printf("Lost\n");
	return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string slots;
    cin>>slots;
    if(slots[0]==slots[1]&&slots[1]==slots[2])
        cout<<"Won";
    else
        cout<<"Lost";
    return 0;
}


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

int main(){
  string s;
  std::cin >> s;

  std::map<int,ll> ma;
  rep(i,s.size()){
    int num=(int)(s[i]-'0');
    ma[num]++;
  }

  if(s.size()==1){
    if(s[0]=='8')std::cout << "Yes" << '\n';
    else std::cout << "No" << '\n';
    return 0;
  }

  if(s.size()==2){
    int     si = std::stoi(s);
    int    s2i = ((int)(s[1]-'0'))*10+(int)(s[0]-'0');
    // std::cout << s2i << '\n';
    if(si%8==0 || s2i%8==0)std::cout << "Yes" << '\n';
    else std::cout << "No" << '\n';
    return 0;
  }

  for (int i = 1; i < 10; i++) {
    for (int k = 1; k < 10; k++) {
      for (int l = 1; l < 10; l++) {

        if((i*100+k*10+l)%8!=0)continue;

        std::map<int,ll> ma2=ma;
        if(ma2[i]>0)ma2[i]--;
        else continue;

        if(ma2[k]>0)ma2[k]--;
        else continue;

        if(ma2[l]>0){
          std::cout << "Yes" << '\n';
          return 0;
        }

      }
    }
  }

  std::cout << "No" << '\n';
  return 0;
}

#include <iostream>

using namespace std;

typedef long long ll;
ll num,b[200],sum=0;
int main()
{
    ll n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>num;
        b[num%200]++;
    }
    for(int i=0;i<200;i++)
    {
        if(b[i]>=2)
        {
            sum+=b[i]*(b[i]-1)/2;
        }
    }
    cout<<sum<<endl;
    return 0;
}


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

int main() {
	int A,B,C;
	cin >> A >> B >> C;
	if(A + C <= B){
		cout << "Aoki" << endl;
	}else{
		cout << "Takahashi" << endl;
	}
	return(0);
}

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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  if ( A > B )
    cout << "Takahashi" << endl;
  if ( A < B )
    cout << "Aoki" << endl;
  if ( A == B && C == 0 )
    cout << "Aoki" << endl;
  if ( A == B && C == 1 )
    cout << "Takahashi" << endl;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>
#include <map>

#include <cstdlib>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T>bool chmaxj(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; } //true==yes

#define INF 21474836

//////////////////////////////////////////////////////////////

int H, W;

int main() {

	int Sx, Sy;
	int Gx, Gy;

	cin >> H >> W;

	vector<vector<char>> a(H, vector<char>(W, 0));
	vector<vector<int>> max(H, vector<int>(W, INF));
	vector<vector<pair<int, int>>>
		alpha(30,vector<pair<int,int>>(1,pair<int,int>(-1,-1)));
	bool checked[30] = { false };

	for (int y = 0; y < H; y++) {
		string s;
		cin >> s;
		for (int x = 0; x < W; x++) {
			a[y][x] = s[x];

			if (a[y][x] == 'S') {
				Sx = x;
				Sy = y;
			}

			if (a[y][x] == 'G') {
				Gx = x;
				Gy = y;
			}

			if ('a' <= a[y][x] && a[y][x] <= 'z') {
				if (alpha[a[y][x] - 'a'][0].first == -1) {
					alpha[a[y][x] - 'a'][0].first = x;
					alpha[a[y][x] - 'a'][0].second = y;
				}
				else {
					alpha[a[y][x] - 'a'].push_back(pair<int,int>(x,y));
				}
			}
		}
	}

	max[Sy][Sx] = 0;

	queue<pair<int,int>> que;
	que.push(pair<int, int>(Sy,Sx));

	while (!que.empty())
	{
		pair<int, int> p = que.front();
		que.pop();

		int x = p.second;
		int y = p.first;

		if (0 < x) {
			if (a[y][x - 1] != '#') {
				if (max[y][x - 1] > max[y][x] + 1) {
					max[y][x - 1] = max[y][x] + 1;
					que.push(pair<int, int>(y, x - 1));
				}
			}
		}

		if (x < W - 1) {
			if (a[y][x + 1] != '#') {
				if (max[y][x + 1] > max[y][x] + 1) {
					max[y][x + 1] = max[y][x] + 1;
					que.push(pair<int, int>(y, x + 1));
				}
			}
		}

		if (0 < y) {
			if (a[y - 1][x] != '#') {
				if (max[y - 1][x] > max[y][x] + 1) {
					max[y - 1][x] = max[y][x] + 1;
					que.push(pair<int, int>(y - 1, x));
				}
			}
		}

		if (y < H - 1) {
			if (a[y + 1][x] != '#') {
				if (max[y + 1][x] > max[y][x] + 1) {
					max[y + 1][x] = max[y][x] + 1;
					que.push(pair<int, int>(y + 1, x));
				}
			}
		}

		if ('a' <= a[y][x] && a[y][x] <= 'z') {

			int ss = a[y][x] - 'a';
			if (checked[ss] == false) {

				for (int i = 0; i < alpha[ss].size(); i++) {
					int alx = alpha[ss][i].first;
					int aly = alpha[ss][i].second;
					if (max[aly][alx] > max[y][x] + 1) {
						max[aly][alx] = max[y][x] + 1;
						que.push(pair<int, int>(aly, alx));
					}
				}
			}

			checked[ss] = true;

		}

	}

	if (max[Gy][Gx] == INF) {
		cout << -1;
		return 0 ;
	}
	cout << max[Gy][Gx];
	return 0;
}

#include <cstdio>
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
# define rep(i,a,b) for(int i=(a); i<=(b); ++i)
inline int readint(){
	int a = 0; char c = getchar(), f = 1;
	for(; c<'0'||c>'9'; c=getchar())
		if(c == '-') f = -f;
	for(; '0'<=c&&c<='9'; c=getchar())
		a = (a<<3)+(a<<1)+(c^48);
	return a*f;
}

const int MaxN = 1000005;
char s[MaxN<<1], cmd[MaxN];
char res[MaxN<<1];

int main(){
	int L = MaxN+1, R = L-1;
	scanf("%s",cmd);
	int n = strlen(cmd), op = 1;
	for(int i=0; i<n; ++i)
		if(cmd[i] == 'R') op ^= 1;
		else if(op) s[++ R] = cmd[i];
		else s[-- L] = cmd[i];
	if(!op) rep(i,L,L+R-i)
		swap(s[i],s[L+R-i]);
	int lst = L-1; // last one
	res[L-1] = '#';
	for(int i=L; i<=R; ++i)
		if(lst >= L && s[i] == res[lst]) -- lst;
		else res[++ lst] = s[i];
	res[lst+1] = '?'; rep(i,L,lst)
		if(i < lst && res[i] == res[i+1])
			++ i; // skip the two
		else putchar(res[i]);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<sstream>
#include<iomanip>
#define forn(i,n) for(int (i)=0;i<(n);i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=100005;
const int INF=2147483647;
const ll LINF=9223372036854775807;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int n,ans;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	while(n--)
	{
		int x;
		cin>>x;
		ans+=max(0,x-10);
	}
	cout<<ans;
	return 0;
}

#include <iostream>

using namespace std;

void solve() {
  int n;
  string s1,s2,s3;
  cin >> n >> s1 >> s2 >> s3;
  cout << string(n,'0') << string(n,'1') << '0' << endl;
}

int main() {
  int t;
  cin >> t;
  for (int _=0; _<t; _++) solve();
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<ll,ll>;

int n;
vector<int> c(100005);
vector<bool> ok(100005,false);
vector<bool> visited(100005,false);

vector<int> g[100005];
vector<int> cnt(100005,0);

void dfs(int x){
    visited[x] = true;
    if(cnt[c[x]]==0){
        ok[x] = true;
    }

    cnt[c[x]]++;
    for(auto next:g[x]){
        if(visited[next]) continue;
        dfs(next);
    }
    cnt[c[x]]--;
}

int main(){
    cin >> n;
    rep(i,n){
        cin >> c[i];
    }

    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    dfs(0);

    rep(i,n){
        if(ok[i]){
            cout << i+1 << endl;
        }
    }
}

#include<bits/stdc++.h>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
using namespace std;

const int mxn=2e5+5;

int c[mxn];
vector<int> g[mxn];
map<int, int> mp;
set<int> ans;

void dfs(int x, int p){
    if(mp[c[x]]==0)
        ans.insert(x);
    mp[c[x]]++;
    for(auto y:g[x]){
        if(y==p)
         continue;
        dfs(y, x);
    }
    mp[c[x]]--;
}

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

    for(i=1; i<=n; i++)
    	cin>>c[i];

    for(i=0; i<n-1; i++){
        int a, b;
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(1, -1);

    for(auto x:ans)
    	cout<<x<<'\n';
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	double sx, sy, gx, gy;

	cin >> sx >> sy >> gx >> gy;

	double x = (sy*gx + gy*sx) / (sy + gy);

	cout.precision(12);
	cout << x;

	return 0;
}

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

int main() {

	float R, X, Y;
	cin >> R >> X >> Y;

	double dist = sqrt(X * X + Y * Y);
	int ans = 0;
	while (true) {
		ans++;
		if (R == dist) break;
		if (R < dist) dist -= R;
		if (R > dist) {
			ans += 1;
			break;
		}
	}

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


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

void input(int& rnMaxNum)
{
  cin >> rnMaxNum;
}

bool is7NotIncluded(int nNum, int nBase)
{
  while (nNum != 0)
  {
    if (nNum % nBase == 7)
      return false;

    nNum /= nBase;
  }
  return true;
}

int calc7NotIncluded(int nMaxNum)
{
  int n7NotIncluded = 0;

  for (int nx = 1; nx <= nMaxNum; ++nx)
    if ( is7NotIncluded(nx, 10) &&
         is7NotIncluded(nx,  8)    )
      ++n7NotIncluded;

  return n7NotIncluded;
}

int main()
{
  int nMaxNum;
  input(nMaxNum);
  cout << calc7NotIncluded(nMaxNum) << endl;

  return 0;
}

#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

ll MOD=998244353;

int main(){FIN;
	ll n; cin>>n;
	vector<ll> a(n);
	fore(i,0,n)cin>>a[i];
	sort(ALL(a));
	ll res=0;
	ll sum=0;
	fore(i,0,n){
		res=(res+sum*a[i])%MOD;
		sum=(2*sum+a[i])%MOD;
	}
	fore(i,0,n)res=(res+a[i]*a[i])%MOD;
	cout<<res<<"\n";

	return 0;
}


// Problem : C - Friends and Travel costs
// Contest : AtCoder - AtCoder Beginner Contest 203（Sponsored by Panasonic）
// URL : https://atcoder.jp/contests/abc203/tasks/abc203_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

#define endl  "\n"
#define int   long long
#define FAST  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef pair<int,int>   pii;
typedef vector<pii>     vii;
#define rep(i,n)        for(int i=0;i<(n);i++)
#define pb              push_back
#define ff              first
#define ss              second
#define sz(x)           ((int)(x).size())
#define all(x)          (x).begin(), (x).end()
#define INF             (long long) 1e13
#define MOD             1000000007
#define MAX             (int) 2e5+5

void solve() {

}

int32_t main(){
    FAST
    int n,k;
    cin>>n>>k;
    int best = 0;
    vector<pii> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i].ff >> a[i].ss;
    }
    sort(all(a));
    for(int i=0;i<n;i++){
        if(abs(a[i].ff-best)<=k){
            k -= a[i].ff-best;
            best = a[i].ff;
            k += a[i].ss;
        }
    }
    best += k;
    cout << best << endl;
    return 0;
}

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

int main() {
	int n,k;
	cin>>n>>k;
	string p=to_string(n);
	for(int i=1;i<=k;i++){
		string tmp1=p,tmp2=p;
		sort(tmp1.begin(),tmp1.end());
		sort(tmp2.begin(),tmp2.end(),greater<int>());
		p=to_string(stoi(tmp2)-stoi(tmp1));

	}
	cout<<p<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define endl '\n'
ll n,m;
vector <P> v,w;
set<ll> s;
int main(){
    cin >> n >> m;
    rep(i,m){
        ll x,y;
        cin >> x >> y;
        v.emplace_back(x,y);
    }
    sort(v.begin(),v.end());
    s.insert(n);
    int l=0,r;
    while(l<m){
        vector <ll> a,b;
        r=l;
        while(r<m){
            if(v[r].first==v[l].first)r++;
            else break;
        }
        for(int i=l;i<r;i++){
            int x=v[i].second;
            if((s.find(x-1)!=s.end())||(s.find(x+1)!=s.end()))a.push_back(x);
            if(((s.find(x-1)==s.end())&&(s.find(x+1)==s.end())) && (s.find(x)!=s.end()))b.push_back(x);
        }
        rep(i,a.size())s.insert(a[i]);
        rep(i,b.size())s.erase(b[i]);
        l=r;
    }
    cout << s.size() << endl;
    return 0;
}

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

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long x;
  cin >> n >> x;
  vector<long long> a(n);
  for (int i=0;i<n;i++) cin >> a[i];
  vector<vector<long long>> dp(n,vector<long long>(2,0));
  vector<long long> mins(n);
  long long nx = x;
  for (int i=n-1;i>=0;i--) {
    mins[i] = nx/a[i];
    nx -= mins[i]*a[i];
  }
  dp[0][0] = 1;
  if (n > 1 && mins[0] != 0) {
    dp[0][1] = 1;
  }
  for (int i=1;i<n-1;i++) {
    dp[i][0] = dp[i-1][0];
    if (mins[i]+1 != a[i+1]/a[i]) {
      dp[i][0] += dp[i-1][1];
    }
    dp[i][1] = dp[i-1][1];
    if (mins[i] != 0) {
      dp[i][1] += dp[i-1][0];
    }
  }
  if (n > 1) {
    dp[n-1][0] = dp[n-2][0]+dp[n-2][1];
  }
  /*for (int i=0;i<n;i++) {
    cout << dp[i][0] << ' ';
  }
  cout << endl;
  for (int i=0;i<n;i++) {
    cout << dp[i][1] << ' ';
  }
  cout << endl;*/
  cout << dp[n-1][0] << endl;
}


#include<bits/stdc++.h>
#include<bits/extc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t){
	while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr<<#x<<": "; for(auto i:x) cerr<<i<<" "; cerr<<endl;}}
#define debugr(l, r, x) {{cerr<<#x<<": "; for(int i=l;i<=r;i++) cerr<<x<<" "; cerr<<endl;}}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debugr(l, r, x)
#define cerr while(0) cerr
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define priority_queue std::priority_queue
#define F first
#define S second
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

char a[1005][1005];
bool vis[3005];
vi adj[3005];
void dfs(int x){
	vis[x]=true;
	for(int y:adj[x]){
		if(!vis[y]) dfs(y);
	}
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int h, w;
	cin>>h>>w;
	set<int> row, col;
	auto add=[&](int x, int y){
		adj[x].push_back(h+y);
		adj[h+y].push_back(x);
		row.insert(x);
		col.insert(h+y);
	};
	add(1, 1);
	add(1, w);
	add(h, 1);
	add(h, w);
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>a[i][j];
			if(a[i][j]=='#'){
				add(i, j);
			}
		}
	}
	int ccs=0;
	for(int i:row){
		if(!vis[i]){
			dfs(i);
			ccs++;
		}
	}
	for(int i:col){
		if(!vis[i]){
			dfs(i);
			ccs++;
		}
	}
	debug(row.size(), col.size());
	cout<<ccs+min(h-row.size(), w-col.size())-1<<endl;
}

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

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using namespace __gnu_pbds;

int n;
vector<int> adj[200005];
ordered_set ins[200005], outs[200005];
int in[200005], out[200005], dis[200005];
int t=0;

void dfs(int u,int p)
{
	in[u] = ++t;
	for(auto x:adj[u])
	{
		if(x!=p) dis[x]=dis[u]+1, dfs(x,u);
	}
	out[u]=++t;
}

int main()
{
	cin>>n;
	for(int i=2;i<=n;i++)
	{
		int x;cin>>x;
		adj[i].push_back(x);
		adj[x].push_back(i);
	}

	dfs(1,0);
	for(int i=1;i<=n;i++)ins[dis[i]].insert(in[i]), outs[dis[i]].insert(out[i]);

	int q;
	cin>>q;
	while(q--)
	{
		int u,d;cin>>u>>d;
		int ans=ins[d].order_of_key(out[u])-ins[d].order_of_key(in[u]);

		cout<<ans<<endl;
	}
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    //入力
    int A,B,C,X,Y,Z;
    cin >> X>>Y>>Z;
    if(X>=Y && X>=Z){
        A=X;
        if(Y>=Z){
            B=Y, C=Z;
        } else {
            B=Z, C=Y;
        }
    } else if(Y>=X && Y>=Z){
        A=Y;
        if(X>=Z){
            B=X, C=Z;
        } else {
            B=Z, C=X;
        }
    } else {
        A=Z;
        if(X>=Y){
            B=X, C=Y;
        } else {
            B=Y, C=X;
        }
    }
    //cout << A << B << C<< endl;
    if(C-B==B-A){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;

}

#include<bits/stdc++.h>
//#include <atcoder/all>

#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define fi first
#define se second
#define sz(x) ((int)x.size())

using namespace std;
//using namespace atcoder;
using ld = long double;
using ll =  long long;
using P = pair<ll, ll>;

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

const ll MOD = 1e9 + 7;
const ll INF = 1e9;

int main(){
    vector<int> a(3);
    rep(i, 3)cin >> a[i];
    sort(ALL(a));
    bool f = false;
    do{
        if(a[1] - a[0] == a[2] - a[1])f = true;
    }while(next_permutation(ALL(a)));
    cout << (f ? "Yes" : "No") << endl;
}