#include<bits/stdc++.h>
using namespace std;
#define MAXN 500005
char s[MAXN],t[MAXN];
int n,cnt1,cnt2;
int main()
{
    scanf("%d",&n);
    scanf("%s %s",s,t);
    for(int i=0;i<n;i++)if(s[i]=='0')cnt1++;
    for(int i=0;i<n;i++)if(t[i]=='0')cnt2++;
    if(cnt1!=cnt2)printf("-1\n");
    else
    {
        int i=0,j=0;
        while(1)
        {
            while(i<n&&s[i]=='1')i++;
            while(j<n&&t[j]=='1')j++;
            if(i>=n)break;
            i++,j++;
            if(i==j)cnt1--;
        }
        printf("%d\n",cnt1);
    }
    return 0;
}

#include <algorithm>
#include <chrono>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <assert.h>

//#pragma GCC optimize("O3")

using namespace std;

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

const ll MOD = 998244353;
const ld EPS = 1e-11;
const ld MEPS = EPS * 1e2;
const ll INFL = 2e18;
const int INF = 1e9 + 7;
const ld PI = acos(-1);
const ld E = exp(1);

mt19937 rnd((unsigned)chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //    freopen("input.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);

    int n;
    cin >> n;

    string s, t;
    cin >> s >> t;

    vector<int> is, it;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '0') {
            is.push_back(i);
        }
        if (t[i] == '0') {
            it.push_back(i);
        }
    }

    if (is.size() != it.size()) {
        cout << "-1\n";
        return 0;
    }

    int ans = 0;
    for (int i = 0; i < is.size(); ++i) {
        if (is[i] != it[i]) {
            ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000000000005

using namespace std;

int main (){

	int a,b,ms,mf;
	cin>>a>>b;

	ms = a+b;
	mf = b;
	//cout<<ms<<" "<<mf<<endl;

	if (  ms >= 15 &&  mf >=8 ) {
		cout<<1; return 0;
	}
	else if ( ms >= 10 && mf >=3  ){
		cout<<2; return 0;
	}
	else if ( ms >=3 ){
		cout<<3; return 0;
	}
	else {
		cout<< 4; return 0;
	}
}

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

long myPow(long x, long n, long m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

int main()
{
  long N, M;
    cin >> N >> M;
    cout << myPow(10,N,M*M) / M << endl;
    system("pause");
    return 0;
}


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

int main(){
  string s;
  cin>>s;
  reverse(s.begin(),s.end());
  for(auto& a:s){
    if (a=='6') {
      a='9';
    } else if(a=='9') {
      a='6';
    }
  }
  cout<<s<<endl;
}

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

int main() {
  string s, S;
  cin >> s;
  int n;
  n = s.size();

  for (int i = n - 1; -1 < i; i--){
    if (s.at(i) == '6')
      S += '9';
    if (s.at(i) == '9')
      S += '6';
    if (s.at(i) != '9' && s.at(i) != '6')
      S += s.at(i);
    if (i == 0)
      cout << S << endl;
  }
}


#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

using namespace std;

struct Edge {
  int to;
  long long weight;
  Edge() : to(0), weight(0) {}
  Edge(int to, long long weight) : to(to), weight(weight) {}
  Edge(const Edge& e) {
    to = e.to;
    weight = e.weight;
  }
  bool operator>(const Edge &e) const { return weight > e.weight; }
  bool operator<(const Edge &e) const { return weight < e.weight; }
  bool operator==(const Edge &e) const { return weight == e.weight; }
  bool operator<=(const Edge &e) const { return weight <= e.weight; }
  bool operator>=(const Edge &e) const { return weight >= e.weight; }
};

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
using weightedGraph = vector<vector<Edge>>;
using heap = priority_queue<int, vector<int>, greater<int>>;

const ll BIL = 1e9;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1 << 29;
const ld PI = 3.141592653589793238462643383;

int main(int argc,char* argv[]){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
  int l, r;
  cin >> l >> r;
  vector<int> sp(r+1, -1);
  vector<vector<ll>> p(r+1);
  for(int i=2;i<=r;i++) {
    if(sp[i] < 0) {
      for(int j=1;j*i<=r;j++) sp[i*j] = i;
    }
  }
  for(int i=2;i<=r;i++) {
    int k = i;
    set<int> ck;
    while(sp[k] != k) {
      if(ck.find(sp[k]) == ck.end()) p[i].push_back(sp[k]);
      ck.insert(sp[k]);
      k /= sp[k];
    }
    if(ck.find(k) == ck.end()) p[i].push_back(k);
    sort(p[i].begin(), p[i].end());
  }
  ll ans = 0;
  for(int i=l;i<=r;i++) {
    if(i < 2) continue;
    ll t = 0;
    vector<ll>& q = p[i];
    int sz = q.size();
    for(int b=1;b<(1<<sz);b++) {
      int cnt = 0;
      int k = 1;
      for(int j=0;j<sz;j++) {
        if((1<<j) & b) {
          cnt++;
          k *= q[j];
        }
      }
      if(k == 1) continue;
      ll s = r/k - (i-1)/k;
      if(cnt % 2 == 0) s *= -1;
      t += s;
    }
    t -= r/i;
    ans += t;
  }
  cout << 2*ans << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int Mod=998244353;

namespace modular{
	int add(int a,int b){return a+b>=Mod?a+b-Mod:a+b;}
	int mul(int a,int b){return 1ll*a*b%Mod;}
}using namespace modular;

#define cout cerr
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)

typedef long long ll;
typedef pair<int,int> pii;
#define FR first
#define SE second

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

int n,m;
#define Maxn 5005
pii F[Maxn][2];
pii addt(pii a,pii b){return pii(add(a.FR,b.FR),add(a.SE,b.SE));}
pii mult(pii a,pii b){return pii(mul(a.FR,b.FR),add(mul(a.FR,b.SE),mul(a.SE,b.FR)));}
int DP(int x){
	F[0][0]=pii(1,0);
	rep(i,1,n){
		F[i][0]=F[i][1]=pii(0,0);
		F[i][0]=addt(F[i-1][0],F[i-1][1]);F[i][0]=mult(F[i][0],pii(x,0));
		F[i][1]=mult(F[i-1][0],pii(1,1));
		F[i][1]=addt(F[i][1],mult(F[i-1][1],pii(1,0)));
		F[i][0]=addt(F[i][0],mult(F[i-1][0],pii(m-1-x,0)));
		F[i][1]=addt(F[i][1],mult(F[i-1][1],pii(m-1-x,0)));
	}
	return add(F[n][1].SE,F[n][0].SE);
}

int main(){
	rd(n);rd(m);
	int res=0;
	for(int i=0;i<m;++i)res=add(res,DP(i));
	printf("%d\n",res);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    long long X;
    cin >> N >> X;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    long long ans = X;
    for(int i = 1; i <= N; i++){
        vector<vector<vector<long long>>> dp(N + 1, vector<vector<long long>> (i + 1, vector<long long>(i, -1)));
        dp[0][0][0] = 0;
        for(int j = 0; j < N; j++){
            for(int k = 0; k <= i; k++){
                for(int l = 0; l < i; l++){
                    if(k == i){
                        dp[j + 1][k][l] = max(dp[j + 1][k][l], dp[j][k][l]);
                        continue;
                    }
                    if(dp[j][k][l] == -1) continue;
                    dp[j + 1][k + 1][(l + A[j]) % i] = max(dp[j + 1][k + 1][(l + A[j]) % i], dp[j][k][l] + A[j]);
                    dp[j + 1][k][l] = max(dp[j + 1][k][l], dp[j][k][l]);
                }
            }
        }
        int ind = X % i;
        if(dp[N][i][ind] == -1) continue;
        long long t = (X - dp[N][i][ind]) / i;
        ans = min(ans, t);
    }
    cout << ans << endl;
}

#include<bits/stdc++.h>
#define            pb            push_back
#define            pl            pair<ll,ll>
#define            pll           pair<ll,pair<ll,ll>>
#define            ll            long long
#define            vl            vector<ll>
#define            fastio        ios_base::sync_with_stdio(false); cin.tie(NULL);
#define            mp            make_pair
#define            w(t)          int t;cin>>t;while(t--)
#define            inf           1e18
#define            fi(a,n)       for(ll i=a;i<n;i++)
#define            fr(i,a,b)     for(ll i=a;i>=b;i--)
#define            fj(a,n)       for(ll j=a;j<n;j++)
#define            k(a,n)        for(ll k=a;k<n;k++)
#define            endl          "\n"
#define            all(v)        (v).begin(),(v).end()
#define            set1(x)       __builtin_popcount(x)
#define            gcd(a,b)      __gcd(a,b)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
using namespace std;
const ll mod= 1000000007;
const ll N =1000005;
void solve()
{
   ll h,w;
   cin>>h>>w;
   ll a[h][w];
   fi(0,h)
   {
    fj(0,w)
    {
      char k;
      cin>>k;
      if(k=='#')
        a[i][j]=1;
      else
        a[i][j]=0;
    }
   }

   ll ans=0;

   fi(0,h-1)
   {
    fj(0,w-1)
    {
      ll s=a[i][j]+a[i+1][j]+a[i][j+1]+a[i+1][j+1];
      if(s&1)
      {
        ans+=1;
      }
    }
   }
   cout<<ans<<endl;
}
int main()
{
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
     // w(t)
      solve();

}


/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

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

const long long INF = 1LL << 61;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll conbinationMemo[61][31];

void cmemoInit(){
    rep(i, 61){
        rep(j, 31){
            conbinationMemo[i][j] = -1;
        }
    }
}

ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
ll n;
ll q;
vector<vector<ll>> g;
vector<vector<ll>> l;
ll in[200200];
ll out[200200];
void dfs(ll now, ll pa, ll d, ll &time){

    in[now] = time;
    l[d].push_back(time);
    time++;

    rep(i, g[now].size()){
        ll next = g[now][i];
        if(next == pa) continue;
        ll nextd = d + 1;
        dfs(next, now, nextd, time);
    }

    out[now] = time;
    time++;

}
int main(void){
    cin >> n;
    g.resize(n);
    l.resize(n);
    rep(i, n - 1){
        ll p;
        cin >> p;
        p--;
        g[p].push_back(i + 1);
    }
    ll time = 0;
    dfs(0, -1, 0, time);
    cin >> q;
    rep(i, q){
        ll u, d;
        cin >> u >> d;
        u--;

        auto itr1 = lower_bound(all(l[d]), in[u]);
        auto itr2 = lower_bound(all(l[d]), out[u]);
        cout << itr2 - itr1 << endl;
    }
}

#if _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#ifndef ONLINE_JUDGE
const bool DEBUG = true;
#else
const bool DEBUG = false;
#endif

// Reads a 1D vector
template <class T>
void read1d(vector<T> & arg) {
	const int l = arg.size();
	for (int i = 0; i < l; ++i) cin >> arg[i];
}

void read() {}
// Reads arbitrary values
template <class T1, class... T2>
void read(T1& var1, T2&... var2) { cin >> var1; read(var2...); }

void pln() { cout << (DEBUG ? "]\n" : "\n"); }
template <class T1, class... T2>
void pln(const T1& var1, const T2& ... var2) { cout << var1 << " "; pln(var2...); }

// Prints arbitrary values and goes to next line
template <class T1, class... T2>
constexpr void print(const T1& var1, const T2& ... var2) { cout << (DEBUG ? " [ " : ""); pln(var1, var2...); }

// Prints arbitrary values and goes to next line ONLY IF IN DEBUG MODE
template <class T1, class... T2>
constexpr void debug(const T1& var1, const T2& ... var2) { if (!DEBUG) return;  cout << " debug : [ "; pln(var1, var2...); }

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define all(x) begin(x), end(x)

const bool MULTIPLE_TEST_CASES = 0;

void exec()
{
	int a, b;
	read(a, b);

	int ans = 4;
	if (a + b>= 3) ans = 3;
	if (a + b  >= 10 && b >= 3) ans = 2;
	if (a + b >= 15 && b >= 8) ans = 1;
	print(ans);
}

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

	if (!MULTIPLE_TEST_CASES)
		exec();
	else {
		int n;
		cin >> n;

		while (n--) exec();
	}

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int k;
long long n, a[50];
long long g1(long long x){
    int len = 0;
    while(x){
        a[len ++] = x%10;
        x /= 10;
    }
    sort(a, a+len);

    for(int i = 0; i < len; ++ i){
        x *= 10;
        x += a[i];
    }
//    cout  << x << endl;
    return x;
}
long long g2(long long x){
    int len = 0;
    while(x){
        a[len ++] = x%10;
        x /= 10;
    }
    sort(a, a+len);

    for(int i = len-1; i >= 0; -- i){
        x *= 10;
        x += a[i];
    }
//    cout  << x << endl;
    return x;
}
int main(){
    cin >> n >> k;
    while(k --){
        n = g2(n) - g1(n);
    }
    cout << n <<endl;
}

#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007

using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))

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

    ans=(3-(a+b)%3)%3;

    cout <<ans<<endl;

    return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define debug(a) { cerr << #a << ':' << a << endl; }
#define endl '\n'
#define fi first
#define se second
using lint = long long;
using P = pair<int,int>;
template<class T> using V = vector<T>;
template<class T> using priq     = priority_queue<T>;
template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
template<class T> T ceil(const T &a, const T &b) { return (a+b-1)/b; }
template<class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; }
template<class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; }
struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF;

