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

int main(){
  	int n, m;
  	cin >> n >> m;
  	map<int, vector<int>> mp;
  	rep(i, m){
    	int x, y;
      	cin >> x >> y;
      	mp[x].push_back(y);
    }

  	set<int> s;
  	s.insert(n);
  	for(auto p : mp){
      	vector<int> add;
    	for(int y : p.second){
        	if(s.count(y-1) || s.count(y+1)) add.push_back(y);
        }

        for(int y : p.second) s.erase(y);
        for(int y : add) s.insert(y);
    }

    cout << s.size() << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) ((int)(x).size())
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const int inf = 1 << 30;
const ll INF = 1LL << 60;

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;}

mint pow2[4000005];

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];

    VVI l(h, VI(w)), r(h, VI(w)), u(h, VI(w)), d(h, VI(w));
    rep(i, h) rep(j, w){
        if (s[i][j] == '#') continue;
        if (i != 0) u[i][j] += u[i-1][j];
        if (j != 0) l[i][j] += l[i][j-1];
        u[i][j] += 1;
        l[i][j] += 1;
    }
    rrep(i, h) rrep(j, w){
        if (s[i][j] == '#') continue;
        if (i != h-1) d[i][j] += d[i+1][j];
        if (j != w-1) r[i][j] += r[i][j+1];
        d[i][j] += 1;
        r[i][j] += 1;
    }

    ll cnt = 0;
    rep(i,h) rep(j,w) if (s[i][j] == '.') cnt++;

    pow2[0] = 1;
    rep(i, 4000005) pow2[i+1] = pow2[i] * 2;

    mint ans = 0;
    rep(i,h) rep(j,w){
        if (s[i][j] == '#') continue;
        ll num = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3;
        ans += (pow2[num] - 1) * pow2[cnt-num];
    }
    view(ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int res=0;
    char c;
    bool zf=0;
    while(((c=getchar())<'0'||c>'9')&&c!= '-');
    if(c=='-')zf=1;
    else res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
    if(zf)return -res;
    return res;
}
signed main(){
	cout<<read()-read()+read();
	return 0;
}

#include <iostream>
using namespace  std;
int main() {
	int N;
	int A[4];
	N = 4;
	int ans;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		if (i == 0) {
			ans = A[0];
		}
		else {
			if (ans > A[i]) {
				ans = A[i];
			}
		}
	}
	cout << ans << endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;

int main(){
    int n;cin>>n;
    for(int i=0;i<n;i++){
        ll r,l;cin>>l>>r;
        ll res=int(r-2*l);
        if(res<0)cout<<0<<endl;
        else {
            res=(res+1)*(res+2)/2;
            cout<<res<<endl;
        }
    }
    return 0;
}

// #define LOCAL
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,s,n) for (int i = (ll)s; i < (ll)n; i++)
#define rrep(i,n,e) for (int i = (ll)n; i > (ll)e; i--)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
// #define M_PI 3.14159265358979323846 // CF
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) cout << fixed << setprecision(10) << x << endl; // print Decimal number 10 Rank
#define endl "\n"
#define Case(x) printf("Case #%d: ", x); // gcj

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<char> vch;
typedef vector<vector<char>> vvch;

constexpr ll INF = 1001002003004005006ll;
constexpr int n_max = 2e5+10;

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

template<class T, class U>
T POW(T x, U n) {T ret=1; while (n>0) {if (n&1) {ret*=x;} x*=x; n>>=1;} return ret;};

// debug
template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';};
string to_string(const char c) {return to_string((string) &c);};
string to_string(bool b) {return (b ? "true" : "false");};
template <size_t N>
string to_string(bitset<N> v){
  string res = "";
  for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
  return res;
};
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for(const auto &x : v) {
    if(!first) res += ", ";
    first = false; res += to_string(x);
  }
  res += "}";
  return res;
};
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;};
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); };

void LINE_OUT() {
  cout << "--------------" << endl;
};

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define LINE LINE_OUT();
#else
#define debug(...) 71
#define LINE 71;
#endif

void print() { cout << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
};

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
};

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
};

void solve() {
  int L, R; cin >> L >> R;
  int alt = R-2*L+1;
  if (alt <= 0) {
    cout << 0 << endl;
  } else {
    cout << (alt+1)*alt/2 << endl;
  }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t; cin >> t;
  while (t--) {
    solve();
  }

  return 0;
};


#include<bits/stdc++.h>
using namespace std;
#define ll __int128
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define db double
#define pb push_back
#define N 1000000000
#define inf 10000000000000

char s[65];
ll len,mx,m;

inline ll ksm(ll a,ll b){ ll res=1;
    for(;b;b>>=1,a=a*a){
        if(b&1)res=res*a;
        if(res>m)return -1;
    }
    return res;
}

inline ll read(){
    ll f=0,s=0; char c=getchar();
    while(c>'9'||c<'0')f=(c=='-'),c=getchar();
    while(c>='0'&&c<='9')s=(s<<3)+(s<<1)+(c^'0'),c=getchar();
    return f?-s:s;
}
inline void write(ll x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
        write(x/10);
    putchar(x%10+'0');
}
inline ll check(ll x){ ll res=0;
    for(int i=len;i>=1;i--){
        ll tt=ksm(x,len-i);
        if(tt!=-1)res+=(s[i]-'0')*tt; //write(res); cout<<endl;
        else return 1e30;
    }
    return res;
}

int main(){
    scanf("%s",s+1); len=strlen(s+1),mx=0; m=read();
    for(int i=1;i<=len;i++)mx=max(mx,(ll)s[i]-'0');
    if(len==1){
        if(s[1]-'0'<=m)puts("1");
        else puts("0");
        return 0;
    }
    ll l=mx+1,r=m,mid,res=mx;
    while(l<=r){
        mid=(l+r)>>1; //write(l); putchar(' '); write(r); putchar(' '); write(mid); cout<<endl;
        if(check(mid)<=m)l=mid+1,res=mid;
        else r=mid-1;
    }
    write(res-mx);
    return 0;
}

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

template<typename T>
struct counting_iterator: public iterator<random_access_iterator_tag, bool>{
	T value = 0;
	counting_iterator(const T &value): value(value){}
	counting_iterator(const counting_iterator &it): value(it.value){}
	counting_iterator(){}
	typename iterator_traits<counting_iterator>::difference_type operator-(const counting_iterator &it) const{ return value - it.value; }
	counting_iterator &operator++(){ return *this += 1; }
	counting_iterator &operator--(){ return *this += -1; }
	counting_iterator &operator+=(typename iterator_traits<counting_iterator>::difference_type n){ value += n; return *this; }
	bool operator!=(const counting_iterator &it) const{ return value != it.value; }
	T &operator*(){ return value; }
};
template<typename T>
using cnt_it = counting_iterator<T>;

int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	string x;
	long long m;
	cin >> x >> m;
	if((int)x.size() == 1){
		cout << (x[0] - '0' <= m) << "\n";
		return 0;
	}
	int d = *max_element(x.begin(), x.end()) - '0';
	auto pred = [&](long long n){
		long long cur = 0;
		for(auto digit: x){
			if(__builtin_mul_overflow_p(cur, n, 0LL) || __builtin_add_overflow_p(cur * n, digit - '0', 0LL)){
				return false;
			}
			cur = cur * n + digit - '0';
		}
		return cur <= m;
	};
	cout << *partition_point(cnt_it<long long>(d + 1), cnt_it<long long>(numeric_limits<long long>::max()), pred) - d - 1 << "\n";
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                //
//                                   Coded by Aeren                                   //
//                                                                                //
////////////////////////////////////////////////////////////////////////////////////////


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

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

  ll ans=0;

  for(int i=0;i<n;++i){
    vector<int> dist(n,-1);
    queue<int> que;
    dist[i]=0;
    que.push(i);
    while(!que.empty()){
      int v=que.front();
      que.pop();

      ans++;

      for(int nv : g[v]){
        if(dist[nv]!=-1)continue;

        dist[nv]=dist[v]+1;
        que.push(nv);
      }
    }
  }

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

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
typedef pair<ll, ll> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    rep(i, N)
    {
        cin >> A[i];
    }
    multiset<int> st;
    unordered_map<int, int> mp;
    for (int i = 0; i <= N; i++) {
        st.insert(i);
        mp[i]++;
    }

    int res = INF_32;
    int right = 0;
    int size = 0;
    for (int left = 0; left < N; left++) {
        while (right < N && size < M) {
            if (st.find(A[right]) != st.end()) {
                st.erase(st.find(A[right]));
            }
            mp[A[right]]--;
            size++;
            right++;
        }

        res = min(res, *st.begin());

        if (right == N)
            break;

        if (left == right)
            right++;
        else {
            if (mp[A[left]] == 0) // 足りないのはあと一個
                st.insert(A[left]);
            mp[A[left]]++;
            size--;
        }
    }

    cout << res << endl;
    return 0;
}


#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

template<int M>
class ModInt {
   public:
    ll value;
    constexpr ModInt(ll v = 0) { value = v % M; if (value < 0) value += M; }
    constexpr ModInt pow(ll n) const { if (!n) return 1; ModInt a = pow(n >> 1); a *= a; if (n & 1) a *= *this; return a; }
    constexpr ModInt inv() const { return this->pow(M - 2); }
    constexpr ModInt operator + (const ModInt &rhs) const { return ModInt(*this) += rhs; };
    constexpr ModInt operator - (const ModInt &rhs) const { return ModInt(*this) -= rhs; };
    constexpr ModInt operator * (const ModInt &rhs) const { return ModInt(*this) *= rhs; };
    constexpr ModInt operator / (const ModInt &rhs) const { return ModInt(*this) /= rhs; };
    constexpr ModInt &operator += (const ModInt &rhs) { value += rhs.value; if (value >= M) value -= M; return *this; };
    constexpr ModInt &operator -= (const ModInt &rhs) { value -= rhs.value; if (value <  0) value += M; return *this; };
    constexpr ModInt &operator *= (const ModInt &rhs) { value = value * rhs.value % M; return *this; };
    constexpr ModInt &operator /= (const ModInt &rhs) { return (*this) *= rhs.inv(); };
    constexpr bool operator == (const ModInt &rhs) { return value == rhs.value; }
    constexpr bool operator != (const ModInt &rhs) { return value != rhs.value; }
    friend ostream &operator << (ostream &os, const ModInt &rhs) { os << rhs.value; return os; }
};

using mint = ModInt<MOD>;

int main() {
    int N, M; cin >> N >> M;
    vector<int> A(N); REP(i, 0, N) cin >> A[i];

    ll S = accumulate(ALL(A), 0LL);
    mint ans = 1;
    REP(i, 0, N + S) {
        ans *= (N + M - i);
        ans /= (N + S - i);
    }
    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
#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 per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class T> int lwb(const V<T>& v, const T& a){return lower_bound(all(v),a) - v.begin();}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N;
	double D,H;
	cin >> N >> D >> H;
	double ans = 0;
	while(N--){
		double d,h; cin >> d >> h;
		chmax(ans,h-(H-h)/(D-d)*d);
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch VillageOfMPeople | diff VillageOfMPeople.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address VillageOfMPeople.cpp && ./a.out

/*

 5/9/2021

 23:18-23:48 give up

 5/10/2021

 22:20-22:33 WA

 */

const int MAX_K=1e6+1;
LL A[MAX_K];
LL K,N,M;

VV<LL> build(LL d) {
  VV<LL> B(2,vector<LL>(K));
  REP(i,K) {
    LL minb=(M*A[i]-d+N-1)/N;
    LL maxb=(M*A[i]+d)/N;
    B[0][i]=minb,B[1][i]=maxb;
  }
  return B;
}
bool ok(LL d) {
  VV<LL> B=build(d);
  LL minm=0,maxm=0;
  REP(i,K) minm+=B[0][i],maxm+=B[1][i];

  return minm<=M&&M<=maxm;
}

void solve() {
  LL good=2e18,bad=-1;
  while(abs(good-bad)>1) {
    LL m=(good+bad)/2;
    (ok(m)?good:bad)=m;
  }

  auto B=build(good);
  vector<LL> res=B[0];
  LL sum=accumulate(ALL(B[0]),0LL);
  assert(sum<=M);
  LL rem=M-sum;
  REP(i,K) {
    while(rem>0&&res[i]<B[1][i]) res[i]++,--rem;
  }

  assert(accumulate(ALL(res),0LL)==M);
  REP(i,K) cout<<res[i]<<" ";
  cout<<endl;
}

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

  cin>>K>>N>>M;
  REP(i,K) cin>>A[i];
  solve();

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define setbits(n) __builtin_popcountll(n)
#define mkunique(a) sort(a.begin(),a.end()); a.resize(unique(a.begin(),a.end())-a.begin());
#define print(s) for(ll u: s) cout<<u<<" "; cout<<"\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod=1e9+7;

ll n;
vector<ll> a;

long double getexp(long double x){
    long double sum=0;
    for(ll i=0;i<n;i++){
        sum = sum + x + (long double)a[i] - min((long double)a[i],x*2);
    }
    sum/=n;
    return sum;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll TT=clock();

    cin>>n;
    a.assign(n,0);
    for(ll i=0;i<n;i++)
        cin>>a[i];
    long double l=0, r=2e9;
    for(ll i=0;i<100;i++){
        long double m1 = l + (r-l)/3;
        long double m2 = l + 2*(r-l)/3;
        if(getexp(m1)>getexp(m2))
            l = m1;
        else
            r = m2;
    }
    cout<<fixed<<setprecision(10);
    cout<<getexp(l);

    cerr<<"\n\nTIME: "<<(long double)(clock()-TT)/CLOCKS_PER_SEC<<" sec\n";
    TT = clock();
    return 0;
}


// Link to the Problem
// https://atcoder.jp/contests/abc197/tasks/abc197_a

/*
    飲んだ魔剤で家が建つ。
    created at: 2021-04-11 19:20:49
    cleared at:
*/

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

#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF 1000000000

long long rtceil (long long x) {
    long long i;
    for (i = 1; x > 0; i++) {
        x -= i*2 + 1;
    }

    return i - 1;
}

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

    s = (s + s[0]).substr(1);

    cout << s << endl;

    return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<(n);i++)
#define rep2(i,n,m) for(ll i=n;i<(m);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
void YES(int a){
  if(a) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}
void Yes(int a){
  if(a) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

//#include <atcoder/all>

//using namespace atcoder;
//typedef modint998244353 mint;

int main(){
  string S;
  cin>>S;
  cout<<S.substr(1,2)<<S[0]<<endl;
}


#include <bits/stdc++.h>
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define endl '\n'

using namespace std;

using ll = long long;
using pii = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = 1000000007;
const int dx[] = { 0, 0, -1, 1, 1, -1,  1, -1};
const int dy[] = {-1, 1,  0, 0, 1, -1, -1,  1};

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

  ll n;
  cin >> n;
  n = 2*n;
  auto cnt = [&](ll x){
    ll aux = n/x;
    aux -= x-1;
    return aux%2 == 0;
  };
  ll ans = 0;
  for(ll d=1; d<=n/d; d++){
    if(n%d == 0){
      ans += cnt(d);
      if(d*d != n)
        ans += cnt(n/d);
    }
  }
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
template <class T = ll> using P = pair<T,T>;
template <class T = ll> using V = vector<T>;
template <class T = ll> using VV = V<V<T>>;
#define rep(i,n) for(int i=0; i<(n);++i)
#define repp(i, l, r) for(int i = (l); i < (r); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()

// xのどれかにyを含むか
bool contain(int x, int y){
    if(x%10 == y) return true;
    else if((x/10)%10 == y) return true;
    else if((x/100)%10 == y) return true;
    else if((x/1000)%10 == y) return true;
    else return false;
}

int main()
{
    string s;
    cin >> s;
    int v[10] = {};
    rep(i, 10){
        if(s[i] == 'o'){
            v[i] = 0;
        }else if(s[i] == 'x'){
            v[i] = 1;
        }else{
            v[i] = 2;
        }
    }

    ll ans = 0;
    rep(i, 10000){
        bool ok = true;
        rep(j, 10){
            if(v[j] == 0){
                ok &= contain(i, j);
            }
            else if(v[j] == 1){
                ok &= !contain(i, j);
            }
        }
        if(ok) ans++;
    }

    cout << ans << endl;

    return 0;
}


/**
 *	Author:  Sohel Rana
 *	Date:    2020-10-24 23:02:29
 *	Task:    B_Various_distances
**/
#include <bits/stdc++.h>
#define endl        '\n'
#define db          double
#define ld          long double
#define ll          long long
#define ull         unsigned long long
#define sqr(x)      (x) * (x)
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)   ((a/gcd(a,b)) * b)
#define pf(x) 		push_front(x)
#define pb(x)       push_back(x)
#define eb(x)		emplace_back(x)
#define all(x)      (x).begin(), (x).end()
#define rall(x) 	(x).rbegin(), (x).rend()
#define sz(x) 		(int)x.size()
#define debug(x) 	cerr << #x << " = " << (x) << endl
#define debug2(x,y) cerr << #x << " = " << (x)<< "," << #y << " = " <<(y)<< endl
#define unsyncIO    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ld PI = acos((ld)-1);
const int MOD = 1e9+7;
const ll INF = 1e18;

using namespace std;

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //unsyncIO;
    int n, mx = 0;
    ull Manhattan = 0;
    ld euclidian = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        ll temp;
        cin >> temp;
        if (temp < 0) temp = temp * -1;
        if ((temp) > mx)
            mx = (temp);
        Manhattan += (temp);
        euclidian += sqr(temp);
    }

    cout << Manhattan << endl;
    //ld euc = sqrt(euclidian);
    printf("%0.15Lf\n",sqrt(euclidian));
    //cout << sqrt(euclidian << endl;
    cout << mx << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
#define lowbit(x) ((x)&-(x))
#define rep(i,l,r) for(res i=l,_r=r;i<=_r;++i)
#define per(i,r,l) for(res i=r,_l=l;i>=_l;--i)
#define mkp make_pair
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem0n(a,n) memset(a,0,n*sizeof(a[0]))
#define iter(x,v) for(res v,_p=head[x];v=ver[_p],_p;_p=nxt[_p])
#ifdef cccgift //by lqh
#define SHOW(x) cerr<<#x"="<<(x)<<endl
#else
#define SHOW(x) 0
#endif
//#define getchar()(ip1==ip2&&(ip2=(ip1=ibuf)+fread(ibuf,1,1<<21,stdin),ip1==ip2)?EOF:*ip1++)
//char ibuf[1<<21],*ip1=ibuf,*ip2=ibuf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
int n,k;
char s[201];
inline char doit(char ch1,char ch2) {
	if(ch1==ch2) return ch1;
	if(ch1>ch2) swap(ch1,ch2);
	if(ch1=='P'&&ch2=='R') return 'P';
	if(ch1=='P'&&ch2=='S') return 'S';
	return 'R';
}
int main()
{
	read(n),read(k),scanf("%s",s+1);
	rep(i,1,k) {
		if(n&1) {
			rep(i,n+1,n+n) s[i]=s[i-n];
			n*=2;
		}int len=0;
		for(res j=1;j<=n;j+=2) s[++len]=doit(s[j],s[j+1]);
		n=len;
	}
	putchar(s[1]),puts("");
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/


#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <functional>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <bitset>
#include <cassert>
#include <math.h>
#include <complex>
#include <iomanip>
#include <unordered_map>
using namespace std;
#define ll long long
#define pb(x) push_back(x)

template<typename T1>
void dbg_pr(vector<T1> V, int add = 0, int start = -1, int end = -1) {
    cout << "{";
    if (start < 0) start = 0;
    if (end < 0) end = V.size() - 1;
    for (int i = start; i <= end; i++) {
        cout << V[i] + add << ((i == end) ? "}" : " ");
    }
}
void dbg_pr(string V) {cout << "\"" << V << "\"";}
template<typename T1>
void dbg_pr(T1 V) {cout << V;}
template<typename T1, typename T2>
void dbg_pr(map<T1, T2> M) {
    cout << "{";
    for(const auto m : M) {
        dbg_pr(m.first);
        cout << ":";
        dbg_pr(m.second);
        cout << ",";
    }
    cout << "}";
}
#ifdef _OLIMPOLOCAL
    #define dbg(...) cerr << "\033[1;36m[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define dbg(...) 1337
#endif
void debug_out() { cout << "\033[0m\n";}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cout << " "; dbg_pr(A); debug_out(B...); }
int test = 1;
#define out(x) {cout << x << "\n";return;}
#define all(N) N.begin(),N.end()
#define allr(N) N.rbegin(),N.rend()
void setupFastCin() {ios::sync_with_stdio(false);cin.tie(0);}