template<class T, class U> istream& operator>>(istream &in, pair<T,U> &p) {
    return in >> p.first >> p.second;
}
template<class T, class U> ostream& operator<<(ostream &out, const pair<T,U> &p) {
    return out << p.first << ' ' << p.second;
}
template<class T> istream& operator>>(istream &in, vector<T> &v) {
    for(auto &&e: v) in >> e;
    return in;
}
template<class T> ostream& operator<<(ostream &out, const vector<T> &v) {
    for(const auto &e: v) out << e << ' ';
    return out;
}

/*----------------------------------------------------------------------------------------------------*/

int main() {
    int n;
    cin >> n;
    n *= 108;
    n /= 100;
    if(n < 206) puts("Yay!");
    if(n == 206) puts("so-so");
    if(n > 206) puts(":(");
}

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

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

  int ans=0;
  for(int i=0;i<10000;i++) {
    vector<bool> used(10);
    int x=i;
    for(int j=0;j<4;j++) {
      used[x%10] = true;
      x /=10;
    }
    bool able = true;
    for(int j=0;j<10;j++) {
      if(S[j] == 'o' && !used[j]) {
        able=false;
      }
      if(S[j] == 'x' && used[j]) {
        able=false;
      }
    }
    ans += able;
  }
  cout<<ans<<endl;

}


#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define replr(i, l, r) for (int i = (l); i < (r); ++i)
const int mod = 1e9 + 7;
vector<int> T[202020];
ll ans[202020], C[202020];
void rec(int x, ll c, int par) {
    c += C[x];
    for (int to : T[x]) {
        if (to == par)
            continue;
        rec(to, c, x);
    }
    ans[x] = c;
}

int main() {
    int n, q;
    cin >> n;
    vector<int> A(n), B(n), X(n);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        A[i] = a;
        B[i] = b;
        T[a].push_back(b);
        T[b].push_back(a);
    }
    queue<P> Q;
    Q.push({1, 0});
    while (!Q.empty()) {
        P p = Q.front();
        Q.pop();
        if (X[p.second] > 0)
            continue;
        X[p.second] = p.first;
        for (int to : T[p.second])
            Q.push({p.first + 1, to});
    }

    cin >> q;
    rep(i, q) {
        ll t, e, x;
        cin >> t >> e >> x;
        e--;
        int a = A[e], b = B[e];
        if (X[a] > X[b]) {
            if (t == 1)
                C[a] += x;
            else {
                C[0] += x;
                C[a] -= x;
            }
        } else {
            if (t == 1) {
                C[0] += x;
                C[b] -= x;
            } else
                C[b] += x;
        }
    }
    rec(0, 0, -1);
    rep(i, n) cout << ans[i] << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
map<ll,vector<ll>>adjlist;
void dfs(ll curr,ll P,vector<ll>&parent){
    parent[curr]=P;
    for(auto i:adjlist[curr]){
        if(i!=P){
            dfs(i,curr,parent);
        }
    }
    return;
}
void Sum(ll rt,ll P,ll val,vector<ll>&ans){
    ans[rt]+=val;
    for(auto i:adjlist[rt]){
        if(i!=P){
            Sum(i,rt,ans[rt],ans);
        }
    }
    return;
}
void solve(){
    ll n;
    cin>>n;
    vector<pair<ll,ll>>edge(n);
    for(ll i=1;i<n;i++){
        ll x,y;
        cin>>x>>y;
        adjlist[x].push_back(y);
        adjlist[y].push_back(x);
        edge[i]={x,y};
    }
    vector<ll>parent(n+1);
    dfs(1,1,parent);
    ll q;
    cin>>q;
    vector<ll>ans(n+1,0);
    for(ll i=0;i<q;i++){
        ll t,e,x;
        cin>>t>>e>>x;
        ll a=edge[e].first;
        ll b=edge[e].second;
        ll p=parent[a];
        if(t==1){
            if(p!=b){
                ans[1]+=x;
                ans[b]-=x;
            }
            else{
                ans[a]+=x;
            }
        }
        else{
            if(p!=b){
                ans[b]+=x;
            }
            else{
                ans[1]+=x;
                ans[a]-=x;
            }
        }
    }
    Sum(1,1,0,ans);
    for(ll i=1;i<=n;i++){
        cout<<ans[i]<<endl;
    }
    return;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


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

const int inf = 1e8;
const ll llinf = 1e18;
const double PI = acos(-1);
#define yes "Yes"
#define no "No"
#define all(n) n.begin(), n.end()

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

struct UnionFind {
  vector<int> par, siz;
  UnionFind(int n) : par(n, -1), siz(n, 1) {}
  int root(int x) {
    if (par[x] == -1) return x;
    return par[x] = root(par[x]);
  }
  bool isSame(int x, int y) { return root(x) == root(y); }
  bool unite(int x, int y) {
    x = root(x), y = root(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x, y);
    par[y] = x;
    siz[x] += siz[y];
    return true;
  }
  int size(int x) { return siz[root(x)]; }
};

using Graph = vector<vector<int>>;
vector<int> visited(false);

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

void dfs(const Graph &G, int v) {
  visited[v] = true;
  for (auto next : G[v]) {
    if (visited[next]) continue;
    dfs(G, next);
  }
}

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

// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

ll gcd2(const vector<ll> &v) {
  ll val = v[0];
  for (ll i = 1; i < v.size(); ++i) val = gcd(val, v[i]);
  return val;
}

ll lcm2(const vector<ll> &v) {
  ll val = v[0];
  for (ll i = 1; i < v.size(); ++i) val = lcm(val, v[i]);
  return val;
}

vector<ll> divisors(ll n) {
  vector<ll> a;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      a.push_back(i);
      if (n / i != i) a.push_back(n / i);
    }
  }
  sort(a.begin(), a.end());
  return a;
}

// pairを要素に持つvectorをsecondを基準にソートする比較関数
bool comp(pair<ll, ll> a, pair<ll, ll> b) { return a.second < b.second; }

vector<int> eratosthenes(int n) {
  vector<bool> is_prime(n + 1, true);
  vector<int> p;
  for (int i = 2; i <= n; ++i) {
    if (is_prime[i]) {
      for (int j = i * 2; j <= n; j += i) {
        is_prime[j] = false;
      }
      p.push_back(i);
    }
  }
  return p;
}

int main() {
  vector<int> a(3);
  rep(i, 3) cin >> a[i];
  sort(all(a));
  if ((a[0] == a[1] && a[1] == a[2]) || (a[2] - a[1] == a[1] - a[0]))
    cout << yes << endl;
  else
    cout << no << endl;
  // cout << fixed << setprecision(9) << ans << endl;
}


#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define REP2(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = (l), i##_len = (int)(r); i < i##_len; ++i)
#define GET_MACRO_REP(_1, _2, _3, NAME, ...) NAME
#define REP(...) GET_MACRO_REP(__VA_ARGS__, REP3, REP2) (__VA_ARGS__)
#define RREP2(i, n) for (int i = (n - 1); i >= 0; --i)
#define RREP3(i, l, r) for (int i = (r - 1), i##_len = (l); i >= i##_len; --i)
#define GET_MACRO_RREP(_1, _2, _3, NAME, ...) NAME
#define RREP(...) GET_MACRO_REP(__VA_ARGS__, RREP3, RREP2) (__VA_ARGS__)
#define IN(type, n) type n; cin >> n
#define INALL(v) for (auto &e : v) { cin >> e; }
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#ifdef _DEBUG
#define DEBUG(x) cout << #x << ": " << x << endl
#else
#define DEBUG(x)
#endif

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; }
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
#pragma endregion