template<typename T1>
T1 chmin(T1 &x, const T1 v) { return x = min(x,v); }
template<typename T1>
T1 chmax(T1 &x, const T1 v) { return x = max(x,v); }
template<typename T1>
void pr(vector<T1> V, int add = 0, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = V.size() - 1;
    for (int i = start; i <= end; i++) {
        cout << V[i] + add << ((i == end) ? "\n" : " ");
    }
}
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define repsr(i, s, n) for (int i = n-1; i >= s; i--)
#define PI pair<int,int>
#define PLL pair<ll, ll>
template<typename T1>
T1 gcd(const T1 &a, const T1 &b) {
    if (a == 0 || b == 0) return a + b;
    return gcd(b, a %b);
}
//-------------------------- ^ DONT TOUCH ^-----------------------------------------------------------------

#define MAX 1000000
#define MAXP 21
//#define MOD 998244353ll
#define MOD 1000000007ll

long long power(long long x, long long n) {
    long long p = x;
    long long s = 1;
    while (n > 0) {
        if (n & 1) s = (s * p) % MOD;
        p = (p * p) % MOD;
        n /= 2;
    }
    return s;
}

int n;
ll N[MAX];

double val(double x) {
    double s = -x;
    rep(i,n) {
        s += min((double)N[i], 2 * x) / n;
    }
    //dbg(x, s);
    return s;
}

void solve() {
    cin >> n;
    double s = 0;
    double hi = 0;
    double lo = 0;
    rep(i,n) {
        cin >> N[i];
        s -= N[i];
        chmax(hi, N[i] * 2.0 + 1);
    }

    rep(kk, 100) {
        double sz = (hi - lo) / 3;
        double m1 = lo + sz;
        double m2 = hi - sz;
        if (val(m1) < val(m2)) lo = m1;
        else hi = m2;
    }
    double ans = s / n + val(lo);
    printf("%.10lf\n", -ans);
}

int main() {
    setupFastCin();
    int T = 1;
#ifdef _OLIMPOLOCAL
    cin >> T;
#endif
    reps(t, 1, T + 1){
        solve();
    }

    return 0;
}

#include <bits/stdc++.h>

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  vector<double> a;
  Solver(LL n) : n(n), a(n){};

  void solve() {
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    sort(a.begin(), a.end());
    double x = a[n / 2] / 2;
    double ans = 0;
    for (int i = 0; i < n; ++i) {
      ans += x + a[i] - min(a[i], 2.0 * x);
    }
    cout << ans / n << endl;
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
#define all(v) begin(v),end(v)
#define pb push_back
#define fr first
#define sc second
#define si(s) (int)s.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pi 3.1415926536
#define dig(a) fixed<<setprecision(a)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
const int M = 1e9+7;
const int N = 1e5+5;
ll power(ll a, ll n) {
ll res = 1;
while (n) {
if (n % 2) {res = (res * a) % M;}
n >>= 1; a = (a * a) % M;}
return res;
}
void solve(){
	int n;
	cin>>n;
	vector<ll> a(n);
	for(auto &x:a){
		cin>>x;
	}
	ll ma = INT_MIN;
	for(int i=0;i<n;i++){
		ll s = a[i];
		for(int j=i-1;j>=0;j--){
			if(a[i]<=a[j]){
				s+=a[i];
			}
			else{
				break;
			}
		}
		for(int j=i+1;j<n;j++){
			if(a[i]<=a[j]){
				s+=a[i];
			}
			else{
				break;
			}
		}
		ma = max(ma,s);
	}
	cout<<ma;
}
int main(){
	fast;

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

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

#include <bits/stdc++.h>
#define PRINT(x) cerr<<#x<<'='<<x<<endl
#define NL(x) " \n"[(x)]
#define sz(x) int((x).size())
#define all(x) begin(x),end(x)
#define mid (l+r)/2
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define lld long long
#define pii pair<int,int>
#define pli pair<lld,int>
#define pil pair<int,lld>
#define pll pair<lld,lld>
#define INF 1000000000
#define LINF 1000000000000000000LL
#define EPS 1e-9
using namespace std;
#define MAXN 10010
lld A[MAXN];
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int N; cin >> N;
    for(int i = 1; i <= N; i++) cin >> A[i];
    long long rez = 0;
    for(int i = 1; i <= N; i++) {
        lld minn = INF;
        for(int j = i; j <= N; j++) {
            minn = min(minn, A[j]);
            rez = max(rez, minn*(j-i+1));
        }
    }
    cout << rez;
    return 0;
}


/*input
10
6 7 5 18 2
3 8 1 6 3
7 2 8 7 7
6 3 3 4 7
12 8 9 15 9
9 8 6 1 10
12 9 7 8 2
10 3 17 4 10
3 1 3 19 3
3 14 7 13 1
*/
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define rd() abs((int)rng())
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
vector<vector<int> >v;
int get(int msk, int i) {
	int mn = mod;
	for (int bit = 0; bit < 5; bit++) {
		if (msk >> bit & 1) {
			mn = min(mn, v[i][bit]);
		}
	}
	return mn;
}
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	vector<int>best(1 << 5, -1);
	for (int i = 0; i < n; i++) {
		vector<int>cand;
		for (int j = 0; j < 5; j++) {
			int a;
			cin >> a;
			cand.pb(a);
		}
		v.pb(cand);

		for (int msk = 0; msk < 1 << 5; msk++) {
			if (best[msk] == -1) {
				best[msk] = i;
			} else if (get(msk, i) > get(msk, best[msk])) {
				best[msk] = i;
			}
		}
	}

	int ans = 0;
	for (int a = 0; a < 1 << 5; a++) {
		for (int b = a; b >= 0; b = (b - 1) & a) {
			int msk1 = b;
			int msk2 = a ^ b;
			int msk3 = ((1 << 5) - 1) ^ a;

			vector<int>mx(5);
			for (int idx : {best[msk1], best[msk2], best[msk3]}) {
				for (int i = 0; i < 5; i++) {
					mx[i] = max(mx[i], v[idx][i]);
				}
			}

			int mn = mod;
			for (int i = 0; i < 5; i++) {
				mn = min(mn, mx[i]);
			}
			ans = max(ans, mn);

			if (b == 0) {
				break;
			}
		}
	}

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

#include<bits/stdc++.h>
#define DONTSYNC ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL) //dont use stdio with iostream functions //input and output are out of order now!
#define TEST unsigned long long T; cin>>T; while(T--)  //loop over each testcase
#define endl "\n"
#define fori(a,start,end) for(int a=start;a<end;a++)
#define forll(a,start,end) for(long long a=start;a<end;a++)
#define forull(a,start,end) for(unsigned long long a=start;a<end;a++)
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define fi first
#define se second
using namespace std;

void solve(){
    /* code */
    int n; cin>>n;
    vector<vector<int>> mat(n,vector<int>(n));
    int mini=0,minj=0;
    fori(i,0,n){
        fori(j,0,n){
            cin>>mat[i][j];
            if(mat[i][j]<mat[mini][minj]) mini=i,minj=j;
        }
    }
    vector<int> B(n);
    vector<int> A(n);
    fori(i,0,n){
        if(!i) B[i]=0;
        else{
            B[i]=mat[0][i]-mat[0][0];
        }

        if(!i) A[i]=0;
        else{
            A[i]=mat[i][0]-mat[0][0];
        }
    }

    fori(i,1,n){
        fori(j,1,n){
            if(B[j]!=mat[i][j]-mat[i][0])
            {cout<<"No"<<endl;return;}
            if(A[i]!=mat[i][j]-mat[0][j])
            {cout<<"No"<<endl;return;}
        }
    }cout<<"Yes"<<endl;
    fori(i,0,n){
        cout<<A[i]-A[mini]<<' ';
    }  cout<<endl;
    fori(i,0,n){
        cout<<B[i]-B[minj]+mat[mini][minj]<<' ';
    }  cout<<endl;
}

int main()
{
    DONTSYNC;
    // TEST
    solve();
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
int main()
{
  std::string input;
  std::cin >> input;

  std::reverse(input.begin(), input.end());

  for(int i = 0; i < input.length(); ++i)
  {
    if(input.at(i) == '6')
      input.at(i) = '9';
    else if(input.at(i) == '9')
      input.at(i) = '6';
  }
  std::cout << input << std::endl;
  return 0;
}

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

typedef long long LL;

int main(){
    long long i,j,k,l,m,n,t;
    char a[300010];
    cin>>n;
    getchar();
    for(i=0;i<n;i++) {
        a[i]=getchar();
    }
    if (a[0]!=a[n-1]) {
        cout<<1;
        return 0;
    }
    for(i=1;i<n-1;i++) {
        if (a[i]!=a[0]&&a[i+1]!=a[0]) {
            cout<<2;
            return 0;
        }
    }
    cout<<-1;
    return 0;
}


// {{{ by unolight
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i,a,b) for (int i = a; i <= (int)(b); i++)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

namespace { namespace unolight {

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template <class T, class F = less<T>>
void sort_uniq(vector<T> &v, F f = F()) {
    sort(begin(v), end(v), f);
    v.resize(unique(begin(v), end(v)) - begin(v));
}
// }}}

void main() {
    int n,m;
    cin >> n >> m;
    if ( m<0||(n==1 && m==1 )||(n>1 && m>n-2) ) {
        cout << -1 << '\n';
        return;
    }
    if ( n==1 ) {
        cout << 1 << ' ' << 2 << '\n';
        return;
    }
    int l=1, r=2*(m+1)+2;
    vector<PII> ans;
    ans.emplace_back(l,r);
    for ( int i=0; i<=m; i++ ) {
        int a=l+i*2+1;
        int b=a+1;
        ans.emplace_back(a,b);
    }
    int a=r+1;
    for ( int i=m+2; i<n; i++ ) {
        ans.emplace_back(a,a+1);
        a+=2;
    }
    for ( auto [i,j]:ans ) {
        cout << i << ' ' << j << '\n';
    }
}

// {{{ main
}}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    unolight::main();
    return 0;
}
// }}}

#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp> // #include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp> //#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds; //using namespace __gnu_pbds;
#define pb push_back
#define ins insert
#define var auto
#define F first
#define S second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
template <class T> using oset = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
const int Max = 4e5 + 10;
const int LOG = 30;
const int Mod = 1e9 + 7;
const int SQ = 3000;
const int INF = 1e9 + 10;
const int BMSK = 4e6;

ll pw(ll a , int b = Mod - 2)
{
	if(b == 0) return 1;
	ll half = pw(a , b / 2);
	if(b % 2) return half * half % Mod * a % Mod;
	return half * half % Mod;
}

void solve()
{
	int n , m;cin >> n >> m;
	if(n == 1 && m == 0)
	{
		cout << 1 << " " << 2 << '\n';
		return;
	}
	if(m < 0 || m >= n - 1)
	{
		cout << -1 << '\n';
		return;
	}

	for(int i = 0 ; i < n - 1 ; i++)
		cout << 3 * i + 2 << " " << 3 * i + 1 + 2 << '\n';
	cout << -1 + 2 << " " << 3 * m + 2 + 2 << '\n';

}

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

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


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 105;

int dp[sz][sz][sz], ara[sz], a[sz], bm;

int fnc(int n, int k, int m) {
   if(!n) return 0;
   int &w = dp[n][k][m];
   if(w < 0) {
      w = fnc(n - 1, k, m);
      if(k == 1) {
         if(a[n] == m) w = max(w, ara[n]);
      }
      else {
         int y = (m - a[n] + bm) % bm;
         int z = fnc(n - 1, k - 1, y);
         if(z) w = max(w, ara[n] + z);
      }
   }
   return w;
}

int main() {
   int n; ll x;
   cin >> n >> x;
   for(int i=1; i<=n; i++) scanf("%d", &ara[i]);

   ll ans = LLONG_MAX;
   for(int k=1; k<=n; k++) {
      for(int i=1; i<=n; i++) a[i] = ara[i] % k;
      memset(dp, -1, sizeof(dp));
      bm = k;
      int now = fnc(n, k, x % k);
      if(now) ans = min(ans, (x - now) / k);
   }
   cout << ans;
}

#include<bits/stdc++.h>
#define forn(i,s,t) for(register int i=(s);i<=(t);++i)
#define form(i,s,t) for(register int i=(s);i>=(t);--i)
using namespace std;
typedef long long LL;
const int N = 1e2+3;
const LL INF = 2e18;
template<typename T>inline T Max(T A, T B) {return A>B?A:B;}
template<typename T>inline T Min(T A, T B) {return A<B?A:B;}
LL a[N], f[N][N], X, Ans; int n;
int main() {
	scanf("%d%lld", &n, &X);
	forn(i,1,n) scanf("%lld", a+i);
	Ans = INF;
	forn(i,1,n) {
		forn(j,1,n) form(k,i-1,0) f[j][k] = -1;
		f[0][0] = 0;
		forn(j,1,n) form(k,i,0) forn(l,0,i-1) if(f[k][l] != -1) {
			LL tmp = f[k][l] + a[j];
			f[k+1][tmp % i] = Max(f[k+1][tmp % i], tmp);
		}
		if(f[i][X % i] != -1) Ans = Min(Ans, (X - f[i][X % i]) / i);
	}
	printf("%lld\n", Ans);
	return 0;
}


/*
"An anomaly, I'm Muhammad Ali
  Cause I know one day I'm gonna be the"
                - Greatest, Eminem
*/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#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;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;

int main(){
    Shazam;
    string s; cin >> s;
    while(s.size() && s.back() == '0') s.pop_back();
    for(int i = 0; i < s.size() / 2 ; i++){
        if(s[i] == s[s.size() - 1 - i]) continue;
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
char s[N],t[N],f[]=" atcoder";
int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		scanf("%s", s+1);
		int n = strlen(s+1);
		int ook = 0;
		for (int i=1; i<=min(n,7); ++i) {
			if (s[i]>f[i]) {
				ook = 1;
				break;
			}
			if (s[i]<f[i]) {
				ook = -1;
				break;
			}
		}
		if (ook==1||ook==0&&n>7) {
			puts("0");
			continue;
		}
		for (int i=1; i<=n; ++i) t[i] = s[i];
		sort(t+1,t+1+n,greater<char>());
		int ok = 0;
		for (int i=1; i<=min(n,7); ++i) {
			if (t[i]>f[i]) {
				ok = 1;
				break;
			}
			if (t[i]<f[i]) {
				ok = -1;
				break;
			}
		}
		if (ok==-1||ok==0&&n<7) puts("-1");
		else {
			int ans = 1e9;
			for (int i=1; i<=n; ++i) if (s[i]>'a') {
				ans = min(ans, abs(i-1));
			}
			for (int i=1; i<=n; ++i) if (s[i]>'t') {
				ans = min(ans, abs(i-2));
			}
			printf("%d\n", ans);
		}
	}
}


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

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

	if(C%2==0){
		if(abs(A)>abs(B)) cout << ">" << endl;
		else if(abs(A)<abs(B)) cout << "<" << endl;
		else cout << "=" << endl;
	}else{
		if(A>B) cout << ">" << endl;
		else if(A<B) cout << "<" << endl;
		else cout << "=" << endl;
	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
// clang-format off

using LL = long long;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

const int fx[]={+1,-1,+0,+0};
const int fy[]={+0,+0,+1,-1};
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
// clang-format on

void solve(long long A, long long B, long long C) {
  // solver code

  if (A >= 0 && B >= 0) {
    if (A < B) {
      std::cout << "<" << std::endl;
    } else if (A > B) {
      std::cout << ">" << std::endl;
    } else {
      std::cout << "=" << std::endl;
    }
    return;
  }

  // std::cout << 1 << std::endl;
  // if(A==0 || B==0){
  //   if(A==B){
  //     std::cout << "=" << std::endl;
  //   }else if(A<B){
  //     std::cout << "<" << std::endl;
  //   }else{
  //     std::cout << ">" << std::endl;
  //   }
  //   return;
  // }
  //
  // std::cout << 2 << std::endl;

  // if(A<0){
  //   if(B>0){
  //     if(C%2==0){
  //       if(abs(A)<abs(B)){
  //         std::cout << "<" << std::endl;
  //       }else if(abs(A)>abs(B)){
  //         std::cout << ">" << std::endl;
  //       }else{
  //         std::cout << "=" << std::endl;
  //
  //       }
  //     }else{
  //         std::cout << "<" << std::endl;
  //     }
  //   }else{
  //     if(A<B){
  //       std::cout << ">" << std::endl;
  //     }else{
  //       std::cout << "<" << std::endl;
  //     }
  //   }
  // }

  if (A < 0) {  // B>0
    if (C % 2 == 0) {
      if (abs(A) < abs(B)) {
        std::cout << "<" << std::endl;
      } else if (abs(A) > abs(B)) {
        std::cout << ">" << std::endl;
      } else {
        std::cout << "=" << std::endl;
      }
    } else {
      std::cout << "<" << std::endl;
    }

  } else {  // A>0 -> b<0
    if (C % 2 == 0) {
      if (abs(A) < abs(B)) {
        std::cout << "<" << std::endl;
      } else if (abs(A) > abs(B)) {
        std::cout << ">" << std::endl;
      } else {
        std::cout << "=" << std::endl;
      }
    } else {
      std::cout << ">" << std::endl;
    }

  }
}

int main() {
  long long A;
  std::scanf("%lld", &A);
  long long B;
  std::scanf("%lld", &B);
  long long C;
  std::scanf("%lld", &C);
  solve(A, B, C);
  return 0;
}


#include <iostream>
using namespace std;

int main(){
  int N;
  cin >> N;
  int a[N], b[N];
  for (int i = 0; i < N; i++) cin >> a[i];
  for (int i = 0; i < N; i++) cin >> b[i];
  long long ans;
  for (int i = 0; i < N; i++){
    ans += a[i] * b[i];
  }
  if (ans == 0)cout << "Yes";
  else cout << "No";
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second

int main(){

    ll t,n,i;
    cin>>n;
    vector<ll>arr(n);
     set<ll>s;
    for(i=0;i<n;i++)
     {
         cin>>arr[i];
         s.insert(arr[i]);
     }
     while(s.size()>=2)
     {
         ll x=*s.begin();
         ll y=*s.rbegin();

         s.insert(y-x);
         s.erase(y);

     }
     cout<<*s.begin();

    return 0;
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define WT int T=read();while(T--)
#define NO puts("NO");
#define YES puts("YES");
using namespace std;

inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}

const int M=2e5+10;
int sum[M],a[M],maxn[M],ans;

signed main()
{
	int n=read();
	for (int i=1;i<=n;i++)a[i]=read(),maxn[i]=max(maxn[i-1],a[i]),sum[i]=sum[i-1]+a[i];
	for (int i=1;i<=n;i++)
	{
		ans+=sum[i];ans-=maxn[i-1]*(i-1),ans+=i*maxn[i];
		cout<<ans<<endl;
	}
	return 0;
}

#include<cstdio>
using namespace std;
#define int long long
int n,a[200010],sum[200010],sum2[200010],mx[200010];
signed main(){
    scanf("%lld",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        sum[i]=sum[i-1]+a[i];
        sum2[i]=sum2[i-1]+sum[i];
        mx[i]=(mx[i-1]>a[i]?mx[i-1]:a[i]);
    }
    for(int i=1;i<=n;i++){
        printf("%lld\n",sum2[i]+mx[i]*i);
    }
    return 0;
}


//...Bismillahir Rahmanir Rahim. . .

#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;

// typedefs...
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

// constants...
const double PI = acos(-1);
const ll mod = 1000000007; // 998244353;
const int MXS = 2e5+5;
const ll MXI = 1e9+5;
const ll MXL = 1e18+5;
const ll INF = 1e9+5;
const ll INFLL = 1e18+5;
const ll EPS = 1e-9;

// defines...
#define MP        make_pair
#define PB        push_back
#define fi         first
#define se         second
#define sz(x)      (int)x.size()
#define all(x)      begin(x), end(x)
#define si(a)       scanf("%d", &a)
#define sii(a, b)    scanf("%d%d", &a, &b)
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define boost_      ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define iter_(i,n)    for (int i = 0; i < int(n); i++)
#define for_n(i, n)  for (int i = 1; i <= int(n); i++)
#define print_array(a) for(int i=0;i<n;i++)  cout<<a[i]<<" ";
#define rev(i,n)     for(int i=n;i>=0;i--)
#define itr          ::iterator
#define s_sort(s)    sort(s.begin(),s.end())
#define n_sort(a, n)    sort(a,a+n)
#define precise_impact cout<<setprecision(10)<<fixed;
#define endl         "\n"
// functions...
ll gcd(ll a, ll b){ while (b){ a %= b; swap(a, b);} return a;}
ll lcm(ll a, ll b){ return (a/gcd(a, b)*b);}
ll ncr(ll a, ll b){ ll x = max(a-b, b), ans=1; for(ll K=a, L=1; K>=x+1; K--, L++){ ans = ans * K; ans /= L;} return ans;}
ll bigmod(ll a,ll b){ if(b==0){ return 1;} ll tm=bigmod(a,b/2); tm=(tm*tm)%mod; if(b%2==1) tm=(tm*a)%mod; return tm;}
ll egcd(ll a,ll b,ll &x,ll &y){ if(a==0){ x=0; y=1; return b;} ll x1,y1; ll d=egcd(b%a,a,x1,y1); x=y1-(b/a)*x1; y=x1; return d;}
int main()
{
    ll t;
    cin>>t;
    vector<pair<ll,string> > v;
    while(t--)
    {
        string s;
        ll n;
        cin>>s>>n;
        v.PB({n,s});
    }
    sort(all(v));
    cout<<v[v.size()-2].se<<endl;
}

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

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

//#pragma GCC target("arch=skylake-avx512")
#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse4")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define repeat(i, n, m) for(int i = n; i < (m); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a)
#define printLdb(a) printf("%.50Lf\n", a)
#define printdbd(a) printf("%.16lf\n", a)
#define prints(s) printf("%s\n", s.c_str())
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d))

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

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