int main() {
  IN(int, N);
  IN(int, M);
  vector<ll> As(N);
  INALL(As);
  vector<vector<int> > citis(N, vector<int>());
  REP(i, M) {
    IN(int, X);
    IN(int, Y);
    X--;
    Y--;
    citis.at(Y).emplace_back(X);
  }

  vector<ll> maxs(N, -10000000000);
  RREP(i, N) {
    for (auto &city : citis.at(i)) {
      chmax(maxs.at(city), max(As.at(i), maxs.at(i)));
    }
  }

  ll ans = -10000000000;
  REP(i, N) {
    chmax(ans, maxs.at(i) - As.at(i));
    // cout << "i: " << i << ", A: " << As.at(i) << ", max: " << maxs.at(i) << ", cal: " << maxs.at(i) - As.at(i) << ", ans: " << ans << endl;
  }

  cout << ans << endl;

  return 0;
}

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

#define  int               long long int
#define  ld                long double
#define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)           for(int i = n; i >= j; i--)
#define  all(container)       container.begin() , container.end()
#define  sz(container)        (int)container.size()
#define  ff                first
#define  ss                second
#define  pii               pair <int , int>
#define  sp(x)              setprecision(x)
#define  mod              1000000007
#define  endl            "\n"
#define  pb              push_back
#define  mp             make_pair
#define  T             int ttt; cin >> ttt; while(ttt--)
#define fast           ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int n,e,a[18][3],dp[18][600005];
int solve(int i,int mask){
    if(mask==e)   return ( abs(a[0][0]-a[i][0]) + abs(a[0][1]-a[i][1]) + max(0LL ,a[0][2]-a[i][2]));
    int &x = dp[i][mask];
    if(x!=1e18)  return x;
    f(j,0,n-1)
    {
        if( (mask & (1LL<<j)) ==0){
            int c= abs(a[j][0]-a[i][0]) + abs(a[i][1]-a[j][1]) + max(0LL ,a[j][2]-a[i][2]);
            x =min(x,solve(j,mask ^ (1LL<<j) ) + c);
        }
    }
    return x;
}

int32_t main()
{
    fast
    cin>>n;
    e= 1ll<<n;  e--;
    f(i,0,n)
        f(j,0,e)
            dp[i][j]=1e18;
    f(i,0,n-1)
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    cout<<solve(0,1LL<<0LL)<<endl;
}


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

const int INF = 1000000001;

void chmin(int& x, int y){
  x = min(x,y);
}

int main() {

  int N;
  cin >> N;

  vector<int> X(N);
  vector<int> Y(N);
  vector<int> Z(N);

  for (int i = 0; i < N; ++i) {
    cin >> X[i] >> Y[i] >> Z[i];
  }

  int N2 = 1<<N;

  vector<vector<int>> dp(N2, vector<int>(N, INF));
  vector<vector<int>> dist(N, vector<int>(N));

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      int current = abs(X[i]-X[j]);
      current += abs(Y[i]-Y[j]);
      current += max(0, Z[j]-Z[i]);
      dist[i][j] = current;
    }
  }

  for (int i = 0; i < N; ++i) {
    if (i == 0) {
      continue;
    }
    dp[1<<i][i] = dist[0][i];
  }

  for (int i = 0; i < N2; ++i) {
    for (int j = 0; j < N; ++j) {
      if (~i>>j&1) {
        continue;
      }
      for (int k = 0; k < N; ++k) {
        if (i>>k&1) {
          continue;
        }
        chmin(dp[i|1<<k][k], dp[i][j] + dist[j][k]);
      }
    }
  }

  cout << dp[N2 - 1][0] << endl;
  return 0;

}

#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define First(n) cout << ((n) ? "First" : "Second"  ) << endl
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define vl vector<ll>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) {
  if(a < b) return GCD(b, a);
  if(b==0){
      return a;
  }else{
      return GCD(b,a%b);
  }
}
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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }
ll MOD=1e9+7;

const int MAXN=17;
int n;
int d[MAXN][MAXN];
int dp[1<<MAXN][MAXN];

int rec(int S, int v) {
    if(dp[S][v] >= 0) return dp[S][v];
    if(S==(1<<n)-1 && v==0) return dp[S][v]=0;
    int tmp=MOD;
    rep(u,n) if(!(S>>u & 1)) tmp=min(tmp, rec(S|1<<u,u)+d[v][u]);
    return dp[S][v]=tmp;
}

int main() {
    cin>>n;
    vl x(n);
    vl y(n);
    vl z(n);
    rep(i,n)cin>>x[i]>>y[i]>>z[i];
    rep(i,n) rep(j,n) d[i][j]=d[j][i]=MOD;
    rep(i,n){
        rep(j,n){
            if(i!=j)d[i][j]=abs(x[j]-x[i])+abs(y[j]-y[i])+max(0LL,z[j]-z[i]);
        }
    }
    fill((int *)dp, (int *)(dp+(1<<MAXN)), -1);
    cout << rec(0,0) << endl;
}


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

using namespace std;
using ll =long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;

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; }
const long long INF = 1LL << 60;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define fr(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){

  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}

vi dx= {0,-1,0,1};
vi dy= {1,0,-1,0};

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//cout<<""<<endl;

int main(){
  ll N;cin>>N;
  vl a(1000004);
  ll cnt=0;
  for(ll i=1;i*i<=2*N;i++){
    if((2*N)%i!=0)continue;
    ll A=i,B=2*N/i;
      if((B+A-1)%2==0&&(B-A-1)%2==0)cnt++;
  }
  cout<<2*cnt<<endl;

}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

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

	int n;
	cin >> n;
	int ans = 0;
	for(int i = 1; i * i <= 2 * n; i++) {
		if((2 * n) % i == 0 && ((i + ((2 * n) / i)) & 1)) {
			ans += 2;
		}
	}
	cout << ans;

	return 0;
}


#include <bits/stdc++.h>
#define MAX 1000005
#define M 1000000000
using namespace std;
#define ll long long int
// bool prime[MAX+1];
// ll ans[MAX];

// void seive()
// {

//     memset(prime, true, sizeof(prime));

//     for (int p=2; p*p<=MAX; p++)
//     {

//         if (prime[p] == true)
//         {

//             for (int i=p*p; i<=MAX; i += p)
//                 prime[i] = false;
//         }
//     }
// }
// void solve()
// {

// }
int main()
{
	int n, ans = -1;
  ll x, c = 0;
  cin >> n >> x;
  x *= 100;
  for (int i = 1; i <= n; i++) {
    ll v, p;
    cin >> v >> p;
    c += v * p;
    if (c > x && ans == -1) ans = i;
  }
  cout << ans << endl;
	return 0;
}

#include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <string>
#include <cstring>
#include <cassert>
#include <iomanip>
#include <algorithm>
#include <set>
#include <map>
#include <ctime>
#include <cmath>

using namespace std;

#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'

#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pt pair<int, int>

#define forf(i, a, b) for (int i = (a); i < (b); i++)
#define forb(i, a, b) for (int i = (b); i >= (a); i--)
#define fo(i, n) forf(i, 0, n)
#define fob(i, n) forb(i, 0, n - 1)

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;

using namespace std;

const int INF = 1000 * 1000 * 1000;
const int EPS = 1e-9;
const int PI = acos(-1.0);

int32_t main () {
    fastio
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cerr << setprecision(10) << fixed;
    int n,x;
    cin >> n >> x;
    x = x*100;
    vi a;
    forf(i,0,n)
    {
        int v,p;
        cin >> v >> p;
        a.pb(v*p);
    }
    int sum = 0;
    forf(i,0,n)
    {
        sum += a[i];
        if(sum > x)
        {
            cout << i + 1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}

const ll MAXN=1e2+5,MAXlg=__lg(MAXN)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;
const int MAXM = 1e4+5;

vector<pii> edge;
int c[MAXN], ans[MAXM]; // 0:-> 1:<-
vector<pii> e[MAXN];
bool vis[MAXN];
void print(int x){
    if (x) cout << "<-" << endl;
    else cout << "->" << endl;
}
void dfs(int x){
    vis[x] = true;
    for (auto i:e[x]) {
        pii cur = edge[i.X];
        int to;
        if (i.Y == 0) to = cur.Y;
        else to = cur.X;
        ans[i.X] = i.Y;
        if (vis[to]) continue;
        dfs(to);
    }
}
signed main(){
    IOS();
    int n,m;
    cin >> n >> m;
    for (int i=0;i<m;++i) {
        int u,v;
        cin >> u >> v;
        u--, v--;
        edge.eb(u,v);
        ans[i] = -1;
    }
    for (int i=0;i<n;++i) cin >> c[i];
    for (int i=0;i<m;++i) {
        int u = edge[i].X, v = edge[i].Y;
        if (c[u] == c[v]) {
            e[u].eb(i,0);
            e[v].eb(i,1);
            continue;
        }
        if (c[u] > c[v]) ans[i] = 0;
        else ans[i] = 1;
    }
    for (int i=0;i<n;++i) {
        if (vis[i]) continue;
        dfs(i);
    }
    for (int i=0;i<m;++i) print(ans[i]);
}

#include <bits/stdc++.h>

using namespace std;

const int max_n = 11, inf = 1000111222;
const int max_m = 100011;

int n, m, a[max_n], dp[max_n][max_n];
pair<int, int> b[max_m];
vector<pair<int, int>> v;

int solve() {
    for (int i = 0; i < n; ++i) {
        if (a[i] > v[0].first) {
            return inf;
        }
    }
    for (int len = 1; len <= n; ++len) {
        for (int l = 0; l + len <= n; ++l) {
            const int r = l + len - 1;
            int tot = accumulate(a + l, a + r + 1, 0);
            auto it = upper_bound(v.begin(), v.end(), make_pair(tot, -1));
            dp[l][r] = 0;
            if (it != v.begin()) {
                --it;
                dp[l][r] = it->second;
            }
            for (int i = l + 1; i < r; ++i) {
                dp[l][r] = max(dp[l][r], dp[l][i] + dp[i][r]);
            }
            //cout << l << " " << r << ": " << dp[l][r] << endl;
        }
    }
    return dp[0][n - 1];
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < m; ++i) {
        cin >> b[i].second >> b[i].first;
    }
    sort(b, b + m);
    for (int i = 0; i < m; ++i) {
        if (v.empty() || v.back().second < b[i].second) {
            v.push_back(b[i]);
        }
    }
    sort(a, a + n);
    int ans = inf;
    do {
        ans = min(ans, solve());
    } while (next_permutation(a, a + n));
    if (ans == inf) {
        ans = -1;
    }
    cout << ans << "\n";
    return 0;
}


#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define pb push_back
#define S second
#define F first
//#define int long long int
#define endl			"\n"
ll MOD=1e9+7;

void solve() {
	ll x,y;
	cin>>x>>y;
	ll k=min(x,y)+3;
	ll m=max(x,y);
	if(k>m)
	cout<<"Yes"<<endl;
	else
	cout<<"No";

}

signed main(){
        FS;

    int t=1;

    //cin >> t;

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

    return 0;
}

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

int main(){
	int A, B;
	cin>>A>>B;
	if(A<B&&A+3>B||B<A&&B+3>A) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

}


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

ll f(ll k){
    return k*(k+1)/2;
}

bool ok(ll k){
    return f(k) <= n+1 and n+1 < f(k+1);
}

int main(void){
    cin >> n;
    ll left = 1, right = n, k;
    while(true){
        ll m = (left+right)/2;
        if(m<=2*(n+1)/(m+1) and 2*(n+1)/(m+1)<m+2){
            k = m;
            break;
        } else if(m+1<2*(n+1)/m){
            left = m+1;
        } else {
            right = m-1;
        }
    }
    cout << n-k+1 << endl;
    return 0;
}
/*
 * 109109109109109109
 * 109109108641970782
 */

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

/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair

/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())