using namespace std;

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

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

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

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

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

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

//cpp_int
#if __has_include(<boost/multiprecision/cpp_int.hpp>)
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace boost::multiprecision;
#else
using cpp_int = ll;
#endif

//atcoder library
#if __has_include(<atcoder/all>)
#include <atcoder/all>
//using namespace atcoder;
#endif

/*
    random_device seed_gen;
    mt19937 engine(seed_gen());
    uniform_int_distribution dist(1, 100);
*/

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

int main() {

    int n;
    scanf("%d", &n);
    vector<ll> a(n);
    rep(i, n)scanf("%lld", &a[i]);
    map<ll, ll> mp;
    ll ans = 0;
    ++mp[0];
    ll r = 0;
    rep(i, n) {
        r += a[i] * (i % 2 ? -1 : 1);
        ans += (mp[r]++);
    }
    printf("%lld\n", ans);

    Please AC;
}


/**
 *    author:  shishunze
 *    date:	 2021/2/18
**/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back

const int N = 100005;
vector<int> e[N];
int n,x,dp[N],sz[N];
void dfs1(int u)
{
	sz[u]=1;
	for(int i=0;i<e[u].size();i++)
	{
		int v  = e[u][i];
		dfs1(v);
		sz[u]+=sz[v];
	}
}
void dfs2(int u)
{
	vector<int> vt;
	int sum=0;
	dp[u]=1;
	for(int i=0;i<e[u].size();i++)
	{
		int v = e[u][i];
		dfs2(v);

		if(sz[v]%2==0 && dp[v]<0) dp[u]+=dp[v];
		if(sz[v]%2==1) vt.pb(dp[v]);
		if(sz[v]%2==0 && dp[v]>=0) sum+=dp[v];
	}
	sort(vt.begin(),vt.end());
	vt.pb(sum);
	for(int i=0;i<vt.size();i++)
	{
		if(i%2==0) dp[u]+=vt[i];
		else dp[u]-=vt[i];
	}
}
int main()
{
	ios::sync_with_stdio(false);

	cin>>n;
	for(int i=2;i<=n;i++)
	{
		cin>>x;
		e[x].pb(i);
	}
	dfs1(1);
	dfs2(1);
	cout<<(n+dp[1])/2;
}

#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> v[100000];

pair<int, pair<int, int>> dfs(int x) {
    int p1 = 0, p2 = 0, sa = 0, sb = 0, f = 0, i;
    vector<pair<int, pair<int, int>>> w;

    p1++;
    f = 1 - f;

    for (i = 0; i < v[x].size(); i++) {
        pair<int, pair<int, int>> p = dfs(v[x][i]);
        int x = p.second.first;
        int y = p.second.second;

        if (p.first == 0) {
            if (x <= y) {
                p1 += x;
                p2 += y;
            } else {
                sa += x;
                sb += y;
            }
        } else {
            w.push_back(make_pair(x - y, make_pair(x, y)));
        }
    }

    sort(w.begin(), w.end());

    for (i = 0; i < w.size(); i++) {
        int x = w[i].second.first;
        int y = w[i].second.second;

        if (f == 1) {
            p1 += x;
            p2 += y;
        } else {
            p1 += y;
            p2 += x;
        }

        f = 1 - f;
    }

    if (f == 1) {
        p1 += sa;
        p2 += sb;
    } else {
        p1 += sb;
        p2 += sa;
    }

    return make_pair(f, make_pair(p1, p2));
}

int main() {
    int n, i;

    scanf("%d", &n);

    for (i = 1; i < n; i++) {
        int p;

        scanf("%d", &p);

        v[p - 1].push_back(i);
    }

    printf("%d\n", dfs(0).second.first);

    return 0;
}


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

#define ll              long long int
#define scan(any)       for(auto &i:any) cin>>i;
#define print(any)      for(auto i:any) cout<<i<<" ";
#define endl            '\n'
#define pb              push_back
#define vll             vector<ll>
#define f(i,x,y)        for(i=x;i<y;i++)
#define INF             LLONG_MAX
#define s(x)            sort(x.begin(),x.end())
#define all(v)          v.begin(),v.end()
#define p2(n,x)         cout << fixed << setprecision(x) <<n<<endl;
#define pll             pair<ll,ll>
#define mll             map<ll,ll>
#define ff              first
#define ss              second
#define blt(x)          __builtin_popcount(x)

void solve()
{
    long  double n;
    cin>>n;
    long  double ans=n;
    long double i;
    f(i,2,n)
    {
        ans+=(n/i);
    }
    p2(ans,10);
}

int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);

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

#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using lli = long long;
using vi = vc<int>;
using ii = pair<int,int>;

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}
lli lcm(lli a, lli b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
int popcount(lli x) { return __builtin_popcountll(x); }
lli poww(lli a, lli b){
	lli res = 1;
	while(b){ if(b&1) res = res*a; a=a*a; b>>=1;}
	return res;
}

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int rnd(int n){return uniform_int_distribution<int>(0, n-1)(rng);}

template<class t,class u>bool mmax(t&a,u b){if(a<b)a=b;return a<b;}
template<class t,class u>bool mmin(t&a,u b){if(b<a)a=b;return b<a;}
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
// ---- しゃけ ツナマヨ ('-')7

void solve(){
	int n; cin>>n;
	int best = inf<int>,same=inf<int>;
	vi x(n),y(n);
	fore(i,0,n){
		int a,b; cin>>a>>b;
		mmin(same,a+b);
		x[i]=a;
		y[i]=b;
	}
	best = same;
	fore(i,0,n)fore(j,0,n)if(i!=j)mmin(best,max(x[i],y[j]));
	fore(i,0,n)fore(j,0,n)if(i!=j)mmin(best,max(y[i],x[j]));
	cout<<best<<ENDL;

}

int main(){_
//	int t; cin>>t; while(t--)
	solve();
}


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

const int max_n = 1000;
multiset<int> mst;

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

	int n, m, ta;

	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> ta;
		mst.insert(ta);
	}
	for (int i = 0; i < m; i++)
	{
		cin >> ta;
		mst.insert(ta);
	}

	for (int i = 0; i <= max_n; i++)
	{
		if (mst.count(i) == 1)
			cout << i << " ";
	}
	cout << endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define vec vector<int>
#define vecp vector<pair<int,int>>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fr first
#define sc second
#define fr1(i,a,b) for(int i=a;i<b;i++)
#define fr2(i,a,b) for(int i=a;i>=b;i--)
#define fr3(i,a,b) for(int i=a;i<=b;i++)
#define umap unordered_map<int,int,custom_hash>
#define omap map<int,int>
#define uset unordered_set<int,custom_hash>
#define oset set<int>
#define pr pair<int,int>
#define mod 1000000007
#define mp make_pair
#define all(v) v.begin(),v.end()
#define ppb pop_back

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

void solve()
{
  int n,m;
  cin>>n>>m;
  map<int,int> map1;
  fr1(i,0,n)
  {
    int x;
    cin>>x;
    map1[x]++;
  }
  fr1(i,0,m)
  {
    int x;
    cin>>x;
    map1[x]++;
  }
  for(auto i:map1)if(i.sc==1)cout<<i.fr<<" ";
  cout<<"\n";

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    fr3(i,1,t){
      //cout<<"Case: "<<t<<;
        solve();
    }
   return 0;
}


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

using namespace std;
//using namespace atcoder;

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

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

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

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

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

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

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

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

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

// edit
int N;
vector<ll> A;

double f(double x) {
    double ret = 0;
    for (auto e : A) {
        ret += max<double>(0, e - 2 * x);
    }

    return ret;
}

void solve() {
    cin >> N;
    A.resize(N);
    REP(i, N) cin >> A[i];
    sort(ALL(A));
    double x1 = A[N / 2] / 2.;

//    double lb = 0, ub = 2e9;
////    double lb = 0, ub = 3;
//    REP(_, 100) {
////        double md = (lb + ub) / 2;
////        double tmp = f(md);
////        if (N * md < tmp) {
////            lb = md;
////        } else {
////            ub = md;
////        }
//        double c1 = (lb * 2 + ub) / 3;
//        double c2 = (lb + ub * 2) / 3;
//        double f1 = f(c1);
//        double f2 = f(c2);
//        if (f1 < f2) {
//            ub = c2;
//        } else {
//            lb = c1;
//        }
//    }

//    double ans = lb + f(lb) / N;

//    cout << 1.5 + f(1.5) / N << endl;

    double ans = f(x1) / N + x1;
    cout << ans << endl;
}

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

    solve();

    return 0;
}

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>
#include <numeric>
#include <chrono>
#include <random>

using namespace std;

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

#define debug(x) cerr << #x << " = " << (x) << endl;
#define debug_pii(x) cerr << "(" << x.first << "," << x.second << ")";
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define F first
#define S second

// template<typename _Ty1, typename _Ty2>
// ostream& operator<<(ostream& _os, const pair<_Ty1, _Ty2>& _p) {
//     _os << '(' <<_p.first << ',' << _p.second << ')';
//     return _os;
// }
//
// template<typename _Ty1, typename _Ty2>
// istream& operator>>(istream& _is, pair<_Ty1, _Ty2>& _p) {
//     _is >> _p.first >> _p.second;
//     return _is;
// }

// #1 >= #0
// #1 >= #0
//
// #0 > #1
// #0 > #1

// dp[i]['ab']

void solve() {
   string s;
   cin>>s;
   int cnt = 0;
   for(int i = 0;i <= 8;i++) {
     if(s.substr(i, 4) == "ZONe") cnt++;
   }
   cout<<cnt;
}

// a1 a2 a3 a4 a4 a6 a7
// b1 b2 b3 b4 b5 b6 b7
//
// dp[i][j] = cost + dp[i+1][j-1]

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);
 // cout << fixed << setprecision(15);

 ios_base::sync_with_stdio(false);
 cin.tie(nullptr);

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

 }

 return 0;
}


//region TEMPLATE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(X) begin((X)), end((X))
#define sz(X) (int)(X).size()
#define fi first
#define se second
#define fv(X) for(auto&_:(X))cin>>_
#define fv2(X) for(auto&__:(X))fv(__)
#define lboundi(X, n) (lower_bound(all(X), n) - begin(X))
#define uboundi(X, n) (upper_bound(all(X), n) - begin(X))
#define maxi(X) max_element(all(X)) - begin(X)
#define maxe(X) *max_element(all(X))
#define mini(X) min_element(all(X)) - begin(X)
#define mine(X) *min_element(all(X))
#define acc(X) accumulate(all(X), 0LL)
#ifdef LOCAL
template<size_t S>
string to_string(const bitset<S> &x) { return x.to_string(); }
string to_string(const string &x) { return '"' + x + '"'; }
string to_string(char x) { return string{'\'', x, '\''}; }
string to_string(bool x) { return x ? "true" : "false"; }
template<typename Head, typename Tail>
string to_string(const pair<Head, Tail> &x) { return "(" + to_string(x.first) + ", " + to_string(x.second) + ")"; }
template<class T>
string to_string(T x) {
    string ret = "[";
    for (const auto &i: x)
        ret += to_string(i) + ", ";
    if (sz(ret) > 1)
        ret = ret.substr(0, sz(ret) - 2);
    return ret += "]";
}
string to_string(const char *x) { return string(x); }
string to_string() { return ""; }
template<typename Head, typename... Tail>
string to_string(Head H, Tail... T) { return to_string(H) + ", " + to_string(T...); }
#define debug(...) sizeof( (char[]){#__VA_ARGS__} ) == 1 ? cerr << endl \
: cerr << "[" << #__VA_ARGS__ << "]: " << to_string(__VA_ARGS__) << endl
#define nr() cerr << endl
#else
#define debug(...) 1
#endif
// endregion
class FenwickTreeSum {
private:
   int sum(int i) {
       if (i <= 0) return 0;
       int ret = 0;
       while (i) {
           ret += tree[i];
           i -= i & -i;
       }
       return ret;
   }
public:
   int n;
   vi tree;
   FenwickTreeSum(int n) : n(n) {
       tree.resize(n + 1);
   }
   void update(int i, int diff) {
       i++;
       while (i <= n) {
           tree[i] += diff;
           i += i & -i;
       }
   }
   int query(int l, int r) { return sum(r + 1) - sum(l); }
};
void solve() {
    int n;
    cin >> n;
    vi a(n), b(n);
    fv(a);
    fv(b);
    if (acc(a) != acc(b)) {
        cout << -1;
        return;
    }
    if (a == b) {
        cout << 0;
        return;
    }

    // 8

    map<int, vi> pos_a, pos_b;
    for (int i = 0; i < n; i++) {
        a[i] += i;
        b[i] += i;
        pos_a[a[i]].pb(i);
        pos_b[b[i]].pb(i);
    }
    vi inversion_count(n);
    for (const auto &p: pos_a) {
        const vi &bv = pos_b[p.fi];
        if (sz(p.se) != sz(bv)) {
            cout << -1;
            return;
        }

        for (int i = 0; i < sz(p.se); i++) {
            inversion_count[bv[i]] = p.se[i];
        }
    }
    debug(inversion_count);
    FenwickTreeSum fenwick(n);
    ll ret = 0;
    for (int i = 0; i < n; i++) {
        ret += fenwick.query(inversion_count[i], n - 1);
        debug(fenwick.query(0, n - 1));
        fenwick.update(inversion_count[i], 1);
    }

    cout << ret;
}

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

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("unroll-loops")

#include "bits/stdc++.h"
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'
#define F first
#define S second
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define cf ll testcases;cin>>testcases;while(testcases--)
#define prn(x) if(x) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define minel(x) (*min_element(all(x)))
#define maxel(x) (*max_element(all(x)))
#define cou dbg=1;cout
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<ld> vd;
typedef vector<pi> vp;
ll dbg=0;
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p);
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p);
template<typename A> istream& operator>>(istream& cin, vector<A> &v);
int dx[] = {-1, -1, -1,  0, 0,  1, 1, 1};
int dy[] = {-1,  0,  1, -1, 1, -1, 0, 1};

void solve(){
    ll n;
    cin>>n;
    vi arr(n);
    cin>>arr;
    ll man=0;
    for(auto i:arr) man+=abs(i);
    cout<<man<<endl;
    ll euc=0;
    for(auto i:arr) euc+=i*i;
    cout.precision(15);
    cout<<fixed<<sqrt(euc)<<endl;
    ll cheb=LLONG_MIN;
    for(auto i:arr) cheb=max(cheb,abs(i));
    cout<<cheb<<endl;

}

int main(){
    IO;
    // cf
    solve();
    return 0;
}

template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) {
    if(dbg){
        return cout << "(" << p.F << ", " << p.S << ")";
    }else{
        return cout<<p.F<<' '<<p.S;
    }
        dbg=0;}
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
    if(dbg){
        cout << "["; for(ll i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
    }else{
        for(ll i=0;i<v.size()-1;i++) cout<<v[i]<<' ';
        return cout<<v[v.size()-1];
    dbg=0;}
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
   cin >> p.first;
   return cin >> p.second;
}
template<typename A> istream& operator>>(istream& cin, vector<A> &v) {
   for(ll i=0;i<v.size()-1;i++) cin>>v[i];
   return cin >> v[v.size()-1];
}


#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
#define _GLIBCXX_DEBUG
#define rep(i, s, n) for (int i = (int)s; i < (int)n; i++)
#define repr(i, n, s) for (int i = (int)n; (int)s < i; i--)
#define len(a) (int)a.size()
#define all(a) a.begin(), a.end()

const int INF32 = 1 << 30;
const long long INF64 = 1LL << 60;
const double PI = acos(-1);

/* 1次元ベクトルをスペースでつなぎ、改行をつけて出力
   vi, vl, list<int>, list<ll>に対応  */