/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;

/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  vi a(4);
  rep(i, 4) cin >> a[i];

  sort(all(a));
  int sum = accumulate(all(a),0);

  do {
    int s = 0;
    rep(i, 4) {
      s += a[i];
      int eat = sum - s;

      if (s == eat) {
        cout << "Yes" << endl;
        return 0;
      }
    }

  } while (next_permutation(all(a)));

  cout << "No" << endl;
}


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

const int MAX_N = 2e5, MOD = 998244353, INF = 1e9;
int h, w, k, ans[5000][5000], cntx[5000][5000], cnty[5000][5000], po3[5001];
P p[MAX_N];
char c[MAX_N];

int main() {
    ci3(h, w, k);
    rep(i, k) {
        int x, y;
        char z;
        ci3(x, y, z);
        cntx[x - 1][y - 1]--;
        cnty[x - 1][y - 1]--;
        p[i].fi = (x - 1) * w + y - 1;
        p[i].se = i;
        c[i] = z;
    }
    rep(i, h) rep(j, w) {
        cntx[i][j]++;
        cnty[i][j]++;
    }
    po3[0] = 1;
    rep(i, 5000) po3[i + 1] = 3L * po3[i] % MOD;
    rep(i, w) rep(j, h - 1) cntx[j + 1][i] += cntx[j][i];
    rep(i, h) rep(j, w - 1) cnty[i][j + 1] += cnty[i][j];
    sort(p, p + k);
    int ind = 0;
    ans[0][0] = 1;
    rep(i, h) {
        rep(j, w) {
            if (ind < k && i == p[ind].fi / w && j == p[ind].fi % w) {
                if (c[p[ind].se] != 'D' && j < w - 1) {
                    ans[i][j + 1] =
                    (ans[i][j + 1] + scll(ans[i][j]) *
                    po3[cntx[h - 1][j] - cntx[i][j]] % MOD) % MOD;
                }
                if (c[p[ind].se] != 'R' && i < h - 1) ans[i + 1][j] =
                    scll(ans[i][j]) * po3[cnty[i][w - 1] - cnty[i][j]] % MOD;
                ind++;
                continue;
            }
            if (j < w - 1)
                ans[i][j + 1] = (ans[i][j + 1] + 2L * ans[i][j] *
                po3[cntx[h - 1][j] - cntx[i][j]] % MOD) % MOD;
            if (i < h - 1) ans[i + 1][j] = 2L * ans[i][j] *
                po3[cnty[i][w - 1] - cnty[i][j]] % MOD;
        }
    }
    if (k == 0 || p[k - 1].fi != h * w - 1)
        ans[h - 1][w - 1] = 3L * ans[h - 1][w - 1] % MOD;
    co(ans[h - 1][w - 1]);
    return 0;
}

// Author: wlzhouzhuan
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fir first
#define sec second
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, t) memset(s, t, sizeof(s))
#define mcpy(s, t) memcpy(s, t, sizeof(t))
template<typename T1, typename T2> void ckmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> void ckmax(T1 &a, T2 b) { if (a < b) a = b; }
int read() {
  int x = 0, f = 0; char ch = getchar();
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();
  return f ? -x : x;
}
template<typename T> void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
template<typename T> void print(T x, char let) {
  print(x), putchar(let);
}

const int N = 5005;
const int mod = 998244353;
const int inv3 = (mod + 1) / 3;

char a[N][N];
// 0->R, 1->D, 2->X
int dp[N][N][3];
int n, m, k;

void add(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
int mul(int x, int y) {
  return 1ll * x * y % mod;
}
int qpow(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) res = 1ll * res * a % mod;
    a = 1ll * a * a % mod;
    b >>= 1;
  }
  return res;
}
int main() {
  n = read(), m = read(), k = read();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      a[i][j] = '?';
    }
  }
  for (int i = 1; i <= k; i++) {
    int x = read(), y = read();
    char str[3];
    scanf("%s", str);
    a[x][y] = str[0];
  }
  if (a[1][1] == 'X') dp[1][1][2] = 1;
  else if (a[1][1] == 'R') dp[1][1][0] = 1;
  else if (a[1][1] == 'D') dp[1][1][1] = 1;
  else dp[1][1][0] = dp[1][1][1] = dp[1][1][2] = 1;
  if (a[1][1] == '?') k++;
  dp[1][1][0] = mul(dp[1][1][0], qpow(3, n * m - k));
  dp[1][1][1] = mul(dp[1][1][1], qpow(3, n * m - k));
  dp[1][1][2] = mul(dp[1][1][2], qpow(3, n * m - k));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == '?') {
        if (i > 1) {
          add(dp[i][j][0], 1ll * dp[i - 1][j][1] * inv3 % mod);
          add(dp[i][j][1], 1ll * dp[i - 1][j][1] * inv3 % mod);
          add(dp[i][j][2], 1ll * dp[i - 1][j][1] * inv3 % mod);
          add(dp[i][j][0], 1ll * dp[i - 1][j][2] * inv3 % mod);
          add(dp[i][j][1], 1ll * dp[i - 1][j][2] * inv3 % mod);
          add(dp[i][j][2], 1ll * dp[i - 1][j][2] * inv3 % mod);
        }
        if (j > 1) {
          add(dp[i][j][0], 1ll * dp[i][j - 1][0] * inv3 % mod);
          add(dp[i][j][1], 1ll * dp[i][j - 1][0] * inv3 % mod);
          add(dp[i][j][2], 1ll * dp[i][j - 1][0] * inv3 % mod);
          add(dp[i][j][0], 1ll * dp[i][j - 1][2] * inv3 % mod);
          add(dp[i][j][1], 1ll * dp[i][j - 1][2] * inv3 % mod);
          add(dp[i][j][2], 1ll * dp[i][j - 1][2] * inv3 % mod);
        }
      } else {
        if (i > 1) {
          add(dp[i][j][0], dp[i - 1][j][1]);
          add(dp[i][j][1], dp[i - 1][j][1]);
          add(dp[i][j][2], dp[i - 1][j][1]);
          add(dp[i][j][0], dp[i - 1][j][2]);
          add(dp[i][j][1], dp[i - 1][j][2]);
          add(dp[i][j][2], dp[i - 1][j][2]);
        }
        if (j > 1) {
          add(dp[i][j][0], dp[i][j - 1][0]);
          add(dp[i][j][1], dp[i][j - 1][0]);
          add(dp[i][j][2], dp[i][j - 1][0]);
          add(dp[i][j][0], dp[i][j - 1][2]);
          add(dp[i][j][1], dp[i][j - 1][2]);
          add(dp[i][j][2], dp[i][j - 1][2]);
        }
      }
      if (a[i][j] == 'R') dp[i][j][1] = dp[i][j][2] = 0;
      if (a[i][j] == 'D') dp[i][j][0] = dp[i][j][2] = 0;
      if (a[i][j] == 'X') dp[i][j][0] = dp[i][j][1] = 0;
      //printf("dp[%d][%d] = %d %d %d\n", i, j, dp[i][j][0], dp[i][j][1], dp[i][j][2]);
    }
  }
  printf("%d\n", (((long long)dp[n][m][0] + dp[n][m][1]) % mod + dp[n][m][2]) % mod);
  return 0;
}


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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
    string sep = " ";
    if(v.size()) os << v[0];
    for(int i=1; i<v.size(); i++) os << sep << v[i];
    return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
    for(int i=0; i<v.size(); i++) is >> v[i];
    return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
    cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

void solve(){
    string s; cin >> s;
    int ans = 1e9;
    int m = 0;
    for(auto c: "atcoder") {
        int x=-1, y=-1;
        for(int i=0; i<s.size(); i++){
            if(s[i]>=c+1){
                x=i;
                break;
            }
        }
        if(x>=0) ans = min(ans, x+m);
        for(int i=0; i<s.size(); i++){
            if(s[i]>=c){
                y=i;
                break;
            }
        }
        if(y>=0){
            m += y;
            s = s.substr(0, y) + s.substr(y+1);
        } else {
            break;
        }
    }

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

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(20) << fixed;
    int t; cin >> t;
    for(int i=0; i<t; i++) solve();
    return 0;
}

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <memory.h>
#include <cmath>

using namespace std;

#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define FOR0(i,n) for( i = 0 ; i < n ; ++i )
#define FOR1(i,n) for( i = 1 ; i <= n ; ++i )
#define sys_p system( "pause" )
#define pb push_back
#define mp make_pair
#define FI first
#define SE second
#define sz(a) (int)a.size()

typedef long long LL;

const LL MOD = (LL)(1e9 + 7);

int t, i, j, found[7], ans1, ans2;
string s, x = "atcoder";