template<class T> string print_elements(T a) {
    string str = "";
    for (auto itr = a.begin(); itr != a.end(); ++itr) {
        str += to_string(*itr) + ' ';
    }
    str.pop_back();  // 最後の空白を削除
    str += '\n';
    return str;
}

int main() {
    int N, W;
    cin >> N >> W;
    cout << N / W << endl;

}

#include<iostream>
using namespace std;
int main()
{
  int n,w;
  cin>>n>>w;
  int i=1;
  int t=1;
  while(t<=n){
    t=w*i;
    i++;
  }
  cout<<i-2;
}


#include<bits/stdc++.h>
#define L(i, j, k) for(int i = j, i##E = k; i <= i##E; i++)
#define R(i, j, k) for(int i = j, i##E = k; i >= i##E; i--)
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int, int>
#define mkp make_pair
#define sz(x) ((int) x.size())
#define be(x) x.begin()
#define en(x) x.end()
using namespace std;
const int N = 1e5 + 7;
int n, m;
void exgcd(ll a, ll b, ll &x, ll &y) {
	if(b == 0) return x = 1, y = 0, void();
	exgcd(b, a % b, y, x), y -= x * (a / b);
}
ll mul(ll aa, ll bb, ll mod) {
	ll sav = aa * bb - (ll)( (long db) aa * bb / mod + 0.2 ) * mod;
	return sav < 0 ? sav + mod : sav;
}
ll crt(ll *a, ll *b, int len) { // x mod a_i = b_i
	ll now = 1, ys = 0;
	L(i, 1, len) {
		ll g = __gcd(now, a[i]), c1, c2, md = a[i] / g;
		if((b[i] - ys) % g) return 2e18;
		exgcd(now, a[i], c1, c2), ((c1 %= md) += md) %= md, c1 = mul(c1, ((b[i] - ys) / g % md + md) % md, md);
		((c1 %= md) += md) %= md, ys += c1 * now;
		now /= g, now *= a[i], ((ys %= now) += now) %= now;
	}
	return ys;
}
ll a[N], b[N];
int T, x, y, p, q;
ll ans = 0;
void Main() {
	ans = 2e18;
	cin >> x >> y >> p >> q;
	L(i, x, x + y - 1) L(j, p, p + q - 1) {
		a[1] = 2 * (x + y), b[1] = i;
		a[2] = p + q, b[2] = j;
		ans = min(ans, crt(a, b, 2));
	}
	if(ans == 2e18) cout << "infinity\n";
	else cout << ans << "\n";
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> T;
	while(T--) Main();
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
int p,q,t,x,y;
ll a[3],ans,g,m[3];
template<class T>
inline T slow_add(T a,T b,T mod){
	while(a>mod-b)a-=mod;
	return a+b;
}
template<class T>
inline T slow_mul(T a,T b,T mod){
	T ret=0;
	for(;b;a=(a+a)%mod,b>>=1)if(b&1)ret=(ret+a)%mod;
	return ret;
}
template<class T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T>
void exgcd(T a,T b,T &x,T &y){
	a%=b;
	if(!a){
		x=b;y=0;
		return;
	}
	ll s=b,t=a,m0=0,m1=1;
	while(t){
		ll u=s/t;
		s-=t*u;
		m0-=m1*u;
		ll tmp=s;
		s=t;
		t=tmp;
		tmp=m0;
		m0=m1;
		m1=tmp;
	}
	if(m0<0)m0+=b/s;
	x=s,y=m0;
}
inline ll cn(int n){
	ll mul=1,ret=0;
	for(ri i=1;i<=n;++i){
		ll a1=a[i]%m[i],m1=m[i];
		if(mul<m1)swap(mul,m1),swap(ret,a1);
		if(mul%m1==0){
			if(ret%m1!=a1)return LLONG_MAX;
			continue;
		}
		ll t1=0,t2=0;
		exgcd(mul,m1,t1,t2);
		ll u1=m1/t1;
		ll tmp=(a1-ret)/t1%u1*t2%u1;
		ret+=tmp*mul;
		mul*=u1;
		if(ret<0)ret+=mul;
	}
	return ret;
}
int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%d%d%d%d",&x,&y,&p,&q);
		#define a1 a[1]
		#define a2 a[2]
		#define m1 m[1]
		#define m2 m[2]
		m1=(x+y)<<1,m2=p+q;
		g=gcd(m1,m2);
		ans=LLONG_MAX;
		for(a1=x;a1<x+y;++a1)
			for(a2=p;a2<p+q;++a2)
				if((a2-a1)%g==0)
					ans=min(ans,cn(2));
		if(ans==LLONG_MAX)puts("infinity");
		else printf("%lld\n",ans);
	}
	return 0;
}


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

const ll INF=1e18;
const int mx=200005;
//arc106
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    V<P> ans;
    bool ok=1;
    if(m==0){
        rep(i,n) ans.emplace_back(2*(i+1)-1,2*(i+1));
    }else if(m>0){
        int r=1;
        for(int i=1;i<=n;i++){
            if(i-2==m){
                ans.emplace_back(1,r+1);
                r++;
            }else{
                ans.emplace_back(r+1,r+2);
                r+=2;
            }
        }
    }else{
        int l=1000000000;
        int tmp=10000000;
        int cnt=1;
        for(int i=1;i<=n;i++){
            if(i==1){
                ans.emplace_back(1,tmp);
                cnt++;
            }else if(i-2<=-m){
                ans.emplace_back(cnt,tmp+cnt);
                //cnt++;
                if(i-1==-m){
                    cnt=tmp+cnt;
                }else cnt++;
            }else{
                ans.emplace_back(cnt+1,cnt+2);
                cnt+=2;
            }
        }
    }
    if(m>=n-1||m<0) ok=0;
    if(n==1&&m==0){
        cout<<1<<' '<<2<<endl;
        return 0;
    }
    if(ok){
        for(auto p:ans) cout<<p.ft<<' '<<p.sc<<'\n';
    }else out(-1);
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
dpするときは「配る」、「もらう」の両方を考えて最適な方を選べ
Segtreeで区間最大(max)を使うとき,単位元の設定をしっかり
(デフォルトは-INF,0の方が都合の良い場合は変更)
*/

#include <bits/stdc++.h>
using namespace std;
#ifdef __DEBUG__
    void debug_out() { cerr << endl; }
    template <typename Head, typename... Tail>
    void debug_out(Head H, Tail... T) {cerr << " " << H; debug_out(T...);}
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...)
#endif

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }

ll N,M;
inline void input(){
    fast_io();
    cin >> N >> M;
}

int cntR(vector<pll> a){
    auto cmp = [](pll x, pll y){return x.second < y.second;};
    sort(a.begin(),a.end(),cmp);
    debug(a);
    int ret = 0;
    ll last = 0;
    for (int i = 0; i < a.size(); i++)
    {
        if(last < a[i].first){
            ret++;
            last = a[i].second;
        }
    }
    return ret;
}

int cntL(vector<pll> a){
    auto cmp = [](pll x, pll y){return x.first < y.first;};
    sort(a.begin(),a.end(),cmp);
    debug(a);
    int ret = 0;
    ll last = 0;
    for (int i = 0; i < a.size(); i++)
    {
        if(last < a[i].first){
            ret++;
            last = a[i].second;
        }
    }
    return ret;
}

int solve(ll N, ll M){
    if(M<0){
        cout << -1 << endl;
        return 0;
    }
    else if(N==1 && M==0){
        vector<pll> Ans;
        Ans.emplace_back(1,2);
        for(auto [x,y]:Ans) cout << x << " " << y << "\n";
        return 0;
    }
    else if(M>=N-1){
        cout << -1 << endl;
        return 0;
    }
    vector<pll> Ans;
    ll rest = N-M;
    for (int i = 1; i <= min(M+1,N); i++)
    {
        Ans.emplace_back(2*i+rest+10,2*i+rest+11);
    }
    for (int i = 0; i < rest-1; i++)
    {
        Ans.emplace_back(i+1,(ll)1e6+i+1);
    }
    debug(cntR(Ans));
    debug(cntL(Ans));
    debug(Ans.size());
    for(auto [x,y]:Ans) cout << x << " " << y << "\n";
    return 0;
}

int test(){
    int n = 1;
    for (int m = -n; m <= n; m++)
    {
        debug(n,m);
        solve(n,m);
    }
    return 0;
}

int main()
{
    // test();
    input();
    solve(N,M);
    return 0;
}


// {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
// }}}

void main() {
    int n;
    R(n);
    VI a(n);
    REP(i,n) R(a[i]);
    chmin(n,8);
    vector<VI> g(200);
    for ( int s=1; s<1<<n; s++ ) {
        VI f;
        int sum=0;
        REP(i,n) if ( s>>i&1 ) {
            sum=(sum+a[i])%200;
            f.PB(i+1);
        }
        if ( SZ(g[sum]) ) {
            W("Yes");
            W(SZ(f),f);
            W(SZ(g[sum]),g[sum]);
            return;
        }
        g[sum]=f;
    }
    W("No");
}

 // {{{ main
}}
int main() { unolight::main(); return 0; }
// }}}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

ll a[505][505];
ll b[505][505];

const int INF = 1000000000;

int dist[1000005];
vector <pair <int, int>> graf[1000005];
int n, m;

int hes(int i, int j, int k){
    return k*n*m + (i-1)*m+j;
}