int main() {
    cin >> t;

    while (t--) {
        cin >> s;

        FOR0(i, 7) {
            found[i] = -1;
        }

        ans1 = ans2 = 1e9;

        // option 1: atcoderXXX
        if (s.length() > 7) {
            FOR0(i, s.length()) {
                char c = s[i];
                FOR0(j, 7) {
                    if (c == x[j] && ((found[j] < 0) || abs(i - j) < abs(i - found[j]))) {
                        found[j] = i;
                    }
                }
            }

            ans1 = 0;
            FOR0(j, 7) {
                if (found[j] < 0) {
                    ans1 = 1e9;
                    break;
                }
                else {
                    ans1 += abs(found[j] - j);
                }
            }

        }

        // option 2: put larger letter somewhere
        int prev_cost = 0;
        FOR0(j, 7) {
            for (i = j; i < s.length(); ++i) {
                if (s[i] > x[j]) {
                    ans2 = min(ans2, prev_cost + i - j);
                    break;
                }
            }

            for (i = j; i < s.length(); ++i) {
                if (s[i] == x[j]) {
                    s.erase(i, 1);
                    s.insert(j, 1, x[j]);
                    prev_cost += i - j;
                    break;
                }
            }

            if (i == s.length()) {
                break;
            }
        }

        if (min(ans1, ans2) > 1e8) {
            cout << -1 << endl;
        }
        else {
            cout << min(ans1, ans2) << endl;
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const double pi=3.1415926535897932384626;
inline ll read(){
	ll 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<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
const ll mod=998244353;
const int maxn=5e2+5;
ll n,m;
char s[maxn][maxn];
ll q_pow(ll x,ll y){
    ll ans=1;
    while(y){
        if(y&1) ans=ans*x%mod;
        y>>=1;
        x=x*x%mod;
    }
    return ans;
}
int main(){
    n=read(),m=read();
    for(int i=1;i<=n;++i) scanf("%s",s[i]+1);
    ll cnt=0,flag=1;
    for(int i=1;i<=n;++i){
        int x=i,y=1,r=0,b=0,tmp=0;
        while(x>=1&&y<=m){
            if(s[x][y]=='.') ++tmp;
            else if(s[x][y]=='R') r=1;
            else b=1;
            --x;
            ++y;
        }
        if(r==1&&b==1) flag=0;
        else if(r+b==0&&tmp) ++cnt;
    }
    for(int i=2;i<=m;++i){
        int x=n,y=i,r=0,b=0,tmp=0;
        while(x>=1&&y<=m){
            if(s[x][y]=='.') ++tmp;
            else if(s[x][y]=='R') r=1;
            else b=1;
            --x;
            ++y;
        }
        if(r==1&&b==1) flag=0;
        else if(r+b==0&&tmp) ++cnt;
    }
    if(!flag) printf("0\n");
    else printf("%lld\n",q_pow(2,cnt));
    return 0;
}

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

int main(){
  int h, w; cin >> h >> w;
  const int mod = 998244353;
  string tmp;
  vector<vector<char>> grid(h, vector<char>(w));
  for(int i = 0; i < h; ++i){
    cin >> tmp;
    for(int j = 0; j < w; ++j){grid[i][j] = tmp[j];}
  }

  vector<vector<int>> state(h+w-1, vector<int>(3)); // ["R", "B", "."]
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      if(grid[i][j] == 'R'){state[i+j][0] += 1;}
      if(grid[i][j] == 'B'){state[i+j][1] += 1;}
      if(grid[i][j] == '.'){state[i+j][2] += 1;}
    }
  }

  int ans = 1;
  for(int i = 0; i < h+w-1; ++i){
    if(state[i][0] == 0 && state[i][1] == 0){ans *= 2;}
    if(state[i][0] != 0 && state[i][1] != 0){ans *= 0;}
    ans %= mod;
  }
  cout << ans << endl;
}


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

constexpr int MAX_N = 100000;

int n, m;
vector<pair<int, int>> G[MAX_N];
int ans[MAX_N];
bool reached[MAX_N];

void dfs(int cur) {
    reached[cur] = true;
    for (auto p : G[cur]) {
        if (reached[p.first]) continue;
        if (ans[cur] != p.second)
            ans[p.first] = p.second;
        else
            ans[p.first] = (p.second + 1) % n + 1;
        dfs(p.first);
    }
}

signed main() {
    cin >> n >> m;
    int u, v, c;
    rep(i, m) {
        cin >> u >> v >> c;
        u--;
        v--;
        G[u].emplace_back(v, c);
        G[v].emplace_back(u, c);
    }
    ans[0] = 1;
    dfs(0);
    rep(i, n) {
        cout << ans[i] << endl;
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 1;

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

void solve() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int u, v, c;
        cin >> u >> v >> c;
        g[u].emplace_back(v, c);
        g[v].emplace_back(u, c);
    }
    vector<int> color(n + 1);
    set<int> colors;
    for (int i = 1; i <= n; ++i) {
        colors.insert(i);
    }
    vector<int> used(n + 1);
    queue<int> q;
    used[1] = 2;
    for (auto &[u, c] : g[1]) {
        q.push(u);
        used[u] = 1;
    }
    while (!q.empty()) {
        int v = q.front(); q.pop();
        used[v] = 2;
        for (auto& [u, c] : g[v]) {
            if (used[u] == 2 && color[u] != c) {
                color[v] = c;
            } else if (!used[u]) {
                q.push(u);
                used[u] = 1;
            }
        }
        if (!color[v]) {
            color[v] = *colors.begin();
        }
        colors.erase(color[v]);
    }
    color[1] = *colors.begin();
    for (int i = 1; i <= n; ++i) {
        cout << color[i] << "\n";
    }
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);

    solve();
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    long long n, m, q;
    long long w[100],v[100];
    vector<long long> x(100);
    vector<long long> tempx(100);
    long long max = 0;
    long long l,r;
    vector<pair<long long, long long>> p(100);
    cin >> n >> m >> q;
    for (long long i = 0; i < n; i++){
        p[i] = make_pair(0,0);
    }
    for (long long i = 0; i < n; i++){
        cin >> w[i] >> v[i];
        p[i].first = v[i];
        p[i].second = -w[i];
//        p[i] = make_pair(v[i],-w[i]);
    }
    for (long long i = 0; i < m; i++){
        cin >> x[i];
    }
    sort(p.begin(),p.end());
    for (long long i = 0; i < q ; i++){
        max = 0;
        cin >> l >> r;
        for (long long j  = 0; j < 100;j++){ //壊れた箱の処理
            if ((j < (l-1)) || (j > (r-1))){
                tempx[j] = x[j];
            } else{
                tempx[j] = 0;
            }
        }
        sort(tempx.begin(),tempx.end());
        for (long long j = 0; j < n; j++){
            for (long long k = 0; k < 100;k++){
                if (tempx[k] >= (-p[100-j-1].second)){
                    tempx[k] =0;
                    max += p[100-j-1].first;
                    break;
                }
            }
        }
        cout << max << endl;
    }
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define mp make_pair
#define ins insert
#define sz(x) (int)x.size()
#define whoami(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); whi(_it, args); }

void whi(istream_iterator<string> it) { cerr<<"\n"; }

template<typename T, typename... Args>
void whi(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<" "<<a<<" "; whi(++it, args...); }

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed); cerr.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed); cerr.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

const int MOD = 1000000007;
const ll INF = 4e18;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
//ordered_set = order_of_key(.)
//ordered_set = find_by_order(.)
typedef ordered_set<int> OSI;
typedef ordered_set<ll> OSL;
typedef ordered_multiset<int> MOSI;
typedef ordered_multiset<ll> MOSL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV];
PII bag[MV];

void solve(int T)
{
	int n,m,q;
	cin>>n>>m>>q;
	for(int i=1;i<=n;i++)
	cin>>bag[i].ff>>bag[i].ss;
	sort(bag+1, bag+n+1, [](PII A, PII B){ return (A.ss > B.ss); });
	for(int i=1;i<=m;i++)
	cin>>ar[i];
	while(q--)
	{
		int l,r;
		cin>>l>>r;
		multiset<int> M;
		for(int i=1;i<l;i++)
		M.ins(ar[i]);
		for(int i=r+1;i<=m;i++)
		M.ins(ar[i]);
		int tt = 0;
		for(int i=1;i<=n;i++)
		{
			if(M.lower_bound(bag[i].ff) != M.end())
			{
				tt += bag[i].ss;
				M.erase(M.lower_bound(bag[i].ff));
			}
		}
		cout<<tt<<"\n";
	}
	return;
}

int main(void)
{
	FLASH();
	//freopen("cowjog.in", "r", stdin);
	//freopen("cowjog.out", "w", stdout);
	int T;
	T = 1;

#ifndef ONLINE_JUDGE
	time_t time_t1, time_t2;
	time_t1 = clock();
#endif

	//cin>>T;
	while(T--)
	solve(T);

#ifndef ONLINE_JUDGE
	time_t2 = clock();
	SETF();
	cerr<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
	UNSETF();
#endif

	return 0;
}


// 2021-04-19 00:32:20
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

// clang-format on
const int MX = 400040;
int n, c2[MX], c3[MX], x2, x3, y2, y3, z2, z3;
string s;
void answer() {
  cin >> n >> s;
  REPC(i, 1, n) {
    int j = i;
    while (j % 3 == 0) {
      c3[i]++;
      j /= 3;
    }
    if (j % 3 == 2) c2[i]++;
  }
  rep(i, n) {
    x2 += c2[i];
    x3 += c3[i];
    y2 += c2[i];
    y3 += c3[i];
  }
  int ans = 0;
  rep(i, n) {
    if (x3 == y3 + z3) {
      int color = 0;
      if (s[i] == 'B') color = 0;
      if (s[i] == 'W') color = 1;
      if (s[i] == 'R') color = 2;
      if ((x2 + y2 + z2) % 2) {
        ans += color * 2;
      } else {
        ans += color * 1;
      }
      ans %= 3;
    }
    y2 -= c2[n - i - 1];
    y3 -= c3[n - i - 1];
    z2 += c2[i + 1];
    z3 += c3[i + 1];
  }
  rep(i, n - 1) { (ans *= 2) %= 3; }
  if (ans == 0) cout << 'B' << '\n';
  if (ans == 1) cout << 'W' << '\n';
  if (ans == 2) cout << 'R' << '\n';
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=4e5+1000;
typedef long long LL;
const LL mod=3;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
map<char,LL>map1;
LL fac[maxn];
LL ksm(LL a,LL k){
   LL res=1;
   while(k>0){
      if(k&1) res=res*a%mod;
      k>>=1;
      a=a*a%mod;
   }return res%mod;
}
LL C(LL n,LL m){
   if(m>n) return 0;
   return (fac[n]*ksm(fac[m],mod-2)%mod*ksm(fac[n-m],mod-2)%mod)%mod;
}
LL lucas(LL n,LL m){
    if(!m) return 1;
    return C(n%mod,m%mod)*lucas(n/mod,m/mod)%mod;
}
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   fac[0]=1;
   for(LL i=1;i<=3;i++) fac[i]=fac[i-1]*i%mod;
   map1['B']=0;map1['W']=1;map1['R']=2;
   LL n;cin>>n;
   LL ans=0;
   for(LL i=0;i<n;i++){
      char op;cin>>op;
      LL d=map1[op];
      ans=(ans+d*lucas(n-1,i))%mod;
   }
   if(n%2==0) ans=(3-ans)%3;///ans*=(-1)^(n-1)
   if(ans==0){
      cout<<"B"<<"\n";
   }
   else if(ans==1){
      cout<<"W"<<"\n";
   }
   else if(ans==2){
      cout<<"R"<<"\n";
   }
   return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    cin >> res;
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int main(){
    cout << (in()%2?"Black":"White") << endl;
  return 0;
}

#include <iostream>
#include <string>

using namespace std;
using ll = int64_t;

ll n, k;

ll numar(ll x)
{
    ll g1 = 0, g2 = 0;
    int c[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

    while(x)
        c[x % 10]++, x /= 10;

    for(int i = 0 ; i < 10 ; i++) for(int j = 1 ; j <= c[i] ; j++) g1 = g1 * 10 + i;
    for(int i = 9 ; i >= 0 ; i--) for(int j = 1 ; j <= c[i] ; j++) g2 = g2 * 10 + i;

    return g2 - g1;
}

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

    for(int i = 1 ; i <= k ; i++)
        n = numar(n);

    cout << n;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long double ld;
typedef long long ll;
using P = pair<ll,int>;
const char EOLN = '\n';
#define rep(i,n) for (int i = 0; i < (n); ++i)
// DP
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; }

// 定数
#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 1000000007 //問題による
const double pi = 3.14159265359;

// メモ
// vector二次元配列
// vector<vector<ll>> cnt(h,vector<ll> (w));
// bit演算
// for (int bit = 0; bit < (1<<k); ++bit)
// bit & (1 << i)
// 複数変数をいっきに代入
// tie(a,b,c) = make_tuple(10, 7.7, "hello");
// index が条件を満たすかどうか
struct Edge{
    int to,t,k;
    Edge(int to,int t,int k): to(to),t(t),k(k){}
};

int main()
{
    int N,M,XX,YY;
    cin>>N>>M>>XX>>YY;
    XX--;YY--;
    vector<vector<Edge>> G(N);
    for(int i=0;i<M;i++){
        int a,b,t,k;
        cin>>a>>b>>t>>k;
        a--;b--;
        G[a].emplace_back(b,t,k);
        G[b].emplace_back(a,t,k);
    }

    vector<ll> dist(N,INF64); //dp
    priority_queue<P,vector<P>,greater<P>> X;
    X.push({0,XX});
    //queueが空になるまでroop
    while(!X.empty()){
        ll curcost=X.top().first;
        int from=X.top().second;
        X.pop();    //queueから1つ取り出す
        if(dist[from]<curcost) continue;
        for(auto x:G[from]){    //Gの行ける場所を調査
            ll nx = (curcost+x.k-1)/x.k*x.k + x.t;
            if(chmin(dist[x.to],nx)){  //Update
                //X.push({nx,x.to});    //調査対象の取り出し
                X.push({dist[x.to],x.to});
            }
        }
    }
    ll ans = dist[YY];
    if(ans==INF64) ans=-1;
    cout <<ans;
    return 0;
}

#if _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#ifndef ONLINE_JUDGE
const bool DEBUG = true;
#else
const bool DEBUG = false;
#endif

// Reads a 1D vector
template <class T>
void read1d(vector<T> & arg) {
	const int l = arg.size();
	for (int i = 0; i < l; ++i) cin >> arg[i];
}

void read() {}
// Reads arbitrary values
template <class T1, class... T2>
void read(T1& var1, T2&... var2) { cin >> var1; read(var2...); }

void pln() { cout << (DEBUG ? "]\n" : "\n"); }
template <class T1, class... T2>
void pln(const T1& var1, const T2& ... var2) { cout << var1 << " "; pln(var2...); }

// Prints arbitrary values and goes to next line
template <class T1, class... T2>
constexpr void print(const T1& var1, const T2& ... var2) { cout << (DEBUG ? " [ " : ""); pln(var1, var2...); }

// Prints arbitrary values and goes to next line ONLY IF IN DEBUG MODE
template <class T1, class... T2>
constexpr void debug(const T1& var1, const T2& ... var2) { if (!DEBUG) return;  cout << " debug : [ "; pln(var1, var2...); }

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define all(x) begin(x), end(x)

const bool MULTIPLE_TEST_CASES = 0;

struct Edge {
	ll wt;
	ll mul;

	Edge() {}
	Edge(ll wt, ll mul) : mul(mul), wt(wt) { }
};

void exec()
{
	int n, m;
	read(n, m);
	int x, y;
	read(x, y);
	--x; --y;

	vector<unordered_map<int, vector<Edge>>> graph(n, unordered_map<int, vector<Edge>>());
	for (int i = 0; i < m; ++i) {
		int from, to, time, mul;
		read(from, to, time, mul);
		--from; --to;

		graph[from][to].push_back(Edge(time, mul));
		graph[to][from].push_back(Edge(time, mul));
	}

	auto cmp = [&](pair<ll, int>& a, pair<ll, int>& b) { return a < b; };

	vector<bool> vis(n, false);
	vector<ll> T(n, LLONG_MAX);
	priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> djk;

	//vis[x] = true;
	T[x] = 0;
	djk.push({ 0, x });

	for (int i = 0; i < n; ++i) {
		while (!djk.empty() && vis[djk.top().second]) djk.pop();
		if (djk.empty()) break;
		int root = djk.top().second;
		ll _T = djk.top().first;
		djk.pop();

		vis[root] = true;
		//if (root == y) break;

		for (auto& [node, edges] : graph[root]) {
			if (vis[node]) continue;

			ll reachingAt = LLONG_MAX;

			for (auto& edge : edges) {
				// when is the next train coming?
				ll nextTrain = (_T % edge.mul == 0 ? _T : ((_T / edge.mul) + 1) * edge.mul);
				// when we reaching?
				reachingAt = min(reachingAt, nextTrain + edge.wt);
			}

			if (reachingAt < T[node]) {
				T[node] = reachingAt;
				djk.push({ reachingAt, node });
			}
		}
	}

	if (T[y] == LLONG_MAX) print(-1);
	else print(T[y]);
}

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

	if (!MULTIPLE_TEST_CASES)
		exec();
	else {
		int n;
		cin >> n;

		while (n--) exec();
	}

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep1(i, n) for(int i=1; i<=(int)(n); i++)
#define rep2(i, n, m) for(int i=(int)n; i<=(int)m; i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> wi;
typedef vector<ll> vl;
typedef vector<vl> wl;
const ll inf=1LL<<60;
const ll mod=1000000007;

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

  int n, m, t;
  cin >> n >> m >> t;
  vi a(m), b(m);
  rep(i, m)cin >> a[i] >> b[i];

  int bt=n, f=0, e=0;
  rep(i, m){
  	bt-=a[i]-e;
  	if(bt<=0){
  		f=1;
  		break;
  	}
  	bt+=b[i]-a[i];
  	bt=min(n, bt);
  	e=b[i];
  }

  if(f==0&&bt-(t-e)>0)cout << "Yes\n";
  else cout << "No\n";

  return 0;
}

#include <stack>
#include <queue>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <tuple>
#include <cmath>
#include <random>
#include <algorithm>
#include <vector>
#include <iostream>
#include <fstream>
#include <chrono>
#include <numeric>

#define fio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define rng mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count())

#define ri(...) i64 __VA_ARGS__; rx(__VA_ARGS__)
#define rc(...) char __VA_ARGS__; rx(__VA_ARGS__)
#define rs(...) string __VA_ARGS__; rx(__VA_ARGS__)
#define rvi(x, n) vi x(n); cin >> x
#define rvvi(x, n, m) vvi x(n, vi(m)); cin >> x

#ifndef ONLINE_JUDGE
#define dbg(...) cerr << '[' << #__VA_ARGS__ << "]: "; dbg_log(__VA_ARGS__)
#else
#define dbg(...) ;;
#endif

#define fa(i, v) for (auto &i : v)
#define fi(i, n) for (i32 i = 0; i < n; i++)
#define fp(i, n) for (i32 i = 1; i < n; i++)
#define fr(i, n) for (i32 i = n - 1; i >= 0; i--)
#define fu(_i) ri(i); fi(_i, i)

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

typedef uint32_t u32;
typedef int32_t i32;
typedef uint64_t u64;
typedef int64_t i64;
#ifdef __SIZEOF_INT128__
typedef __uint128_t u128;
typedef __int128_t i128;
#endif
typedef vector<i64> vi;
typedef vector<vi> vvi;

template<typename T>
inline istream &operator>>(istream &in, vector<T> &v) {
    fa(x, v) in >> x;
    return in;
}

template<typename T>
inline ostream &operator<<(ostream &out, const vector<T> &v) {
    fa(x, v) out << x << ' ';
    return out;
}

template<typename T>
inline void rx(T &x) {
    cin >> x;
}

template<typename T, typename... R>
inline void rx(T &x, R &... l) {
    cin >> x;
    rx(l...);
}

template<typename T>
inline void dbg_log(const T &x) {
    cerr << x << endl;
}

template<typename T, typename... R>
inline void dbg_log(const T &x, const R &... l) {
    cerr << x << ", ";
    dbg_log(l...);
}

template<typename T>
inline void wl(const T &x) {
    cout << x << '\n';
}

template<typename T, typename... R>
inline void wl(const T &x, const R &... l) {
    cout << x << ' ';
    wl<R...>(l...);
}