int main(){
    ios_base::sync_with_stdio(false);
	cout.precision(10);
	cout << fixed;

    cin >> n >> m;
    for(int i=1; i<=n; i++){
        for(int j=1; j<m; j++){
            cin >> a[i][j];
        }
    }
    for(int i=1; i<n; i++){
        for(int j=1; j<=m; j++){
            cin >> b[i][j];
        }
    }
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            if(j < m) graf[hes(i, j, 0)].push_back({hes(i, j+1, 0), a[i][j]});
            if(j < m) graf[hes(i, j, 1)].push_back({hes(i, j+1, 0), a[i][j]});
            if(j > 1) graf[hes(i, j, 0)].push_back({hes(i, j-1, 0), a[i][j-1]});
            if(j > 1) graf[hes(i, j, 1)].push_back({hes(i, j-1, 0), a[i][j-1]});
            if(i < n) graf[hes(i, j, 0)].push_back({hes(i+1, j, 0), b[i][j]});
            if(i < n) graf[hes(i, j, 1)].push_back({hes(i+1, j, 0), b[i][j]});
            if(i > 1) graf[hes(i, j, 0)].push_back({hes(i-1, j, 1), 2});
            if(i > 1) graf[hes(i, j, 1)].push_back({hes(i-1, j, 1), 1});
        }
    }
    for(int i=2; i<=2*n*m; i++) dist[i] = INF;
    set <pair <int, int>> q;
    q.insert({0, 1});
    while(!q.empty()){
        pair <int, int> pr = *q.begin();
        q.erase(q.begin());
        int v = pr.second;
        for(auto c : graf[v]){
            if(dist[c.first] > c.second + dist[v]){
                q.erase({dist[c.first], c.first});
                dist[c.first] = c.second + dist[v];
                q.insert({dist[c.first], c.first});
            }
        }
    }
    cout << min(dist[n*m], dist[2*n*m]);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef BOI
#include "debug.h"
#else
#define debug(args...)
#endif

typedef long long ll;

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

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

      vector <int> aa(n);
      iota(aa.begin(), aa.end(), 0);
      int cnt = 0;
      do {
            ll sum = 0;
            for (int i = 1; i < n; ++i) {
                  sum += a[aa[i]][aa[i - 1]];
            }
            sum += a[aa[n - 1]][0];
            if (sum == k) ++cnt;
            debug(aa, sum);
      } while (next_permutation(aa.begin() + 1, aa.end()));

      cout << cnt;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<ll mod>
struct Mint {
    ll x;
    Mint(ll x = 0) : x((x %= mod) < 0 ? x + mod : x) { }
    Mint& operator+=(Mint rhs) { return (x += rhs.x) >= mod ? x -= mod : 0, *this; }
    Mint& operator-=(Mint rhs) { return (x -= rhs.x) < 0 ? x += mod : 0, *this; }
    Mint& operator*=(Mint rhs) { return (x *= rhs.x) %= mod, *this; }
    Mint& operator/=(Mint rhs) { return *this *= rhs.power(-1); }
    Mint power(ll p) const {
        p %= mod - 1;
        if (p < 0) p += mod - 1;
        Mint res = 1;
        for (Mint y = *this; p; p >>= 1, y *= y) if (p & 1) res *= y;
        return res;
    }
    bool operator==(Mint rhs) const { return x == rhs.x; }
    bool operator<(Mint rhs) const { return x < rhs.x; }
    friend Mint operator+(Mint lhs, Mint rhs) { return lhs += rhs; }
    friend Mint operator-(Mint lhs, Mint rhs) { return lhs -= rhs; }
    friend Mint operator*(Mint lhs, Mint rhs) { return lhs *= rhs; }
    friend Mint operator/(Mint lhs, Mint rhs) { return lhs /= rhs; }
    friend ostream& operator<<(ostream& out, Mint a) { return out << a.x; }
    friend istream& operator>>(istream& in, Mint& a) {
        ll x;
        in >> x;
        a = Mint(x);
        return in;
    }
};
constexpr ll mod = 998244353;
using mint = Mint<mod>;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    const int Wmax = 100;
    vector<vector<mint>> dp(N + 1, vector<mint>(N * Wmax + 1));
    dp[0][0] = 1;
    int sum = 0;
    for (int i = 0; i < N; ++i) {
        int W;
        cin >> W;
        for (int k = N - 1; k >= 0; --k) {
            for (int x = N * Wmax - W; x >= 0; --x) {
                dp[k + 1][x + W] += dp[k][x];
            }
        }
        sum += W;
    }
    mint ans = 0;
    if (sum % 2 == 0) {
        vector<mint> f(N + 1, 1);
        for (int x = 1; x <= N; ++x) {
            f[x] = x * f[x - 1];
        }
        for (int k = 1; k <= N; ++k) {
            ans += dp[k][sum / 2] * f[k] * f[N - k];
        }
    }
    cout << ans << endl;
    exit(0);
}


#include <bits/stdc++.h>
using namespace std;
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
// =================
#define f(i, k, n) for (int i = k; i < n; i++)
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define len(s) s.size()
#define all(v) v.begin(), v.end()
// =================

const int mod = 1e9+7;
const int N = 3e5 + 1;

void solve()
{
    int v,t,s,d;
    cin>>v>>t>>s>>d;
    puts( (d>s*v || d<v*t) ? "Yes" : "No");
}

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

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

#include <iostream>
#include <cmath>

using namespace std;

int main(){
    int N, a, b;

    cin >> N;
    int arr[N], arr1[N];
    for(int i = 0; i < N; i++){
        cin >> a;
        arr[i] = a;
    }
    for(int k = 0; k < N; k++){
        cin >> b;
        arr1[k] = b;
    }
    int result = 0;

    for(int j = 0; j < N; j++){
        result += arr[j]*arr1[j];
    }
    if(result == 0){
        cout << "Yes" << endl;}
    else{
        cout << "No" << endl;
    }
}


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

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
map<int,int> S;

void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>N;
	ll ret=1LL*N*(N-1)/2;
	FOR(i,N) {
		cin>>x;
		ret-=S[x];
		S[x]++;
	}
	cout<<ret<<endl;
}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
    ll n;
    cin >> n;
    map<ll, ll> m;
    vector<ll> v;
    {
        ll tmp;
        while (cin >> tmp) {
            m[tmp]++;
            v.push_back(tmp);
        }
    }
    ll ans = 0;
    for (ll i: v) {
        ans += (n - m[i]);
    }
    cout << ans / 2LL << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  long long t, N;
  cin>>t>>N;
  long long ans;
  long long nonexistcount=0;
  long long i=1;
  while(nonexistcount!=N){
    if(i*(double)t/100>=nonexistcount+1){
      ans = i+nonexistcount;
      nonexistcount++;
      if(nonexistcount==1&&N!=1){
        i = i+(100/t)*(N-1);
        nonexistcount=N-1;
      }
      else{
        i = i+100/t;
      }
    }
    else{
      i++;
    }
  }
  cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;
#define _ 0
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    long long t,n;
    cin>>t>>n;
    cout<<(n*100+t-1)/t+n-1<<endl;
	return ~~(0^_^0);
}


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

// for loop
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

// abbreviati
#define PB(v) push_back(v)
#define MP(A,B) make_pair(A,B)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

// constant
const int INF = 1<<30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/

// adjacency list
vector<int> to[100005];

// Graph
using Graph = vector<vector<int>>;

// Grid
int H,W;
vector<vector<int>> field;

// 4方向への移動ベクトル
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h,w; cin >> h >> w;
    vector<string> s(h);
    rep(i,0,h){
        cin >> s[i];
    }

    bool flag=0;
    int cnt=0;
    rep(i,0,h){
        rep(j,0,w){
            flag=0;
            //if(j==w-1 || i==h-1) continue;
            if(s[i][j]=='.'){
                flag=1;
            }
            if(j<w-1 && flag && s[i][j+1]=='.'){
                cnt++;
            }
            if(i<h-1 && flag && s[i+1][j]=='.'){
                cnt++;
            }
        }
    }

    cout << cnt ENDL;

    return 0;
}

#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
#define N 100012
inline int sgn(int x){return (x==0)?0:((x>0)?1:(-1));}
inline int Abs(int x){return (x>0)?x:(-x);}
int n,L,a[N],b[N],c[N],la[N];bool fl=true;map<int,int>mp;long long ans=0;
inline void Fin(int l,int r)
{
	if(l+1>=r)return;int i,ql=l,qr=r,ls;
	for(i=l+1;i<r-1;i++)if((c[i]==1)&&(c[i+1]==(-1))){fl=false;return;}
	for(i=l;i<=r;i++)if(c[i]==(-1))ql=i;for(i=r;i>=l;i--)if(c[i]==1)qr=i;
	mp.clear();for(i=l;i<=ql;i++){if(c[i]){if(!mp.count(b[i]-i)){fl=false;return;}la[i]=mp[b[i]-i];}mp[a[i]-i]=i;}
	mp.clear();for(i=r;i>=qr;i--){if(c[i]){if(!mp.count(b[i]-i)){fl=false;return;}la[i]=mp[b[i]-i];}mp[a[i]-i]=i;}
	ls=l;for(i=l;i<=r;i++){if(c[i]&&(ls>la[i])){fl=false;return;}if(c[i])ls=max(ls,la[i]);}
	ls=r;for(i=r;i>=l;i--){if(c[i]&&(ls<la[i])){fl=false;return;}if(c[i])ls=min(ls,la[i]);}
	ls=r;for(i=ql;i>=l;i--)if(c[i]&&(la[i]!=ls)){ans+=i-la[i];ls=la[i];}
	ls=l;for(i=qr;i<=r;i++)if(c[i]&&(la[i]!=ls)){ans+=la[i]-i;ls=la[i];}
}
int main(){
	scanf("%d%d",&n,&L);int i,l,r;for(i=1;i<=n;i++)scanf("%d",&a[i]);for(i=1;i<=n;i++)scanf("%d",&b[i]);a[0]=b[0]=0;a[n+1]=b[n+1]=L+1;
	for(i=1;i<=n;i++)c[i]=sgn(b[i]-a[i]);
	for(i=0;(i<=(n+1))&&fl;i=r){l=i;r=i+1;while((r<=n)&&c[r])++r;Fin(l,r);}if(!fl){printf("-1");return 0;}printf("%lld",ans);return 0;
}