int main() {
    fio;

    ri(n, m, q);
    vector<tuple<i32, i32>> vs(n);
    fi(i, n) {
        ri(w, v);
        vs[i] = {v, w};
    }
    sort(rall(vs));

    vector<tuple<i32, i32>> xs(m);
    fi(i, m) {
        ri(x);
        xs[i] = {x, i};
    }
    sort(all(xs));

    vi used(m);
    fi(t, q) {
        used.clear();
        used.resize(m, false);
        ri(l, r);
        dbg(l, r);

        i64 result = 0;
        for (auto &[v, w] : vs) {
            dbg(v, w);
            for (auto &[x, i] : xs) {
                if ((i + 1 < l || i + 1 > r) && w <= x && !used[i]) {
                    dbg(i, x);
                    result += v;
                    used[i] = true;
                    break;
                }
            }
        }
        dbg(used);
        wl(result);
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
// auto mod int
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod; return *this;}
  mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod; return *this;}
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

const int N=200005,K=17;
mint dp[N][K];
bool u[N][K];
int n,k;
mint f(int i,int j){
  if(i==0) return j==k;
  if(j>k) return 0;
  if(u[i][j]) return dp[i][j];
  u[i][j] = true;
  return dp[i][j] = f(i-1,j)*j+f(i-1,j+1)*(16-j);
}
int main() {
  string s;
  cin >> s >> k;
  n = s.size();

  mint ans;
  set<int> t;
  rep(i,n){
    int a = [&]{
      auto c=s[i];
      if(isdigit(c)) return c-'0';
      return c-'A'+10;
    }();
    rep(ai,a){
      int ki = t.size()+1;
      if(t.count(ai)) --ki;
      if(ki==1&&ai==0) continue;
      ans += f(n-1-i,ki);
    }
    t.insert(a);
  }
  rep(i,n-1) ans += f(i,1)*(16-1);
  if(t.size()==k) ans += 1;
  cout << ans << endl;
}


#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define FF first.first
#define FS first.second
#define pb push_back
using namespace std;
const ll N=1000006, INF=1e18, MOD=1e9+7;

ll n, m, t, a[N][2], f[N], q=1, e, o, u, x, y, k, ans, Ans0[2], Ans1[2], mx;
vector <ll> v;
string s[101];

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

//	cin>>q;
	while(q--){
		cin>>n;
		for (int i=1; i<=n; i++)a[i][0]=INF,a[i][1]=-INF;

		for (int i=1; i<=n; i++){
			cin>>x>>y;
			a[y][0]=min(x, a[y][0]);
			a[y][1]=max(x, a[y][1]);
		}

		x=0;
		for (int i=1; i<=n+1; i++){
			if(a[i][0]<INF){
				Ans1[0]=min(Ans0[0]+abs(a[x][0]-a[i][1]), Ans0[1]+abs(a[x][1]-a[i][1]))+a[i][1]-a[i][0];
				Ans1[1]=min(Ans0[0]+abs(a[x][0]-a[i][0]), Ans0[1]+abs(a[x][1]-a[i][0]))+a[i][1]-a[i][0];
				Ans0[0]=Ans1[0];
				Ans0[1]=Ans1[1];
				x=i;
			}
//			cout<<Ans0[0]<<" "<<Ans0[1]<<"____\n";
		}
		cout<<min(Ans0[0], Ans0[1]);
	}
}

// Always remember that you are absolutely unique, just like everyone else!

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

// DEBUGGING SECTION
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...);}

#define fastio  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)

#define MOD     1000000007
#define INF     (ll)1e18
#define ll      long long int
#define pll     pair<ll, ll>
#define vll     vector<ll>
#define vvll	vector<vll>
#define vpll    vector<pll>
#define pb      push_back
#define endl    '\n' // Remove if interactive
#define ff      first
#define ss      second
#define all(x)  x.begin(), x.end()
#define FOR(i, a, b)   for(int i = a; i < b; i++)

ll power(ll x, ll y) { ll ans = 1; x %= MOD; while (y) {if (y & 1)ans = (x * ans) % MOD; x = (x * x) % MOD; y >>= 1;} return ans;}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//#include <algorithm>
//#include <cstring>
//#include <map>
//#include <set>
//#include <queue>

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

// comparator(A, B) -> should return true if A needs to come before B!
// ALWAYS RETURN FALSE IF A == B

vector<pll> vec;
vvll arr;
vvll dp, dp2;

ll helper(ll in, int end);

ll helper2(ll in, int end) {
	if (in == arr.size() - 1)
		return 0;
	if (dp2[in][end] != -1)
		return dp2[in][end];

	ll one = helper(in + 1, 0);
	ll two = helper(in + 1, 1);

	ll ans = min(abs(arr[in][end] - arr[in + 1][0]) + one, abs(arr[in][end] - arr[in + 1][1]) + two);;

	dp2[in][end] = ans;
	return ans;
}

ll helper(ll in, int end) {
	if (in == arr.size() - 1) {
		return 0;
	}
	if (dp[in][end] != -1)
		return dp[in][end];
	ll one = helper2(in, 1 - end);
	ll two = helper2(in, 1 - end);
	ll dist = abs(arr[in][1] - arr[in][0]);
	ll ans = dist + min(one, two);
	dp[in][end] = ans;
	return ans;
}

void solve() {
	int n;
	cin >> n;
	vec.resize(n + 10, {INF, -INF});
	dp.resize(n + 10, vll(2, -1));
	dp2.resize(n + 10, vll(2, -1));

	ll x, c;
	FOR(i, 0, n) {
		cin >> x >> c;
		--c;
		vec[c].ff = min(vec[c].ff, x);
		vec[c].ss = max(vec[c].ss, x);
	}

	FOR(i, 0, n) {
		if (vec[i].ff != INF) {
			arr.pb({vec[i].ff, vec[i].ss});
		}
	}
	arr.pb({0, 0});
	//debug(arr);
	cout << min(abs(arr[0][0]) + helper(0, 0), abs(arr[0][1]) + helper(0, 1));
	//debug(dp);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	// freopen("error.txt", "w", stderr);
	freopen("output.txt", "w", stdout);
#endif

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


#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int score(int N, vector<int> A, string S) {
	vector<int> st;
	int ans = 0;
	for (int i = 0; i < 2 * N; ++i) {
		if (S[i] == '(') st.push_back(i);
		else {
			ans += abs(A[st.back()] - A[i]);
			st.pop_back();
		}
	}
	return ans;
}
string solve(int N, vector<int> A) {
	vector<int> p(2 * N);
	for (int i = 0; i < 2 * N; ++i) {
		p[i] = i;
	}
	sort(p.begin(), p.end(), [&](int va, int vb) { return A[va] < A[vb]; });
	vector<int> ip(2 * N);
	for (int i = 0; i < 2 * N; ++i) {
		ip[p[i]] = i;
	}
	vector<int> sa, sb;
	string str(2 * N, '?');
	for (int i = 0; i < 2 * N; ++i) {
		if (ip[i] < N) {
			sa.push_back(i);
		}
		else {
			sb.push_back(i);
		}
		if (sa.size() >= 1 && sb.size() >= 1) {
			int ta = sa.back(); sa.pop_back();
			int tb = sb.back(); sb.pop_back();
			if (ta > tb) swap(ta, tb);
			str[ta] = '(';
			str[tb] = ')';
		}
	}
	return str;
}
string solve_easy(int N, vector<int> A) {
	string perm = string(N, '(') + string(N, ')');
	int opt = -1; string ans;
	do {
		int d = 0; bool ok = true;
		for (int i = 0; i < 2 * N; ++i) {
			if (perm[i] == '(') ++d;
			else --d;
			if (d < 0) {
				ok = false;
				break;
			}
		}
		if (ok) {
			int res = score(N, A, perm);
			if (res > opt) {
				opt = res;
				ans = perm;
			}
		}
	} while (next_permutation(perm.begin(), perm.end()));
	return ans;
}
#include <random>
mt19937_64 mt(2105272032);
int rand_int(int l, int r) {
	uniform_int_distribution<int> p(l, r - 1);
	return p(mt);
}
string to_string(vector<int> arr) {
	string res = "[";
	for (int i = 0; i < arr.size(); ++i) {
		if (i) res += ", ";
		res += to_string(arr[i]);
	}
	res += "]";
	return res;
}
void random_check() {
	for (int N = 1; N <= 7; ++N) {
		for (int testcase = 1; testcase <= 10000; ++testcase) {
			vector<int> A(2 * N);
			for (int i = 0; i < 2 * N; ++i) {
				A[i] = rand_int(1, 10);
			}
			string res1 = solve(N, A);
			string res2 = solve_easy(N, A);
			if (score(N, A, res1) != score(N, A, res2)) {
				cout << "N = " << N << " / Case #" << testcase << ":" << endl;
				cout << "A = " << to_string(A) << endl;
				cout << "Returns: " << res1 << endl;
				cout << "Answer: " << res2 << endl;
				cout << endl;
			}
		}
		cout << "N = " << N << " Completed!" << endl;
		cout << endl;
	}
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(2 * N);
	for (int i = 0; i < 2 * N; ++i) {
		cin >> A[i];
	}
	cout << solve(N, A) << endl;
	return 0;
}

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

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

	int n;
	cin >> n;

	vector<int> a(2 * n);
	for (auto &x : a) cin >> x;

	vector<int> ind(2 * n);
	iota(ind.begin(), ind.end(), 0);
	sort(ind.begin(), ind.end(), [&](int i, int j) {
		return a[i] < a[j];
	});

	vector<bool> big(2 * n);
	for (int i = n; i < 2 * n; i++) {
		big[ind[i]] = true;
	}

	string ans(2 * n, 0);
	vector<int> st;

	for (int i = 0; i < 2 * n; i++) {
		if (!st.empty() && (big[st.back()] ^ big[i])) {
			ans[i] = ')';
			st.pop_back();
		} else {
			ans[i] = '(';
			st.push_back(i);
		}
	}
	cout << ans << '\n';
	return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1001001001;
const long long LINF = 1001002003004005006;
const double PI = acos(-1);
int d4r[] = {1, 0, -1, 0};
int d4c[] = {0, 1, 0, -1};
int d8r[] = {1, 1, 0, -1, -1, -1, 0, 1};
int d8c[] = {0, 1, 1, 1, 0, -1, -1, -1};

long long GCD(long long x, long long y) {
    if (y == 0) return x;
    return GCD(y, x % y);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    vector<long long> x(n);
    for(int i = 0;i < n;++i) {
        cin >> x[i];
    }
    vector<long long> prime = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
    long long ans = LINF;
    for(long long i = 0;i < (1 << prime.size());++i) {
        long long now = 1;
        for(int j = 0;j < prime.size();++j) {
            if(i >> j & 1) {
                now *= prime[j];
            }
        }
        bool flag = true;
        for(int i = 0; i < n;++i) {
            if(GCD(now,x[i]) == 1) {
                flag = false;
            }
        }
        if(flag == false) {
            continue;
        }
        ans = min(ans, now);
    }
    cout << ans << '\n';
    return 0;
}

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define vec vector<ll>
#define be begin()
#define en end()
#define MOD 1000000007
#define ull unsigned long long
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define sll set<ll>
#define MAXN 500005
#define ll_max 5000000000000000000
using namespace std;
int main() {fastio ll t=1;//cin>>t;
    while(t--)
    {
        ll n=0,m=0,k=0,i=0,j=0,p=0,q=0,x=0,y=0,z=0,maxm=INT_MIN,minm=INT_MAX,ans=0,cnt=0,l=0,r=0,mid=0,lo=0,hi=0;string s;bool flag=false;
        cin>>n;ll a[n]; for(i=0;i<n;i++)cin>>a[i];
        sort(a,a+n);
        for(i=0;i<n;i++){
          if(a[i]==i+1){
            cnt++;
          }
        }
        if(cnt==n)cout<<"Yes"<<endl;
        else
          cout<<"No"<<endl;
        //
    }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
// vtqi6hy80o@email.edu.pl
#define rep(i, a, b) for(lli i = a; i < b; i++)
#define lli long long int
#define ld long double
#define all(v) v.begin(), v.end()
#define hell 1000000000000000
#define pb push_back
#define pf push_front
#define vi vector<lli>
#define vip vector<pair<lli, lli>>
#define F first
#define S second
#define pi 2*acos(0.0)
#define sz(s) s.size()
#define atmod (1000000000+7)
#define mod 998244353
// auto _C=clock();
// lli n = 10000000;
// int dx[]={1,-1,0,0};
// int dy[]={0,0,1,-1};
/*vector<bool> p(n + 1, true);
void sieve()
{
    for (long long int i = 2; i * i <= n; i++)
    {
        if (p[i])
        {
            for (long long int j = i + i; j <= n; j = j + i)
            {
                p[j] = false;
            }
        }
    }
}
*/
/*
WINNERS NEVER QUIT AND QUITTERS NEVER WIN!!
Falling down is an accident, Staying down is a choice.
*/
/*lli binpow(lli a, lli n,lli m)
{
    lli r = 1;
    a %=m ;
    while (n > 0)
    {
        if (n & 1)
        {
            r = (r * a)%m ;
        }
        a = (a * a)%m ;
        n = n / 2;
    }
    return r;
}*/
/*bool cmp(pair<lli,lli> a,pair<lli,lli> b)
{
    if(a.F<b.F) return 1;
    else if(a.F==b.F) return(a.S>b.S);
    else return 0;
}*/
/*lli WaysFromOnetoOther(lli start,lli end,lli k)
{
    lli res = 0;
    if(k==1)
    {
        return 1;
    }
    rep(i,0,4)
    {
        if(i!=end&&i!=start)
        {
            res+=WaysFromOnetoOther(i,end,k-1);
        }
    }
    return res;
}*/
/*lli npr(lli n,lli r)
{
    lli res = 1;
    rep(i,1,r+1)
    {
        res=res%atmod*(n-r+i)%atmod;
        res%=atmod;
        // res/=i;
    }
    return res;
}*/
void solve()
{
    lli a , b;
    cin>>a>>b;
    cout<<(a*b/(double)100);
}
int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(0);
    // cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    // sieve();
    lli t = 1;
    // cin >> t;
    rep(i,1,t+1)
    {
        solve();
    }
    // cerr<<"\n\n\nTime elapsed: ";
    // cout<<"\n"<<(double)(clock()-_C)*1000.0/CLOCKS_PER_SEC<<"ms\n";
}

#include <iostream>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
//typedef pair<LL, LL> P;
using namespace std;
//using Graph = vector<vector<LL>>;

//const LL MOD=1000000007;
//const LL MOD=998244353;
//const LL MAX=100100;
//const LL NIL=-1;
//const LL INF=2000000000000000000;
//const LL SEG_VAL = 1 << 19;

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

    LL n;
    LL k;
    cin >> n >> k;
    LL ans=0;
    for(LL i=1; i<=n; i++){
        for(LL j=1; j<=k; j++){
            ans+=100*i+j;
        }
    }

    cout << ans << endl;

    return 0;
}


/*g++ main.cpp -o main.out*/
/*./main.out*/

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

#define LL long long
#define LD long double
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(a,n) memset(a,n,sizeof(a));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

int a[105];

int main()
{
    int n,k,m;
    cin>>n>>k>>m;
    int ans=n*m;
    rep(i,n-1)
    {
        cin>>a[i];
        ans-=a[i];
    }
    if(ans<=k&&ans>0)cout<<ans<<endl;
    else if(ans<=0)cout<<0<<endl;
    else cout<<-1<<endl;

    return 0;
}

#include <iostream>

using namespace std;

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

	if(a + c > b) {
		cout << "Takahashi" << endl;
	}
	else {
		cout << "Aoki" << endl;
	}

	return 0;
}


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

typedef long long ll;

int get() {
	int x = 0; char s = getchar();
	while (s < '0' || s > '9') s = getchar();
	while (s >= '0' && s <= '9') x = (x << 3) + (x << 1) + (s ^ 48), s = getchar();
	return x;
}
char gc() {
	char s = getchar();
	while (s < 'A' || s > 'B') s = getchar();
	return s;
}

const int mo = 1e9 + 7;

ll pow(ll x, int k) {
	ll ans = 1;
	while (k) {
		if(k & 1) ans = ans * x % mo;
		x = x * x % mo;
		k >>= 1;
	}
	return ans;
}

int main() {
	int n = get();
	char aa = gc(), ab = gc(), ba = gc(), bb = gc();
	if(n < 4) return !printf("1");
	if((ab == 'A' && aa == 'A') || (ab == 'B' && bb == 'B')) return !printf("1");
	if(ab ^ ba) printf("%lld", pow(2ll, n - 3));
	else {
		if(n == 4) return !printf("2");
		if(n == 5) return !printf("3");
		ll p = 3, q = 2;
		for (int i = 3; i <= n - 3; ++i) {
			p = (p + q) % mo;
			q = (p - q + mo) % mo;
		}
		printf("%lld", p);
	}
	return 0;
}

#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << (x) << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, M = 1e9 + 7;

signed main()
{
	IO_OP;

	int n;
	cin >> n;
	if(n == 2) return cout << 1 << endl, 0;
	n -= 2;
	V<vi> a(2, vi(2));
	for(int i = 0; i < 2; i++)
		for(int j = 0; j < 2; j++) {
			char c;
			cin >> c;
			a[i][j] = c - 'A';
		}
	if(a[0][1]) {
		auto b = a;
		for(int i = 0; i < 2; i++)
			for(int j = 0; j < 2; j++)
				b[i][j] = a[j][i];
		for(int i = 0; i < 2; i++)
			for(int j = 0; j < 2; j++)
				a[i][j] = b[i ^ 1][j ^ 1] ^ 1;
	}
	if(a[0][0] == 0) return cout << 1 << endl, 0;
	if(a[1][0] == 0) {
		int a = 1, b = 1;
		for(int i = 0; i < n - 1; i++) {
			int aa = (a + b) % M;
			int bb = a;
			a = aa, b = bb;
		}
		cout << a << endl;
	} else {
		int ans = 1;
		for(int i = 0; i < n - 1; i++) ans = ans * 2 % M;
		cout << ans << endl;
	}

}


#include <vector>
#include <functional>

using namespace std;

template<typename T>
class SegmentTree
{
    int n;
    function<T(T,T)> op;
    vector<T> V;

    T q(int l, int r)
    {
        if (l >= r)
            return V[0];
        T a = q((l+1)/2, r/2);
        if (l%2 != 0)
            a = op(a, V[l]);
        if (r%2 != 0)
            a = op(a, V[r-1]);
        return a;
    }

public:
    SegmentTree(int n_, function<T(T,T)> op, T init):
        op(op)
    {
        n = 1;
        while (n < n_)
            n *= 2;
        V = vector<T>(2*n, init);
        for (int i=n-1; i>0; i--)
            V[i] = op(V[i*2], V[i*2+1]);
    }

    T get(int p) const
    {
        return V[p+n];
    }

    void set(int p, T v)
    {
        p += n;
        V[p] = v;
        for (p/=2; p>0; p/=2)
            V[p] = op(V[p*2], V[p*2+1]);
    }

    //  init OP v[l] OP v[l+1] OP ... OP v[r-1]
    T query(int l, int r)
    {
        return q(l+n, r+n);
    }
};

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

int main()
{
    int N;
    cin>>N;
    vector<int> A(N);
    for (int &a: A)
        cin>>a;

    int MA = 0;
    for (int a: A)
        MA = max(MA, a+1);

    vector<int> L(N);
    SegmentTree<int> STL(MA, [&](int x, int y){return max(x, y);}, -1);
    for (int i=0; i<N; i++)
    {
        L[i] = STL.query(0, A[i]);
        STL.set(A[i], i);
    }
    vector<int> R(N);
    SegmentTree<int> STR(MA, [&](int x, int y){return min(x, y);}, N);
    for (int i=N-1; i>=0; i--)
    {
        R[i] = STR.query(0, A[i]);
        STR.set(A[i], i);
    }
    int ans = 0;
    for (int i=0; i<N; i++)
        ans = max(ans, A[i]*(R[i]-L[i]-1));
    cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+105;
const ll mod=1e9+7;
int a[maxn];
int main(){

     int n,ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++){
		int tp=a[i];
		for(int j=i+1;j<=n;j++) {
			if(a[j]<a[i]){
				break;
			}
			tp=tp+a[i];
		}
		for(int j=i-1;j>=1;j--){
			if(a[j]<a[i]){
				break;
			}
			tp=tp+a[i];
		}
		ans=max(ans,tp);

	}

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

	return 0;
}