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

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

    int N; cin >> N;
    long long C_add = 0;
    long long C_min = 1e18;
    long long C_max = -1e18;
    for (int i = 0; i < N; i++) {
        long long a, t; cin >> a >> t;
        if (t == 1) {
            C_add += a;
            C_min += a;
            C_max += a;
        } else if (t == 2) {
            C_max = max(C_max, a);
            C_min = max(C_min, a);
        } else {
            C_min = min(C_min, a);
            C_max = min(C_max, a);
        }
    }

    int Q; cin >> Q;
    while (Q--) {
        long long x; cin >> x;
        cout << min(max(x + C_add, C_max), C_min) << '\n';
    }

    return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
#define ll long long
#define ld long double
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rnd(time(0));

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

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

int seg[6000055];

void upd(int ver,int tl,int tr,int pos,int val)
{
    if(tl>tr)
        return;
    else if(tl==tr)
        seg[ver]+=val;
    else
    {
        int tm=(tl+tr)/2;
        if(tm>=pos)
            upd(2*ver,tl,tm,pos,val);
        else
            upd(2*ver+1,tm+1,tr,pos,val);
        seg[ver]=min(seg[2*ver],seg[2*ver+1]);
    }
}

int get(int ver,int tl,int tr)
{
    if(tl>tr)
        return 0;
    else if(tl==tr)
        return tl;
    else
    {
        int tm=(tl+tr)/2;
        if(seg[2*ver]>0)
            return get(2*ver+1,tm+1,tr);
        else
            return get(2*ver,tl,tm);
    }
}

signed main()
{

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
        freopen("INPUT.txt","r",stdin);
        freopen("OUTPUT.txt","w",stdout);
    }
#endif

    int n;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
    }
    int mn=1e17;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i==j)
            {
                mn=min(mn,a[i]+b[j]);
            }
            else
                mn=min(mn,max(a[i],b[j]));
        }
    }
    cout<<mn;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(void){
    int h,w;
    cin >> h >> w;
    char s[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin.get(s[i][j]);
            if(s[i][j]=='\n'){
                cin.get(s[i][j]);

            }
        }
    }
    int count=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int c;
            c=((s[i][j]=='#')+(s[i+1][j]=='#')+(s[i][j+1]=='#')+(s[i+1][j+1]=='#'));
            if(c==1 || c==3){
                count++;
            }
        }
    }
    cout << count << endl;
}

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <ios>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <utility>

using namespace std;

using i64 = int64_t;
using u64 = uint64_t;
using i32 = int32_t;
using pi64 = pair<i64, i64>;

#define vec vector
#define let const
#define DRi64(x) i64 x; cin >> x;
#define DRS(x) string x; cin >> x;
#define DRVi64(v, n) vec<i64> v(n); { for (i64 i = 0; i < n; ++i) { cin >> v[i]; }}
#define DRpi64(x) pi64 x; cin >> x.first >> x.second;

#ifdef DEBUG
#define P(x) cerr << x << "\n"
#else
#define P(x)
#endif

constexpr i64 MAXN = 3*100*1000LL+5LL;
constexpr i64 MOD = 1000000007LL;
constexpr i64 INF64 = MOD * MOD;

int
main()
{
    ios_base::sync_with_stdio(false);

    DRi64(R); DRi64(C);
    vec<string> G(R + 2, string(C + 2, '.'));
    for (i64 r = 1; r <= R; ++r)
    {
        DRS(S);
        for (i64 c = 0; c < C; ++c)
        {
            G[r][c + 1] = S[c];
        }
    }

    i64 horiz_sides = 0;
    for (i64 r = 1; r <= R + 1; ++r)
    {
        vec<i64> changes;
        for (i64 c = 1; c <= C; ++c)
        {
            let i64 diff = G[r - 1][c] != G[r][c];
            if (changes.empty())
            {
                if (diff == 1)
                {
                    changes.push_back(diff);
                }
            }
            else if (diff != changes.back())
            {
                changes.push_back(diff);
            }
        }
        horiz_sides += count(changes.begin(), changes.end(), 1);
    }
    i64 vert_sides = 0;
    for (i64 c = 1; c <= C + 1; ++c)
    {
        vec<i64> changes;
        for (i64 r = 1; r <= R; ++r)
        {
            let i64 diff = G[r][c - 1] != G[r][c];
            if (changes.empty())
            {
                if (diff == 1)
                {
                    changes.push_back(diff);
                }
            }
            else if (diff != changes.back())
            {
                changes.push_back(diff);
            }
        }
        vert_sides += count(changes.begin(), changes.end(), 1);
    }
    cout << horiz_sides + vert_sides << "\n";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second

int n;
vector<pair<int,int>> shart(100);
vector<pair<int,int>> aadmi(16);
int res=0;

void fun(int pers, int m, int k, vector<int> coin)
{
    if(pers==k)
    {
        bool bartan[101]={};
        for(auto x: coin)  bartan[x]=true;
        int cnt=0;
        for(int i=0;i<m;i++) if(bartan[shart[i].X] && bartan[shart[i].Y]) cnt++;
        res=max(res,cnt);
    }
    else
    {
        coin.push_back(aadmi[pers].X);
        fun(pers+1,m,k,coin);
        coin.pop_back();
        coin.push_back(aadmi[pers].Y);
        fun(pers+1,m,k,coin);
        coin.pop_back();
    }
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int tc=1;
    // cin>>tc;
    while(tc--)
    {
        int m,k;
        cin>>n>>m;
        for(int i=0;i<m;i++) cin>>shart[i].X>>shart[i].Y;
        cin>>k;
        for(int i=0;i<k;i++) cin>>aadmi[i].X>>aadmi[i].Y;
        vector<int> coin;
        fun(0,m,k,coin);
        cout<<res<<"\n";
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)

using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vvp = vector<vp>;
using vl  = vector<ll>;
using rpq = priority_queue<int,vi,less<int>>;   // 大きい順
using pq  = priority_queue<int,vi,greater<int>>;// 小さい順

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int dp[1005][1005];
int main() {
  int n,m;cin >> n >> m;
  vi a(n,0),b(m,0);
  rep(i,n) cin >> a.at(i);
  rep(i,m) cin >> b.at(i);

  rep(i,n+1) rep(j,m+1) {
    dp[i][j] = 1001001001;
  }
  dp[0][0] = 0;

  rep(i,n+1) rep(j,m+1) {
    if(i>0 and j > 0) {
      if(a.at(i-1) == b.at(j-1)) {
        dp[i][j] = min(dp[i][j],dp[i-1][j-1]);
      } else {
        dp[i][j] = min(dp[i][j],dp[i-1][j-1] + 1);
      }
    }
      if(i>0) dp[i][j] = min(dp[i][j],dp[i-1][j] + 1);
      if(j>0) dp[i][j] = min(dp[i][j],dp[i][j-1]+1);
  }
  cout << dp[n][m] << endl;

  return 0;
}


#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
const int MOD=1000000007;
//const int MOD=998244353;
struct ModInt {
  unsigned int val;
  ModInt(): val(0) {}
  ModInt(int v) { norm(v%MOD); }
  ModInt(long long v) { norm(v%MOD); }
  ModInt& norm(long long v) {
    v=v<0?v%MOD+MOD:v; // negative
    v=v>=MOD?v-MOD:v; // mod
    val=(unsigned int)v;
    return *this;
  }
  explicit operator bool() const { return val!=0; }
  ModInt operator-() const { return ModInt(0)-*this; }
  ModInt &operator+=(ModInt that) { return norm((long long)val+that.val); }
  ModInt &operator-=(ModInt that) { return norm((long long)val-that.val); }
  ModInt &operator*=(ModInt that) { val=(unsigned long long)val*that.val%MOD; return *this; }
  ModInt &operator/=(ModInt that) { return *this*=that.inv(); }
  ModInt operator+(ModInt that) const { return ModInt(*this)+=that; }
  ModInt operator-(ModInt that) const { return ModInt(*this)-=that; }
  ModInt operator*(ModInt that) const { return ModInt(*this)*=that; }
  ModInt operator/(ModInt that) const { return ModInt(*this)/=that; }
  ModInt pow(long long n) const {
    ModInt x=*this, res=1;
    while(n>0) {
      if(n&1) res*=x;
      x*=x,n>>=1;
    }
    return res;
  }
  ModInt inv() const { return (*this).pow(MOD-2); }
  bool operator==(ModInt that) const { return val==that.val; }
  bool operator!=(ModInt that) const { return val!=that.val; }
  friend ostream& operator<<(ostream& os, const ModInt& that) { return os<<that.val; }
};
// $ cp-batch NowhereP | diff NowhereP.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address NowhereP.cpp && ./a.out

/*

 4/17/2021

 0:24-

 */

LL N,P;

void solve() {
  auto res=ModInt(P-1)*ModInt(P-2).pow(N-1);
  cout<<res<<endl;
}

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

  cin>>N>>P;
  solve();

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long   ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll>  vl;
typedef vector<pair<int,int>> vpi;
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define pb    push_back
#define mp    make_pair
#define rev(i,a,b) for(int i=a;i<b;i++)
#define sz(a)   (int)a.size()
#define all(a)  a.begin(),a.end()
const int  MOD = 1000000000+7;
ll mul(ll x,ll y){return (x*y)%MOD;}
ll bin_pow(ll x,ll p){if(p==0)return 1;if(p&1)return mul(x,bin_pow(x,p-1));return bin_pow(mul(x,x),p/2);}
ll  gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
bool prime(ll n){for(ll i=2;i*i<=n;i++)if(n%i==0)return 0; return 1;}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n;
    cin>>n;
    vi v;
    ll ans=0;
    if(n<1000)
    {
        cout<<0;
        return 0;
    }
    else
    {
       // int d=1;
        vl p(16);
        p[0]=1;
        for(int i=1;i<=15;i++)
        {
            p[i]=p[i-1]*10;
        }
        for(ll i=3;i<=15;i++)
        {
            ll x=p[i];
            ll t=min(n+1,x*10);
            if(t-x>0)
            {
                ans+=(t-x)*(i/3);
            }
            else
                break;

        }
        cout<<ans;
    }

  //  cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define mod 998244353

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int sig=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    sig+=a[i];
  }
  if(sig%2==1){cout << "0\n";return 0;}
  vector<vector<int>> dp(n+1,vector<int>(5005));
  dp[0][0]=1;
  for(int i=0;i<n;i++){
    for(int j=i;j>=0;j--){
      for(int k=0;k<=5000-a[i];k++){
        dp[j+1][k+a[i]]+=dp[j][k];
        dp[j+1][k+a[i]]%=mod;
      }
    }
  }
  long long res=0;
  for(int i=0;i<=n;i++){
    long long cv=dp[i][sig/2];
    for(long long j=1;j<=i;j++){cv*=j;cv%=mod;}
    for(long long j=1;j<=n-i;j++){cv*=j;cv%=mod;}
    res+=cv;res%=mod;
  }
  cout << res << '\n';
  return 0;
}

// Problem: E. String Reversal
// Contest: Codeforces - Educational Codeforces Round 96 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1430/problem/E
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].l+tr[u].r>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;

//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;

int n;
int a[N],b[N];
map<int,vector<int>>v;
struct Node {
	int l,r;
	LL cnt,lazy;
}tr[N<<2];

void pushdown(int u) {
	if(!tr[u].lazy) return;
	LL lazy=tr[u].lazy; tr[u].lazy=0;
	tr[L].lazy+=lazy; tr[R].lazy+=lazy;
	tr[L].cnt+=lazy; tr[R].cnt+=lazy;
}

void build(int u,int l,int r) {
	tr[u]={l,r,1,0};
	if(l==r) {
		tr[u].cnt=l;
		return;
	}
	build(L,l,Mid); build(R,Mid+1,r);
}

void change(int u,int l,int r,int c) {
	if(tr[u].l>=l&&tr[u].r<=r) {
		tr[u].cnt+=c;
		tr[u].lazy+=c;
		return;
	}
	pushdown(u);
	if(l<=Mid) change(L,l,r,c);
	if(r>Mid) change(R,l,r,c);
}

int query(int u,int l,int r) {
	if(tr[u].l>=l&&tr[u].r<=r) return tr[u].cnt;
	int ans=0;
	pushdown(u);
	if(l<=Mid) ans+=query(L,l,r);
	if(r>Mid) ans+=query(R,l,r);
	return ans;
}

LL solve() {
	LL ans=0;
	build(1,1,n);
	for(int i=1;i<=n;i++) {
		int pos=v[b[i]].back(); v[b[i]].pop_back();
		LL now=query(1,pos,pos);
		ans+=now-i;
		change(1,1,pos,1);
	}
	return ans;
}

bool check() {
	map<int,int>mp1,mp2;
	for(int i=1;i<=n;i++) mp1[a[i]]++;
	for(int i=1;i<=n;i++) mp2[b[i]]++;
	for(int i=1;i<=n;i++) if(mp1[a[i]]!=mp2[a[i]]) return false;
	return true;
}

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

	int _=1;
	while(_--) {
		cin>>n;
		for(int i=1;i<=n;i++) scanf("%d",&a[i]),a[i]+=i;
		for(int i=1;i<=n;i++) scanf("%d",&b[i]),b[i]+=i;
		for(int i=n;i>=1;i--) v[a[i]].pb(i);
		if(!check()) {
			puts("-1");
			return 0;
		}
		printf("%lld\n",solve());
	}

	return 0;
}
/*

*/


#include <bits/stdc++.h>

#include <algorithm>
using namespace std;

#define endl "\n"
#define pb push_back
#define fo(i, start, end) for (ll i = start; i < end; i++)
#define rep(i, start, end, step) for (ll i = start; i < end; i += step)
#define print(x) cout << #x << " is " << x << endl
#define all(arg) arg.begin(), arg.end()
#define sz(arg) (int)arg.size()

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

void solve() {
    int n;
    cin >> n;
    vi a(n), b(n);
    fo(i, 0, n) cin >> a[i] >> b[i];
    int ans = INT_MAX;
    int min_index = min_element(all(a)) - a.begin();
    ans = min(ans, a[min_index] + b[min_index]);
    b[min_index] = INT_MAX;
    ans = min(ans, max(a[min_index], *min_element(all(b))));
    cout << ans << endl;
}

int main() {
#ifndef DEBUG
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    solve();
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vi = vector<int>;
using vb = vector<bool>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vpll = vector<pll>;
const ll LINF = 1ll << 55;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 10;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};

/// cin/cout overloading
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &vec) {
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    out << *it << " ";
  }
  return out;
}

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

template <typename T>
istream &operator>>(istream &in, vector<T> &vec) {
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    in >> *it;
  }
  return in;
}

template <typename T>
istream &operator>>(istream &in, pair<T, T> &P) {
  in >> P.first >> P.second;
  return in;
}

#define error(args...)                       \
  {                                          \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr << endl;                            \
  }

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

#define rep(i, begin, end) \
  for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(x) (x).begin(), (x).end()
#define coutp(x, y) cout << (x) << " " << (y) << endl
#define coutn(x) cout << (x) << endl
#define coutd(x) cout << setprecision(10) << (x) << endl

ll calc(const string &S) {
  ll res = 0;
  for (int i = 1; i <= 9; ++i) {
    ll base = 1;
    for (auto c : S) {
      if (c - '0' == i) {
        base *= 10;
      }
    }
    res += i * base;
  }
  return res;
}

/// main函数
int main() {
  ll A, B;
  cin >> A >> B;
  double ans = (double(A) - B) / A * 100;
  coutd(ans);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 1000000007;
#define mod(x) (x % MOD + MOD) % MOD

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

struct SegmentTreeRSQ
{
    ll size;
    vector<ll> dat;
    const ll INITVAL = 0LL;

    SegmentTreeRSQ(ll n)
    {
        size = 1;
        while (size < n)
            size *= 2;

        dat = vector<ll>(2 * size - 1, INITVAL);
    }

    // update k th value to a
    void update(ll k, ll a)
    {
        k += size - 1;
        dat[k] = a;

        while (k > 0)
        {
            k = (k - 1) / 2;
            dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2];
        }
    }

    ll query(ll a, ll b, ll k = 0, ll l = 0, ll r = -1)
    {
        if (r < 0)
            r = size;
        if (r <= a || b <= l)
            return INITVAL;
        if (a <= l && r <= b)
            return dat[k];
        else
        {
            ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return vl + vr;
        }
    }
};

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll h, w, m;
    cin >> h >> w >> m;
    vector<ll> minh(h), minw(w);
    vector<vector<ll>> obs(h);
    fill(minh.begin(), minh.end(), w);
    fill(minw.begin(), minw.end(), h);
    for (int i = 0; i < m; i++)
    {
        ll ht, wt;
        cin >> ht >> wt;
        ht--;
        wt--;
        minh[ht] = min(minh[ht], wt);
        minw[wt] = min(minw[wt], ht);
        obs[ht].push_back(wt);
    }
    SegmentTreeRSQ sg(w);
    ll cnt = 0;
    for (int j = 0; j < minh[0]; j++)
        cnt += minw[j];
    //cout << cnt << endl;
    for (int j = minh[0]; j < w; j++)
        sg.update(j, 1);
    for (int i = 1; i < minw[0]; i++)
    {
        cnt += sg.query(0, minh[i]);
        for (ll j : obs[i])
            sg.update(j, 1);
    }
    cout << cnt << endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<LL,LL> pii;
typedef pair<LL,pii> ppi;
typedef pair<pii,pii> ppp;
#define FOR(i, n) for(int i = 1; i<=n; i++)
#define F0R(i, n) for(int i = 0; i<n; i++)
#define mp make_pair
#define pb push_back
#define f first
#define s second

template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {cout << "["; F0R(i, v.size()) {if (i) cout << ", "; cout << v[i];} return cout << "]";}

//var
const LL INF = 1e18;
LL T, n, a[105], x, dp[105][105];

void filldp(LL g){
	F0R(i, g+1) F0R(j, g+1) dp[i][j] = -INF;
	dp[0][0] = 0;

	FOR(i, n){
		for(int j = g; j>=1; j--){
			for(int k = 0; k<g; k++){
				if(dp[j-1][k] < 0) continue;
				dp[j][(k + a[i]) % g] = max(dp[j][(k + a[i])%g],
											dp[j-1][k] + a[i]);
			}
		}
	}

	//cout << dp[g][0] << '\n';
}

void solve(){
	cin >> n >> x;
	FOR(i, n) cin >> a[i];

	LL ans = INF;
	FOR(i, n){
		filldp(i);
		LL mxval = dp[i][x%i];
		if(mxval < 0) continue;
		LL tt = (x - mxval)/i;
		ans = min(ans, tt);
	}

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

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

	T = 1;
	//cin >> T;
	FOR(t, T)
		solve();

	cout.flush();
	return 0;
}


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

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

using namespace std;

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

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

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)

template<unsigned MOD_> struct ModInt {
    static constexpr unsigned MOD = MOD_;
    unsigned x;
    void undef() { x = (unsigned)-1; }
    bool isnan() const { return x == (unsigned)-1; }
    inline int geti() const { return (int)x; }
    ModInt() { x = 0; }
    ModInt(int y) { if (y<0 || (int)MOD<=y) y %= (int)MOD; if (y<0) y += MOD; x=y; }
    ModInt(unsigned y) { if (MOD<=y) x = y % MOD; else x = y; }
    ModInt(long long y) { if (y<0 || MOD<=y) y %= MOD; if (y<0) y += MOD; x=y; }
    ModInt(unsigned long long y) { if (MOD<=y) x = y % MOD; else x = y; }
    ModInt &operator+=(const ModInt y) { if ((x += y.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(const ModInt y) { if ((x -= y.x) & (1u<<31)) x += MOD; return *this; }
    ModInt &operator*=(const ModInt y) { x = (unsigned long long)x * y.x % MOD; return *this; }
    ModInt &operator/=(const ModInt y) { x = (unsigned long long)x * y.inv().x % MOD; return *this; }
    ModInt operator-() const { return (x ? MOD-x: 0); }

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

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

constexpr LL MOD = 1000000007;
using Mint = ModInt<MOD>;

int N;
int X[200011];
int Y[200011];
LL W[200011];
VI G[200011];

int par[200011];
LL dp[200011];

void MAIN() {
    scanf("%d", &N);
    REP (i, N-1) {
	int x, y;
	LL w;
	scanf("%d%d%lld", &x, &y, &w);
	x--;
	y--;
	G[x].push_back(i);
	G[y].push_back(i);
	X[i] = x;
	Y[i] = y;
	W[i] = w;
    }

    VI que;
    que.push_back(0);
    REP (i, N) {
	int v = que[i];
	EACH (e, G[v]) {
	    int w = v ^ X[*e] ^ Y[*e];
	    if (w == par[v]) continue;

	    dp[w] = dp[v] ^ W[*e];
	    par[w] = v;
	    que.push_back(w);
	}
    }

    Mint ans = 0;
    for (int t=60; t--;) {
	LL a = 0;
	REP (i, N) if (dp[i]>>t&1) a++;
	LL b = N - a;

	ans *= 2;
	ans += a * b;
    }

    printf("%d\n", ans.geti());
}

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

#include<bits/stdc++.h>
using namespace std;
int N;
long long mod = 1000000007;
vector<pair<int, long long>> E[200010];
long long A[200010];
void dfs(int v, int p){
	int res = 0;
	for(int i = 0; i < (int) E[v].size(); i++){
		int c = E[v][i].first;
		if(c == p) continue;
		long long w = E[v][i].second;
		A[c] = (A[v] ^ w);
		dfs(c, v);
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> N;
	for(int i = 0; i < N-1; i++){
		int u, v; long long w;
		cin >> u >> v >> w;
		u--; v--;
		E[u].push_back(make_pair(v, w));
		E[v].push_back(make_pair(u, w));
	}
	long long mul = 1LL;
	long long ans = 0;
	dfs(0, -1);
	for(int d = 0; d < 60; d++){
		long long a = 0;
		for(int i = 0; i < N; i++){
			if((A[i] >> d) & 1) a ++;
		}
		long long add = a * (N - a) % mod;
		ans += mul * add % mod;
		mul *= 2; mul %= mod;
		ans %= mod;
	}
	cout << ans << "\n";
}


#include <iostream>
#include <algorithm>
#include <limits>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <vector>
#include <deque>
#include <cmath>

using namespace std;
int n;
int a[200010];
long long preSum;
long long sum;

int main() {
    scanf("%d", &n);
//    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
//    sort(a.begin(), a.end());
    sort(a, a + n);
    preSum = a[0];
    for (int i = 1; i < n; ++i) {
        sum += ((long long)a[i] * i) - preSum;
        preSum += a[i];
    }
    printf("%lld\n", sum);
    return 0;
}

// {{{ by unolight
#pragma region
#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\n",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));
}
#pragma endregion
// }}}

void main() {
    int n;
    R(n);
    vector<LL> a(n);
    REP(i,n) R(a[i]);
    LL ans=0;
    sort(ALL(a));
    vector<LL> pref(n+1);
    REP(i,n) pref[i+1]=pref[i]+a[i];
    REP(i,n) ans+=pref[n]-pref[i]-a[i]*(n-i);
    W(ans);
}

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


#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = (1<<30) - 1;
const ll linf = 1LL<<61;
const int MAX = 510000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = 3.14159265358979;
const double eps = 1e-8;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<=b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    int n; cin >> n;
    vl t(n),l(n),r(n);
    rep(i,n){
        cin >> t[i] >> l[i] >> r[i];
    }
    int ans = 0;
    rep(i,n) rep(j,i){
        if(l[i] > l[j]){
            if(t[i] <= 2 && t[j] % 2){
                if(l[i] <= r[j]) ans++;
            }else{
                if(l[i] < r[j]) ans++;
            }
        }else{
            if(t[j] <= 2 && t[i] % 2){
                if(l[j] <= r[i]) ans++;
            }else{
                if(l[j] < r[i]) ans++;
            }
        }
    }
    cout << ans << endl;
}

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

#include <bits/stdc++.h>

using namespace std;

#define ll long long

using pos = pair<int, int>;

bool canMoveWith1Move(const pos& from, const pos& to){
    return (
        (from.first + from.second == to.first + to.second) ||
        (from.first - from.second == to.first - to.second) ||
        (abs(from.first - to.first) + abs(from.second - to.second) <= 3)
    );
}

bool canMoveWith2Moves(const pos& from, const pos& to){
    auto color = [](const pos& p) -> int {
        return ((p.first + p.second) % 2 + 2) % 2;
    };

    bool flg = false;
    for (int dx = -3; dx <= 3; ++dx){
        for (int dy = -3; dy <= 3; ++dy){
            pos tmp = {from.first + dx, from.second + dy};
            flg |= (canMoveWith1Move(from, tmp) && canMoveWith1Move(tmp, to));
        }
    }

    return (
        (color(from) == color(to)) ||
        (abs(from.first + from.second - to.first - to.second) <= 4) ||
        (abs(from.first - from.second - to.first + to.second) <= 4) ||
        (flg)
    );
}

int solve(const pos& from, const pos& to){
    if (from == to) return 0;
    if (canMoveWith1Move(from, to)) return 1;
    if (canMoveWith2Moves(from, to)) return 2;
    return 3;
}

int main(void){
    int x, y;
    cin >> x >> y;
    pos from = {x, y};
    cin >> x >> y;
    pos to = {x, y};
    cout << solve(from, to) << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll ;
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define pb push_back

struct ob {
	unsigned long long t,m ;
} ;

bool comp(ob a , ob b)
{
	return a.t<b.t ;
}

int main()
{
	unsigned long long n,c,x,y,z ;
	cin>>n>>c ;
	vector<ob> a ;
	rep(i,0,n)
	{
		cin>>x>>y>>z ;
		ob t,t1 ;
		t.t=x ; t.m=z ;
		a.pb(t) ;
		t1.t=y+1 ; t1.m=-z ;
		a.pb(t1) ;
	}
	sort(a.begin(),a.end(),comp) ;

	unsigned long long t=1 , val=0 , ans=0 , last=0,tmp;
	rep(i,0,a.size())
	{
		if(a[i].t!=t)
		{
			ans += min(c,val)*(a[i].t-t) ;
			t=a[i].t ;
		}
		val += a[i].m ;
	}
	cout<<ans<<endl ;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define sz(v) (v).size()
#define all(v) (v).begin(),(v).end()
#define REP(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define Time (double)clock()/CLOCKS_PER_SEC
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pi;
template <class T> void chmax(T &x,T y) {x=x>y?x:y;return;}
template <class T> void chmin(T &x,T y) {x=x<y?x:y;return;}
template <class T> T sqr(T x) {return x*x;}
template <class T> T gcd(T x,T y) {return y==0?x:gcd(y,x%y);}
template <class T> T lcm(T x,T y) {return x/gcd(x,y)*y;}
const int inf=1000000000,mod=1000000007;
const ll infll=1000000000000000000ll,modll=ll(mod);
const db maxdb=db(infll),eps=1e-14,PI=acos(-1.0);
//#define mydef
//#define LOCAL
#ifdef mydef
#define foreach(v,it) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#endif
#define debug
#define putnum(x) cout<<#x<<": "<<x<<endl
#define putvec(v) cout<<#v<<": ";REP(i,0,sz(v)) cout<<v[i]<<" ";cout<<endl
template <class T> inline void read(T &x){
	T w=1;x=0;char c=getchar();
	while(c<'0'||c>'9') {if(c=='-')w=-1;c=getchar();}
	while(c>='0'&&c<='9') {x=(x<<3)+(x<<1)+(c&15);c=getchar();}
	x*=w;
}
template <class T> inline void write(T x) {
	if(x<0) putchar('-'),x=~x+1;
	if(x) write(x/10),putchar(x%10+'0');
}

map<int,ll> p;

int main() {
	#ifdef LOCAL
		freopen("input.in","r",stdin);
		freopen("output.out","w",stdout);
	#endif
	int n;
	ll C,ans=0ll;
	cin>>n>>C;
	for(int i=1;i<=n;i++) {
		int x,y,z;
		cin>>x>>y>>z;
		p[x-1]+=ll(z);
		p[y]-=ll(z);
	}
	ll cst=0ll,preday=0ll;
	for(map<int,ll>::iterator it=p.begin();it!=p.end();it++) {
		ll fee;
		if(cst>C) fee=C;
		else fee=cst;
		ans+=((*it).fi-preday)*fee;
		cst+=(*it).se;
		preday=(*it).fi;
	}
	cout<<ans<<endl;
	return 0;
}


// Problem: E - White Pawn
// Contest: AtCoder - AtCoder Beginner Contest 203（Sponsored by Panasonic）
// URL: https://atcoder.jp/contests/abc203/tasks/abc203_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Author: abhidot

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define w(x)  int x; cin>>x; while(x--)
using namespace std;
const long long N=200005, INF=2e9+5; //2000000000000000000;

#define debug(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
	cout << vars << " = ";
    string delim = "";
    (..., (cout << delim << values, delim = ", "));
    cout<<"\n";
}

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

void print(bool n){
    if(n){
        cout<<"YES\n";
    }else{
        cout<<"NO\n";
    }
}

int32_t main()
{
    IOS;
    int n,m;
    cin>>n>>m;
    vector<pii> p;
    vector<int> a, b;
    set<int>s;

    for(int i=0;i<m;i++){
    	int x,y;
    	cin>>x>>y;
    	p.pb({x,y});
    }
    s.insert(n);
    sort(all(p));

    int l=0;
    while(l<m){
    	int r=l;
    	a.clear();
    	b.clear();
    	while(r<m&&p[l].ff==p[r].ff) r++;
    	for(int i=l;i<r;i++){
    		int y = p[i].ss;
    		if((s.find(y-1)!=s.end()||s.find(y+1)!=s.end())&&s.find(y)==s.end()) a.pb(y);
    		if((s.find(y-1)==s.end()&&s.find(y+1)==s.end())&&s.find(y)!=s.end()) b.pb(y);
    	}
    	for(auto i:a) s.insert(i);
    	for(auto i:b) s.erase(i);
    	l=r;
    }

    cout<<s.size();
}

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

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,s,e) for(int i=s ; i < e ; i++)
#define rrep(i,s,e) for(int i=s ; i > e ; i--)
#define srep(i,s,e,j) for(int i=s ; i < e ; i+=j)
#define tr(i,x) for(auto i : x)
#define vinp(a) for(int i=0 ; i<a.size() ; i++)cin>>a[i]
#define ainp(a,n) for(int i=0; i<n; i++)cin>>a[i]
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vb vector<bool>
#define vpi vector<pii>
#define maxpqi priority_queue<int>
#define minpqi priority_queue <int, vector<int>, greater<int> >
#define pii pair<int,int>
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define pf push_front
#define endl '\n'
#define br printf("\n")
#define inf 1000000
#define imap map<int,int>
#define uimap unordered_map<int,int>
#define gcd(a,b) __gcd(a,b)
#define mod 1000000007
#define clr(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define lb lower_bound
#define ub upper_bound
#define npos string::npos
#define all(x) x.begin(),x.end()
#define descen greater<int>()
// vector<vector<int>> v( n , vector<int> (m, 0));

//bitset<n>(x).to_string() -- return string // here n is bit length.
// x << y    ====   x*(2^y)
// x >> y    ====   x/(2^y)
// x&1 --- 1 then x is odd
/*
    lower_bound: iterator pointing to the first element which has a value not less than ‘val’.
    upper_bound: iterator pointing to the first element which has a value greater than ‘val’.
*/

// Driver function to sort the vector elements
// by second element of pairs
// -- IN ASCENDING ORDER --
bool comp(const pair<int,int> &a, const pair<int,int> &b){
    return (a.second < b.second);
}

string yes="YES",no="NO";

void solve(){
    int tt = 1;
    // cin >> tt;
    while(tt--){
        int n,m;cin>>n>>m;
        map<int,vi>mat;
        set<int>avai;
        int x,y;
        rep(i,0,m){
            cin>>x>>y;
            mat[x].pb(y);
        }

        avai.insert(n);
        tr(i,mat){
            set<int>add;
            tr(j,mat[i.F]){
                if(avai.find(j-1) != avai.end() || avai.find(j+1) != avai.end()){
                    add.insert(j);
                }
            }
            tr(j,mat[i.F]){
                if(avai.find(j) != avai.end()){
                    avai.erase(j);
                }
            }
            tr(j,add)avai.insert(j);
        }
        cout << avai.size() << endl;
    }
}

int32_t main()
{
    fastio
    // ios::sync_with_stdio(false);
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    solve();
    return 0;
}

/*
// Sort the array in descending order
    sort(arr, arr + n, greater<int>());
*/


#include "bits/stdc++.h"

#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define ll long long
#define mod 1000000007
//#define mod 998244353
#define so(v) sort(v.begin(), v.end())
#define fi first
#define se second

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

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

int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int mI(int a, int m)
{
    return power(a, m - 2, m);
}

#define double long double

int n;
int dp[1000][100];
int fun(int i,int c){
    if(c>11){
        return 0;
    }

    if(i>=n){
        if(c==11)
            return 1;
        else
            return 0;
    }
    if(dp[i][c]!=-1)
        return dp[i][c];
    return dp[i][c]=fun(i + 1, c + 1) + fun(i + 1, c);
}

void solve(){

    cin >> n;
    memset(dp, -1, sizeof(dp));
    cout << fun(1, 0);
}

int32_t main()
{

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  string X;
  cin>>X;
  string a=X.substr(0,X.find('.'));
  cout<<a<<endl;
}


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

int mod = 998244353;
int add(int a, int b) { return a + b - (a + b >= mod) * mod; }
int sub(int a, int b) { return a - b + (a - b < 0) * mod; }
int mul(int a, int b) { return (1ll * a * b) % mod; }

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

    int n;
    cin >> n;
    int a[n], pre[n] = {}, ans = 0;

    for (int &x : a)
        cin >> x;
    sort(a, a + n);

    for (int i = 0; i < n; i++) {
        if (i > 1) {
            pre[i - 2] = mul(pre[i - 2], 2);
            pre[i - 1] = add(a[i - 1], pre[i - 2]);
        }
        pre[i] = add(i ? pre[i - 1] : 0, a[i]);
        ans = add(ans, mul(a[i], pre[i]));
    }
    cout << ans << '\n';
}

#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <utility>
#include <vector>

#define all(v) v.begin(), v.end()
#define rep(i, j) for (ll i = 0; i < j; ++i)
#define rep2(i, j, k) for (ll i = j; i <= k; ++i)
#define rep3(i, j, k) for (ll i = j; i >= k; --i)

using namespace std;

using ld = long double;
using ll = long long;
using pi = pair<int, int>;
using pl = pair<long, long>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;

constexpr int INF = 1000000000;
constexpr int MAX = 500000;
constexpr int MOD = 998244353;
constexpr ll INFLL = 1000000000000000000;

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

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

struct mint {
  ll x;

  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator+=(const mint &a) {
    x += a.x;
    if (x >= MOD)
      x -= MOD;
    return *this;
  }
  mint operator-=(const mint &a) {
    if (x < a.x)
      x += MOD;
    x -= a.x;
    return *this;
  }
  mint operator*=(const mint &a) {
    x = x * a.x % MOD;
    return *this;
  }
  mint operator/=(const mint &a) { return *this *= a.inv(); }
  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 operator/(const mint &a) const { return mint(*this) /= a; }
  mint inv(void) const { return pow(MOD - 2); }
  mint pow(ll a) const {
    if (!a)
      return 1;
    mint t = pow(a >> 1);
    t *= t;
    if (a & 1)
      t *= (*this);
    return t;
  }
  friend ostream &operator<<(ostream &os, const mint &a) {
    os << a.x;
    return os;
  }
};

int main(void) {

  int n;
  cin >> n;

  vl a(n);
  rep(i, n) cin >> a[i];

  sort(all(a));

  mint sum = a[n - 1], ans = 0;
  rep3(i, n - 2, 0) {
    /* cout << sum << endl; */

    ans += sum * a[i];
    sum = sum * 2 + a[i];
  }

  rep(i, n) ans += a[i] * a[i];

  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll n,x; cin>>n>>x;
    string s; cin>>s;
    for(ll i=0;i<n;i++)
    {
        if(s[i]=='x') x--;
        else x++;
        if(x<0) x=0;
    }
    cout<<x<<endl;
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (int)(n); i++)
#define INF 1000000000
//配列 vector<型> 配列名(要素数, 初期値);
//二次元配列 vector<vector<型>> 配列名(要素数縦,vector<int>(要素数横, 初期値))
//配列のサイズ(二次元縦) 配列名.size(), 二次元横 配列名[0].size()
// 1秒間のforループは10^8くらい

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

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

int main() {
  int N, X;
  string S;
  cin >> N >> X >> S;

  REP(i, N) {
    if (S[i] == 'o') {
      X++;
    } else {
      if (X != 0) X--;
    }
  }
  cout << X << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e3+9;
const int MAX=1e2+9;
const double ep=1e-4;
const double ep1=1e-6;
const int mod=77797;
const double inf=1e20;
const double pi=acos(-1);
#define debug1 puts("?");
#define debug(x) cout<<"##"<<(x)<<endl;
#define mk make_pair
#define PII pair<int,int>
#define PDI pair<double,int>
#define PIII pair<int,PII >
#define PIII1 pair<PII,int>
#define PIIII pair<PII,PII >
#define PIL pair<int,ll>
#define PLI pair<ll,int>
#define PLIII pair<PLI,PII >
#define PLL pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define dep(i,a,b) for(int i=(a);i>=(b);--i)
#define sd(x) scanf("%d",&(x))
#define slld(x) scanf("%lld",&(x))
#define sdd(x,y) scanf("%d%d",&(x),&(y))
#define sc(s) scanf("%s",(s))
#define pd(x) printf("%d\n",(x))
#define plld(x) printf("%lld\n",(x))
#define pdk(x) printf("%d ",(x))
#define plldk(x) printf("%lld ",(x))
#define pdd(x,y) printf("%d %d\n",(x),(y))
#define PR(x) printf("Case %d: ",(x))
#define INF 0x3f3f3f3f
typedef unsigned long long ull;
/*
*/
ll dp[64][2];
int n;
char s[5];
void solve()
{
	sd(n);
	dp[0][0]=dp[0][1]=1;
	rep(i,1,n)
	{
		sc(s);
		if(s[0]=='A')
		{
			dp[i][0]=(dp[i-1][0]*2+dp[i-1][1]);
			dp[i][1]=dp[i-1][1];
		}
		else
		{
			dp[i][1]=(dp[i-1][0]+dp[i-1][1]*2);
			dp[i][0]=dp[i-1][0];
		}
	}
	plld(dp[n][1]);
}
int main()
{
//    ios::sync_with_stdio(false);
//    cin.tie(0);
    int T=1;
//    sd(T);
    while(T--)solve();
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <random>
#include <list>
#include <array>
#include <fstream>
#include <chrono>
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<vector<ll> > dp(n + 1, vector<ll>(2, 0));
	dp[0][0] = dp[0][1] = 1;
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		for (int prev = 0; prev < 2; prev++)
		{
			for (int now = 0; now < 2; now++)
			{
				if (s == "AND")
				{
					dp[i + 1][prev & now] += dp[i][prev];
				}
				else
				{
					dp[i + 1][prev | now] += dp[i][prev];
				}
			}
		}
	}
	cout << dp[n][1] << "\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+50;
int sum[N],a[N];
ll n;
ll lowbit(int x)	{	return x&(-x);	}
void add(int pos,int val)
{
	while(pos<=n)
	{
		sum[pos]+=val;
		pos+=lowbit(pos);
	}
}

ll query(int pos)
{
	ll res=0;
	while(pos)
	{
		res+=sum[pos];
		pos-=lowbit(pos);
	}return res;
}

int main()
{
	scanf("%lld",&n);
	ll flag=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		add(a[i],1);flag+=i-query(a[i]);
	}
	vector<int>ans;
	if(flag!=n-1)
	{
		puts("-1");
	}
	else
	{
		for(int i=1;i<=n;i++)
		{
			int cnt=(i-query(a[i]));
			int j=i-1;
			for(int k=0;k<cnt;k++)
			{
				ans.push_back(j);
				j--;
			}
		}
		for(int i=0;i<(int)ans.size();i++)	printf("%d\n",ans[i]);
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define asort(a,n) sort(a,a+n)
#define vsort(v) sort(v.begin(),v.end())
#define all(v) v.begin(),v.end()
#define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define mod 1000000007
#define LL_MAX LLONG_MAX
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

int main()
{
    run;
    ll n,i;

        cin>>n;

        ll a[n+1]={0},x=1,b[n],j,w;
        vector<ll>v1[n+100];
        for(i=0;i<n;i++)
        {
         cin>>a[i];
         v1[a[i]].pb(i);
         b[i]=i+1;
        }
        set<ll>s;
        vector<ll>v;

         for(i=0;i<n;i++)
         {
             if(a[i]!=b[i])
             {
                 //back==if(a[i]>b[i]);
                // aage if(a[i]<b[i]);

               w=v1[b[i]][0];

                x=b[i]-1;

                for(j=w;j>x;j--)
                {
                     v1[a[j]][0]--;
                    v1[a[j-1]][0]++;
                    swap(a[j],a[j-1]);
                    v.push_back(min(j+1,j));

                    if(s.find(min(j+1,j))==s.end())
                    s.insert(min(j+1,j));
                    else
                    {
                        cout<<-1;
                        return 0;
                    }

                    if(v.size()>n-1)
                    {
                        cout<<-1;
                        return 0;
                    }
                }

             }
         }

         if(v.size()!=n-1)
         {
          cout<<-1;
          return 0;
         }

         for(i=0;i<v.size();i++)
          cout<<v[i]<<endl;

}


#include <bits/stdc++.h>
using namespace std;
int main(){
     int n, m, t;
    cin >> n >> m >> t;
    int charge = n, time = 0;
    int c;
    c = 1;

    while(m--){
        int a, b;
        cin >> a >> b;
        charge -= a - time;
        if(charge <= 0) {
            cout << "No"<< endl;
            return 0;
        }
        charge += b - a;
        if(charge > n) charge = n;
        time = b;
    }
    charge -= t - time;

    if(charge <= 0){
        cout << "No" << endl;
    }
    else{
    cout << "Yes";
    }
    return 0;
}

// KNOW NOTHING!
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it)
#define fall(a) a.begin(),a.end()
#define sz(x) (int)x.size()
#define szs(x) (int)x.length()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define eq equal_range
#define fs first
#define ss second
#define ins insert
#define mkp make_pair
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef queue<int> qin;
typedef deque<ll> dqll;
typedef deque<int> dqint;
typedef priority_queue<ll> pqll;
typedef priority_queue<int> pqin;
typedef map<ll,ll> mpll;
typedef map<int,int> mpin;
typedef pair<ll,ll> pll;
typedef pair<int,int> pin;
const ll MOD=1000000007;
const long double PI=3.1415926535897932384626433832795;
ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;}
int msb (int n) {return 31-__builtin_clz(n);}
ll msbl (ll n) {return 63-__builtin_clzll(n);}
int lsb (int n) {return __builtin_ctz(n);}
ll  lsbl (ll n) {return __builtin_ctzll(n);}
int setbit (int n) {return __builtin_popcount(n);}
ll setbitl (ll n) {return __builtin_popcountll(n);}
int main()
{
/*
freopen ("input.txt","r","stdin");
freopen ("output.txt","w","stdout");
*/
ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
ll n,m,t; cin>>n>>m>>t;
vector <array <ll ,2>> a (m);
F (i,0,m,1) {
	cin>>a[i][0]>>a[i][1];
}
ll cap =n , pr=0;
int ok = 0;
F (i,0,m,1) {
	cap =max (0LL,cap-(a[i][0]-pr));
	if (cap==0) ok=1;
	cap=min (n,cap+(a[i][1]-a[i][0]));
	pr=a[i][1];
}
cap=cap-(t-a[m-1][1]);
if (ok) cout<<"No";
else if (cap>0) cout<<"Yes";
else cout<<"No";
return 0;
}
/* What we know is a drop , but what we don't know is an ocean !*/


#include <bits/stdc++.h>
#define ll int
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
// #define int long long
#define F first
#define S second
#define INF 1e18
#define N 200005

using namespace std;

ll n, m;
string g[2005];
ll dp[2005][2005];

ll go(ll x, ll y)
{
	if (x >= n || y >= m)return 0;
	ll &ans = dp[x][y];
	if (ans != -1e9)return ans;
	if (x + 1 < n)
		ans = max(ans, (g[x + 1][y] == '+' ? 1 : -1) - go(x + 1, y));
	if (y + 1 < m)
		ans = max(ans, (g[x][y + 1] == '+' ? 1 : -1) - go(x, y + 1));
	if (ans == -1e9)ans = 0;
	return ans;
}

void solve()
{
	cin >> n >> m;
	for (int i = 0; i < n; ++i)
	{
		cin >> g[i];
	}
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			dp[i][j] = -1e9;
		}
	}
	ll ans = go(0, 0);
	if (ans > 0)cout << "Takahashi" << endl;
	else if (ans < 0)cout << "Aoki" << endl;
	else cout << "Draw" << endl;
}

int32_t main()
{
	IOS
	ll T = 1;
	// cin >> T;
	for (ll i = 1; i <= T; ++i)
	{
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

//include <atcoder>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#define flush fflush(stdout)
#define endl '\n'
#define all(v) v.begin(), v.end()
#define pf(dans) printf("%.12lf", dans)
#define pfn(dans) pf(dans); cout << endl;
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod1 = (int)1e9 + 7, mod2 = (int)998244353;
const int INF = (int)1e9 + 10;
const ll LINF = (ll)1e18 + 10;
const int di[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dj[8] = {0, 1, 0, -1, -1, 1, -1, 1};

#define rep0(i, n) for (i = 0; i < n; i++)
#define rep1(i, a, b) for (i = a; i < b; i++)

template <typename T>
T my_abs(T x){
    return (x >= 0)? x : -x;
}

template <typename T>
void chmax(T &a, T b){
    a = max(a, b);
}

template <typename T>
void chmin(T &a, T b){
    a = min(a, b);
}

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

bool incld_bit(ll bit, int i){
    return ((bit>>i) & 1) == 1;
}

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

int main(void){
    int i, j;
    ll a, b;

    cin >> a >> b;

    vector<int> p;
    rep0(i, 75){
        rep1(j, 2, i){
            if (i % j == 0){
                break;
            }
        }
        if (j == i){
            p.push_back(i);
        }
    }

    int snsbk[75] = {};
    rep0(i, b - a + 1){
        rep0(j, 20){
            if ((a + i) % p[j] == 0){
                snsbk[i] += (1<<j);
            }
        }
    }

    ll dp[75][(1<<20) + 3] = {};
    dp[0][0] = 1;
    rep0(i, b - a + 1){
        rep0(j, 1<<20){
            dp[i + 1][j] = dp[i][j];
            if ((j & snsbk[i]) == snsbk[i]){
                dp[i + 1][j] += dp[i][j - snsbk[i]];
            }
        }
    }

    ll ans;
    ans = 0;
    rep0(j, 1<<20){
        ans += dp[b - a + 1][j];
    }

    cout << ans << endl;

    return 0;
}


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

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define SZ(x) ((int)(x).size())

#define FASTIO() cin.tie(0); ios::sync_with_stdio(false)

// chmax/min: if update a then true
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ceil(a,b) ((a) + ((b) - 1)) / (b)

template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }

//////////////////////////////////////
#define dp(arg) if(KANAILOCAL) { cout << #arg << ":"; dprint(arg); }
template <typename T> void dprint(T arg) { cout << arg << "\n"; }
template <typename T> void dprint(const vector<T>& arg) { for_each(begin(arg), end(arg), [](T value){ cout << value << " "; }   ); cout << "\n";  }
template <typename T> void dprint(const vector<vector<T>>& arg) { for_each(begin(arg), end(arg), [=](vector<T> arg2){ dprint(arg2); cout << "\n";} );  }
template <typename T> void dprint(const unordered_set<T>& arg) { for_each(begin(arg), end(arg), [](T value){ cout << value << " "; }   ); cout << "\n";  }
template <typename T1, typename T2> void dprint(const unordered_map<T1,T2>& arg) { for_each(begin(arg), end(arg), [](auto & x){ cout << x.first << "_" << x.second << " "; }   ); cout << "\n";  }
//////////////////////////////////////
#define Yes std::cout << "Yes" << std::endl;
#define No std::cout << "No" << std::endl;
#define YES std::cout << "YES" << std::endl;
#define NO std::cout << "NO" << std::endl;
//////////////////////////////////////

void inputSample(){
#if 0
    string s; cin.ignore();
    getline(cin, s);
    int n,c;
    cin >> n >> c;
    int x; vector<int> dat(n); REP(i, n){cin << x; dat.at(i) = x;}
    if('a' <= s[i] && s[i] <= 'z'){}
    if('A' <= s[i] && s[i] <= 'Z'){}
#endif
}
template<typename T>
class SparseTable {
    vector<vector<T>> table;
    vector<int> lookup;
    function<T(T, T)> operation;

public:
    SparseTable(const vector<T> &v, function<T(T, T)> ope): operation(ope) {
        int log_len = 0;
        while((1 << log_len) <= (int)v.size()) ++log_len;
        table = vector<vector<T>>(log_len, vector<int>(1 << log_len));
        lookup = vector<int>((int)v.size() + 1);

        for(int i = 0; i < (int)v.size(); i++) {
            table[0][i] = v[i];
        }
        for(int i = 1; i < log_len; i++) {
            for(int j = 0; j + (1 << i) <= (1 << log_len); j++) {
                table[i][j] = operation(table[i-1][j], table[i - 1][j + (1 << (i - 1))]);
            }
        }
        for(int i = 2; i < (int)lookup.size(); i++) {
            lookup[i] = lookup[i >> 1] + 1;
        }
    }

    inline T query(int l, int r) {
        int b = lookup[r - l];
        return operation(table[b][l], table[b][r - (1 << b)]);
    }
};

using namespace std;
int main() {
    FASTIO();

    auto op = [](int a, int b) {return min(a,b);};

    int n; cin >> n;
    int x; vector<int> dat(n); REP(i, n){cin >> x; dat.at(i) = x;}
    int res = 0;

    SparseTable<int> st(dat, op);

    REP(i,n){
        FOR(j, i, n){
            res = max(res, st.query(i, j + 1) * (j-i+1));
        }

    }
    cout << res << "\n";

}

#include <bits/stdc++.h>
typedef long long       ll;
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define mt                make_tuple
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define deb(x)			  cerr << "# " << (#x) << " = " << (x) << endl;
#define sz(x)             (int)x.size()
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int INF = 1234567890;

const int tam = 2010;

char M[2010][2010];
int dist[2010][2010];

vii tele[26];
bool vis[26];

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    int h, w;
    cin >> h >> w;
    fore(i, 0, h) fore(j, 0, w) cin >> M[i][j];
    int stR, stC;
    int enR, enC;
    fore(i, 0, h) fore(j, 0, w) {
        if (M[i][j] == 'S') stR = i, stC = j;
        if (M[i][j] == 'G') enR = i, enC = j;
        char c = M[i][j];
        if ('a' <= c && c <= 'z') {
            tele[c-'a'].pb({i, j});
        }
        dist[i][j] = INF;
    }
    deque<ii> Q;
    dist[stR][stC] = 0;
    Q.push_back({stR, stC});
    int dy[4] = {1,-1,0,0};
    int dx[4] = {0,0,1,-1};
    while (!Q.empty()) {
        int y = Q.front().F;
        int x = Q.front().S;
        Q.pop_front();
        char c = M[y][x];
        if ('a' <= c && c <= 'z' && !vis[c-'a']) {
            vis[c-'a'] = true;
            for (ii u : tele[c-'a']) {
                int a = u.F;
                int b = u.S;
                if (dist[a][b] > dist[y][x] + 1) {
                    dist[a][b] = dist[y][x] + 1;
                    Q.push_back({a, b});
                }
            }
        }
        fore(i, 0, 4) {
            int a = y + dy[i];
            int b = x + dx[i];
            if (a < 0 || b < 0 || a >= h || b >= w) continue;
            if (M[a][b] == '#') continue;
            if (dist[a][b] <= dist[y][x] + 1) continue;
            dist[a][b] = dist[y][x] + 1;
            Q.push_back({a,b});
        }
    }
    cout << (dist[enR][enC] == INF ? -1 : dist[enR][enC]) << '\n';
    return 0;
}
// Dinosaurs are cool!


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

int main() {
    int n;
    cin >> n;
    vector<ll> v(2 * n, 0);
    rep(i, 2 * n) {
        cin >> v[i];
    }
    ll sum = 0, aoki = 0;
    rep(i, 2 * n) sum += v[i];
    priority_queue<ll, vector<ll>, greater<ll>> que;
    for(int i = n - 1; i >= 0; i--) {
        que.push(v[i]);
        que.push(v[2 * n - 1 - i]);
        aoki += que.top();
        que.pop();
    }
    cout << sum - aoki << endl;
    return 0;
}

#pragma region Macros
#include <bits/stdc++.h>
#if defined(LOCAL) || defined(ONLINE_JUDGE) || defined(_DEBUG)
#include <atcoder/all>
#endif
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>using vec = vector<T>;
template<class T, class U>using umap = unordered_map<T, U>;
using ll = long long;
using P = pair<ll, ll>;
using vl = vec<ll>;
#define fi first
#define se second
#define el endl
constexpr ll INF = numeric_limits<ll>::max()/2-1;
#pragma endregion

#pragma region IOMacros
template<class T>
istream &operator>>(istream &stream, vec<T>& o){REP(i, o.size())stream >> o[i];return stream;}
template<class T>
ostream &operator<<(ostream &stream, vec<T>& objs){REP(i, objs.size())stream << objs[i] << " ";stream << el;return stream;}

#define I(T, ...) ;T __VA_ARGS__;__i(__VA_ARGS__);
void __i() {}
template<class T, class... Ts> void __i(T&& o, Ts&&... args){cin >> o;__i(forward<Ts>(args)...);}

void O() {cout << el;}
template<class T, class... Ts> void O(T&& o, Ts&&... args){cerr << o << " ";O(forward<Ts>(args)...);}
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    I(ll, N);
    priority_queue<ll> q;
    unordered_set<ll> mp;
    ll mn = INF;
    REP(i, N){
        I(ll, a);
        if(mp.find(a) == mp.end()){
            chmin(mn, a);
            q.push(a);
            mp.insert(a);
        }
    }
    while(q.size() > 1){
        auto a = q.top(); q.pop();
        a -= mn;
        if (mp.find(a) == mp.end()){
            chmin(mn, a);
            q.push(a);
            mp.insert(a);
        }
    }
    cout << q.top() << el;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <chrono>

using namespace std;

int main() {
  long long int t,n;
  cin>>t>>n;

  vector<long long int> skip;
  long long int pre = 1;
  for(long long int base=1;base<=100;base++){
    if(floor(base*(100+t)/100)-pre>1) skip.push_back(pre+1);
    pre=floor(base*(100+t)/100);
  }
  //for(int i=0;i<(int)skip.size();i++){
  //  cout<<skip[i]<<" ";
  //}

  long long int period = 100+t;
  long long int nSet = n/t;
  //cout<<endl<<nSet<<"*"<<period<<endl;
  //cout<<"n%t = "<<n%t<<endl;
  long long int answer = 0;
  if(n%t==0){
    answer = period*nSet-1;
  }else{
    answer = period*nSet+(skip[n%t-1]);
  }
  cout<<answer<<endl;
  return 0;
}

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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

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

    int t,n; cin >> t >> n;

    ll lo = 0, hi = 1e15;
    while (lo + 1 < hi) {
        ll mi = (lo+hi)/2;
        ll should = mi, reach = (mi * (100+t) / 100);
        if (reach - should >= n) hi = mi;
        else lo = mi;
    }
    cout << hi+n-1 << endl;

    return 0;
}


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

// 插入此處

#define D long long
#define F double
#define mmm(a,b) memset(a,b,sizeof(a))
D read(){ D ans=0; char last=' ',ch=getchar();
while(ch<'0' || ch>'9')last=ch,ch=getchar();
while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar();
if(last=='-')ans=-ans; return ans;
}
const int N=10000000;
const F pi=acos(-1);

D n,m,_n,_m,p=1e9+7,mi;
D f[N+9],mu[N+9];
D pri[664600],now;
bool vis[N+9];
void init(){
    mmm(vis,0);mi=min(m,n);now=0;
    for(D i=1;i<=mi;i++){
        f[i]=((n/i)-(_n-1)/i)*((m/i)-(_m-1)/i);
    }
    mu[1]=1;
    for(int i=2;i<=N;i++){
        if(!vis[i]){
            pri[++now]=i;
            mu[i]=-1;
        }
        for(int j=1;j<=now&&i*pri[j]<=N;j++){
            vis[i*pri[j]]=true;
            if(i%pri[j])mu[i*pri[j]]=-mu[i];//出现新的素数 mu=-mu
            else{
                mu[i*pri[j]]=0;             //出现相同素数
                break;
            }
        }
    }
}

int main(){
	LL l, r;
	cin >> l >> r;
    _n=l,n=r,_m=l,m=r;
    init();
    D coprime=0;
    for(int i=1;i<=mi;i++)
        coprime+=f[i]*mu[i];

	coprime /= 2;

	// printf("coprime = %lld\n", coprime);

	LL num = r - l + 1;
	LL ans = num * (num - 1) / 2;
	// printf("all: %lld\n", ans);

	LL times = 0;
	for (LL i = l; i <= r; i++) {
		times += (r / i - 1);
	}

	LL ret = 0;
	if (l != 1) {
		ret = (ans - times - coprime) * 2;
	} else {
		ret = (ans - coprime - times + r - 1) * 2;
	}

	// printf("times: %lld\n", times);

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

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define DREP(i,s,n) for(int i = (s); i < (n); i++)
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;}
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);
ll gcd(ll a, ll b) {if(b == 0) return a; else return gcd(b,a%b);}
ll lcm(ll a, ll b) {return a*b/gcd(a,b);}

void bfs(vector<vector<int>> &G, int N, int s, vector<int> &dist) {
    dist.assign(N,-1);
    dist[s] = 0;
    queue<int> que;
    que.push(s);
    while(que.size()) {
        int v = que.front();
        que.pop();
        for(int nv : G[v]) {
            if(dist[nv] != -1) continue;
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }
}

int main() {
    int N,M; cin >> N >> M;
    vecveci G(N);
    REP(i,M) {
        int a,b; cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
    }

    ll ans = 0;

    REP(s,N) {
        veci dist(N,-1);
        bfs(G,N,s,dist);
        REP(g,N) {
            if(dist[g] != -1) ans++;
        }
    }

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


#include <cstdio>
#include <algorithm>

const int N = 2e5 + 5;

int a[N];
int b[N];
int ans[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
#endif
	int n;
	while (~scanf("%d", &n)) {
		for (int i = 1; i <= n; ++i) {
			scanf("%d", &a[i]);
			b[a[i]] = i;
		}
		int cnt = 0;
		for (int i = n; i >= 1; --i) {
			for (int k = b[i]; k < i; ++k) {
				std::swap(a[k], a[k + 1]);
				std::swap(b[a[k]], b[a[k + 1]]);
				ans[cnt++] = k;
				if (cnt >= n - 1) {
					break;
				}
			}
			if (cnt >= n - 1) {
				break;
			}
		}
		if (std::is_sorted(a, a +n) && cnt == n - 1) {
			for (int i = 0; i < cnt; ++i) {
				printf("%d\n", ans[i]);
			}
		} else {
			printf("-1\n");
		}
	}
	return 0;
}

/*
	author : pshishod2645
	Created at : 06:05:49 PM, 05 December 2020
*/

#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7;

typedef long long ll;
//#define int long long
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;
// os.find_by_order(k) -> find kth element
// os.order_of_key(x) -> find number of elements strictly less than x

#define cerr cout
#define sz(a) (int)((a).size())
#define all(x) (x).begin(), (x).end()
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
inline int add(int a, int b){a += b; if(a >= MOD)a -= MOD; return a;}
inline int sub(int a, int b){a -= b; if(a < 0)a += MOD; return a;}
inline int mul(int a, int b){return (int)((long long) a * b %MOD);}
inline int binpow(int a, int b){int res = 1; while(b > 0){ if(b & 1)res = mul(res, a); a = mul(a, a);b /= 2;} return res;}
inline int inv(int a){return binpow(a, MOD - 2);}
int gcd(int a, int b, int &x, int &y){if(a == 0){x = 0, y = 1; return b;} int x1, y1;  int d = gcd(b%a, a, x1, y1); x = y1 - (b/a) * x1; y = x1; return d;}
int gcd(int x, int y){return y? gcd(y, x%y) : x; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// uniform_int_distribution<int> (l, r) (rng) 	// generates random number in [l, r] inclusive
// shuffle(beginIter, endIter, rng)	// randomly shuffles elements in range [beginIter, endIter]

const int N = 2e5 + 5;
int n, a[N], possible = 1, pos[N];
vector<int> ops;

void find(int ind){
	// pr(ind); pr(ops);
	if(ind == 1){
		if(a[ind] != 1)possible = 0; return ;
	}

	if(a[ind] == ind){
		possible = 0; return ;
	}
	int prv = pos[ind];
	for(int i = prv; i < ind; ++i){
		ops.push_back(i);
		if(i != prv && a[i + 1] != i){
			// pr(i, a[i + 1], i);
			possible = 0; return ;
		}
	}
	pos[a[prv + 1]] = prv; a[prv] = a[prv + 1];
	find(prv);
}

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

    cin>>n;
    for(int i = 1;i <= n; ++i){
    	cin>>a[i]; pos[a[i]] = i;
    }

    find(n);
    if(!possible){
    	cout<<"-1\n"; return 0;
    }
    for(int i: ops)cout<<i<<"\n";

    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cassert>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<int, int> pi;

const int maxn = 2e5 + 5;
ll a[maxn], b[maxn];
ll c[maxn];
int n;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    ll mx = 0;
    for(int i = 1;i <= n;i++){
        mx = max(a[i], mx);
        cin >> b[i];
        c[i] = max(b[i] * mx, c[i - 1]);
    }
    for(int i = 1;i <= n;i++){
        cout << c[i] << endl;
    }
    return 0;
}

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

int N = 30*30;
int L = 30;

// (i,j) i個下 , j個右
int ind(int a,int b){
	return a*L + b;
}
int Vi(int v){return v/L;}
int Vj(int v){return v%L;}

bool in(int i,int j,int si,int sj,int ti,int tj){
	if(i<min(si,ti) || max(si,ti)<i) return false;
	if(j<min(sj,tj) || max(sj,tj)<j) return false;
	return true;
}
int length(int v1,int v2){return abs(Vi(v1)-Vi(v2))+abs(Vj(v1)-Vj(v2));}

vector<int> VinRectangle(int si,int sj,int ti,int tj){
	// 四角形の中の頂点を始点からマンハッタン距離が小さい順に
	vector< pair<int,int> > Vs;
	FOR(i,min(si,ti),max(si,ti)+1){
		FOR(j,min(sj,tj),max(sj,tj)+1){
			Vs.push_back( { abs(i-si)+abs(j-sj) , ind(i,j) } );
		}
	}
	sort(Vs.begin(), Vs.end());
	vector<int> res;
	for(auto v:Vs) res.push_back(v.second);
	return res;
}

//vector< vector<string> > S(N,vector<string>(N));
vector< vector<long double> > Len(N,vector<long double>(N,INF));
//vector< vector<char> > C(N,vector<char>(N,'.'));
vector< vector<string> > route(N,vector<string>(N)); // Len の時のルートを示す文字列

void first_do_in_main(){
	FOR(i,0,N){
		int ai = Vi(i);
		int aj = Vj(i);
		if( in(ai+1,aj,0,0,L-1,L-1) ){
			Len[i][ind(ai+1,aj)] = 5000.0;
			route[i][ind(ai+1,aj)] = "D";
		}
		if( in(ai-1,aj,0,0,L-1,L-1) ){
			Len[i][ind(ai-1,aj)] = 5000.0;
			route[i][ind(ai-1,aj)] = "U";
		}
		if( in(ai,aj+1,0,0,L-1,L-1) ){
			Len[i][ind(ai,aj+1)] = 5000.0;
			route[i][ind(ai,aj+1)] = "R";
		}
		if( in(ai,aj-1,0,0,L-1,L-1) ){
			Len[i][ind(ai,aj-1)] = 5000.0;
			route[i][ind(ai,aj-1)] = "L";
		}
	}
}
string rev_route(string s){
	reverse(s.begin(), s.end());
	FOR(i,0,s.size()){
		if(s[i] == 'U'){
			s[i] = 'D';
		}else if(s[i] == 'D'){
			s[i] = 'U';
		}else if(s[i] == 'R'){
			s[i] = 'L';
		}else if(s[i] == 'L'){
			s[i] = 'R';
		}
	}
	return s;
}

string do_calc(int si,int sj,int ti, int tj){
	int start,finish;
	vector<long double> d(N,INF); // startからiまでの距離 d[i]
	vector<int> pv(N); // pv[i]はiの前の頂点
	vector<string> rv(N); // pv[i]からiへどうやって来たか

	start = ind(si,sj);
	finish = ind(ti,tj);
	d[start] = 0;
	auto Vs = VinRectangle(si,sj,ti,tj);
	int Nvs = Vs.size();
	FOR(i,0,Nvs){
		FOR(j,0,i){
			// a -> b へのルート
			int a = Vs[j];
			int b = Vs[i];
			if(route[a][b].size() > 0 && d[a]+Len[a][b] < d[b]){
				d[b] = d[a]+Len[a][b];
				pv[b] = a;
				rv[b] = route[a][b];
			}
		}
	}

	vector<string> s;
	while(finish != start){
		s.push_back(rv[finish]);
		finish = pv[finish];
	}

	string res;
	reverse(s.begin(), s.end());
	for(auto s_ : s) res += s_;
	return res;
}

bool check(string s,int si,int sj,int ti,int tj){
	for(char x:s){
		if(x=='U') si--;
		if(x=='D') si++;
		if(x=='R') sj++;
		if(x=='L') sj--;
	}
	return (si==ti)&&(sj==tj);
}

int main(){
	first_do_in_main();

	FOR(k,0,1000){
		int si,sj,ti,tj;
		cin >> si >> sj >> ti >> tj;
		string res = do_calc(si,sj,ti,tj);

		cout << res << endl;
		cout << flush;

		long double be;
		cin >> be;

		//assert(check(res,si,sj,ti,tj));
		//assert(check(rev_route(res),ti,tj,si,sj));

		/*int st = ind(si,sj);
		int fi = ind(ti,tj);
		route[st][fi] = res;
		Len[st][fi] = be;
		route[fi][st] = rev_route(res);
		Len[fi][st] = be;
		*/

	}

}


#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long long ll;
#define G getchar()
int read()
{
	int x=0; bool flg=false; char ch=G;
	for (;!isdigit(ch);ch=G) if (ch=='-') flg=true;
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return flg?-x:x;
}
#undef G
#define fi first
#define se second
/*
const int mod=;
inline int upd(const int &x){return x+(x>>31&mod);}
inline void add(int &x,const int &y){x=upd(x+y-mod);}
inline void iadd(int &x,const int &y){x=upd(x-y);}
int qpow(int x,int y){
	int res=1;
	for (;y;y>>=1,x=1LL*x*x%mod)
		if (y&1) res=1LL*res*x%mod;
	return res;
}
*/
//typedef pair<int,int> P;
#define rep(i,l,r) for (int i(l);i<=int(r);i++)
#define per(i,l,r) for (int i(r);i>=int(l);i--)
#define all(x) (x).begin(),(x).end()
#define forall(x,y) for (const int &y: e[x])

int n;
vector<int> e[200010];
int w[200010],q;

int fat[200010],dep[200010];
void dfs0(int x,int f,int d){
	fat[x]=f; dep[x]=d;
	forall(x,y) if (y^f) dfs0(y,x,d+1);
}
void dfs1(int x,int f){
	w[x]=++q;
	forall(x,y) if (y^f) dfs1(y,x),++q;
}

void solve(){
	n=read();
	rep(i,2,n){
		int u=read(),v=read();
		e[u].pb(v),e[v].pb(u);
	}
	dfs0(1,0,1);
	const int S=max_element(dep+1,dep+n+1)-dep;
	dfs0(S,0,1);
	const int T=max_element(dep+1,dep+n+1)-dep;
	static int p[200010],m;
	for (int i=T;i;i=fat[i]) p[++m]=i;
	reverse(p+1,p+m+1);
	rep(i,1,m){
		const int &x=p[i];
		w[x]=++q;
		forall(x,y) if (y!=p[i+1]&&y!=p[i-1]) dfs1(y,x),++q;
	}
	rep(i,1,n) printf("%d ",w[i]);
	puts("");
}

int main()
{
	for (int T=1;T--;) solve();
	return 0;
}

/*
    /\ In The Name Of Allah /\
    Author : Jawahiir Nabhan
*/
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const char nl = '\n';
const int NM = 2e5 + 10;

int dis[NM],order[NM],vis[NM],depth[NM];
int N,cnt = 1;
vector <int> g[NM];
void dfs1(int u)
{
    vis[u] = 1;
    for(int v : g[u]){
        if(vis[v]) continue;
        dfs1(v);
        depth[u] = max(depth[u], depth[v] + 1);
    }
}
void dfs2(int u)
{
    order[u] = cnt;
    vis[u] = 1;
    vector <pair<int, int>> vec;
    for(int v : g[u])
    {
        if(vis[v]) continue;
        vec.pb({depth[v], v});
    }
    sort(vec.begin(),vec.end());
    for(auto &[x, y] : vec)
    {
        cnt++;
        dfs2(y);
        cnt++;
    }
}
int main()
{
    cin>> N;
    for(int i = 1;i <= N - 1;i++){
        int u,v; cin>> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    for(int i = 1;i <= N;i++) dis[i] = (1 << 30);
    queue <int> q;
    q.push(1);
    dis[1] = 0;
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        for(int v : g[u]){
            if(dis[v] == (1 << 30))
            {
                q.push(v);
                dis[v] = dis[u] + 1;
            }
        }
    }
    int pos,mx = -1;
    for(int i = 1;i <= N;i++){
        if(dis[i] > mx){
            mx = dis[i];
            pos = i;
        }
    }
    dfs1(pos);
    for(int i = 1;i <= N;i++) vis[i] = 0;
    dfs2(pos);
    for(int i = 1;i <= N;i++) cout<< order[i] << ' ';
    cout<< nl;
}


#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
using ll = long long;
struct Edge
{
    ll to;
    ll cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, ll>;
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), v.end()
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = LLONG_MAX;
const int MAX = 510000;
bool graph[nmax][nmax];
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;

    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

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

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

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

    vector<ll> x(n);
    for (int i = n - 1; i >= 0; --i)
    {
        x[i] = X / a[i];
        X %= a[i];
    }

    vector<ll> t(n);
    for (int i = 0; i < n - 1; i++)
    {
        t[i] = a[i + 1] / a[i];
    }
    t[n - 1] = 1e18;

    vector<ll> dp(2);
    dp[0] = 1;
    for (int i = 0; i < n; i++)
    {
        vector<ll> p(2); // dp[i-1]
        swap(dp, p);
        for (int j = 0; j < 2; j++)
        {
            for (int nj = 0; nj < 2; nj++)
            {
                // x + z + j = y + nj*t[i]
                // z = y + nj*t[i] - x - j;
                {
                    // y == 0
                    ll z = 0 + t[i] * nj - x[i] - j;
                    if (0 <= z && z < t[i])
                        dp[nj] += p[j];
                }
                {
                    // z == 0;
                    ll y = x[i] + 0 + j - nj * t[i];
                    if (0 < y && y < t[i])
                        dp[nj] += p[j];
                }
            }
        }
    }

    cout << dp[0] << endl;

    return 0;
}

//#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
#include<string.h>
#define un unsigned
#define srd srand(time(0))
#define ll long long
#define con continue
#define gtc getchar()
#define ptc putchar
#define dou double
#define eps 0.00000000001
#define opr operator
#define cl(x,a) memset(x,a,sizeof(x))
#define fo0(i,k) for(i=fr[k];i;i=nx[i])
#define fo1(i,l,r) for(i=l;i<=r;i++)
#define fo2(i,l,r) for(i=l;i>=r;i--)
#define fo(i,n) for(i=1;i<=n;i++)
#define ret return
#define x first
#define cint const int
#define y second
#define opi(x) freopen(x,"r",stdin)
#define opo(x) freopen(x,"w",stdout)
#define tpl template<class T>
#define priq priority_queue
#define mp make_pair
#define use using namespace
#define WT while(T--)
use std;
typedef pair<int,int> pii;typedef pair<int,ll> pil;typedef pair<ll,int> pli;typedef pair<ll,ll> pll;
namespace io
{
	void _(int &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;}
	void _(ll &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;}
	void _(char &c){while((c=gtc)==' '||c=='\n');}void _(dou &c){scanf("%lf",&c);}void _(char *s){char c;while((c=gtc)!=EOF&&c!=' '&&c!=10)*s++=c;}
	template<class t1,class t2>void _(t1 &a,t2 &b){_(a);_(b);}template<class t1,class t2,class t3>void _(t1 &a,t2 &b,t3 &c){_(a);_(b);_(c);}
	template<class t1,class t2,class t3,class t4>void _(t1 &a,t2 &b,t3 &c,t4 &d){_(a);_(b);_(c);_(d);}
	template<class t1,class t2,class t3,class t4,class t5>void _(t1 &a,t2 &b,t3 &c,t4 &d,t5 &e){_(a);_(b);_(c);_(d);_(e);}
	void _p(dou k){printf("%.6lf",k);}void _p(char *c){for(;*c;ptc(*c++));}void _p(const char *c){for(;*c;ptc(*c++));}void _p(char c){ptc(c);}
	tpl void _p0(T k){if(k>=10)_p0(k/10);ptc(k%10+'0');}tpl void _p(T k){if(k<0){ptc('-');_p0(-k);}else _p0(k);}tpl void __p(T k){_p(k);ptc(' ');}
	tpl void _pn(T k){_p(k);ptc('\n');}template<class t1,class t2>void _p(t1 a,t2 b){__p(a);_pn(b);}
	template<class t1,class t2,class t3>void _p(t1 a,t2 b,t3 c){__p(a);__p(b);_pn(c);}
	template<class t1,class t2,class t3,class t4>void _p(t1 a,t2 b,t3 c,t4 d){__p(a);__p(b);__p(c);_pn(d);}
	tpl void op(T *a,int n){int i;n--;fo(i,n)__p(a[i]);_pn(a[n+1]);}int gi(){int x;_(x);ret x;}ll gll(){ll x;_(x);ret x;}
}
int gcd(int a,int b){ret b?gcd(b,a%b):a;}void fcl(){fclose(stdin);fclose(stdout);}
void fop(const char *s){char c[256],d[256];cl(c,0);cl(d,0);strcpy(c,s);strcpy(d,s);opi(strcat(c,".in"));opo(strcat(d,".out"));}
int eq(dou a,dou b){return a+eps>=b&&b+eps>=a;}tpl void _ma(T &a,T b){if(a<b)a=b;}tpl void _mi(T &a,T b){if(a>b)a=b;}
cint N=1234567,EE=100000000,GG=1000000000,ima=2147483647;
use io;
int n,m,a[N],f[N],T;
char an[666][666];
void ck(int k,int x,int y,int b)
{
	if(k==0)
		an[x][y]='A'+b;
	else
	{
		ck(k-1,x,y,b);
		ck(k-1,x+(1<<(k-1)),y,b);
		ck(k-1,x,y+(1<<(k-1)),b);
		ck(k-1,x+(1<<(k-1)),y+(1<<(k-1)),b^1);
	}
}
int main()
{
	int i,j,a1,a2;
	_(n);
	ck(n,0,0,0);
	_pn((1<<n)-1);
	fo(i,(1<<n)-1)
		puts(an[i]);
}


#include <algorithm>
#include <array>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
#define int long long
#define ll long long
#define INF 1LL << 33
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define SHOW(p) \
    if (test)   \
        cout << #p " : " << p << endl;
//bool test = true;
bool test = false;
template <class T>
[[maybe_unused]] bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
int N, max_A, max_B, tmp, ans;
vector<pair<int, int>> A, B;
bool same;
signed main()
{
    cin >> N;
    A.resize(N);
    B.resize(N);
    REP(i, N)
    {
        cin >> tmp;
        A.at(i) = {tmp, i};
        cin >> tmp;
        B.at(i) = {tmp, i};
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    max_A = A.at(0).first;
    max_B = B.at(0).first;
    ans = max_A + max_B;
    REP(i, N)
    {
        if (ans < A.at(i).first)
            break;
        REP(j, N)
        {
            if (test)
                cout << "i: " << i << " j: " << j << endl;
            if (ans < B.at(i).first)
                break;
            if (A.at(i).second != B.at(j).second) {
                same = false;
                chmin(ans, max(A.at(i).first, B.at(j).first));
            } else {
                same = true;
                chmin(ans, A.at(i).first + B.at(j).first);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);cerr<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T> void verr(const set<T> &st) { repa(a, st) cerr << a << " "; cerr << endl; }
template <class S, class T> void verr(const map<S, T> &mp) { repa(a, mp) cerr << "{" << a.first << ", " << a.second << "} "; cerr << endl; }
template <class S, class T, class N> void verr(const vector<pair<S,T>>& a, const N& n) { rep(i, n) cerr << "{" << a[i].first << ", " << a[i].second << "} "; cerr << endl; }
template <class T, class N> void verr(const vector<T>& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << endl; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << endl; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    ll N;
    cin >> N;
    vl C(N);
    rep(i, N) cin >> C[i], C[i]--;
    vvc<ll> G(N);
    rep(i, N - 1){
        ll a, b;
        cin >> a >> b;
        a--, b--;
        G[a].eb(b), G[b].eb(a);
    }

    vl ok(N), U(100000, -1);
    auto dfs = [&](auto&& dfs, ll now, ll par) -> void {
        if(U[C[now]] == -1) {
            ok[now] = 1;
            U[C[now]] = now;
        }
        repa(to, G[now]){
            if (to == par) continue;
            dfs(dfs, to, now);
        }
        if(U[C[now]] == now){
            U[C[now]] = -1;
        }
    };

    dfs(dfs, 0, -1);
    rep(i, N){
        if(ok[i]){
            cout << i + 1 << '\n';
        }
    }
}


#ifdef __LOCAL
  #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#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 rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

ll rui(ll a,ll n){
  ll ans=1;
  while(n>0){
    if(n&1) ans=ans*a%mod;
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

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, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint dp[1010];

int main(){
  dp[1]=2;
  dp[2]=3;
  rep1(i,1e3) dp[i+2]=dp[i+1]+dp[i];
  int n; cin >> n;
  char a,b,c,d; cin >> a >> b >> c >> d;
  if(n==2||n==3){
    cout << 1 << endl;
    return 0;
  }
  if(b=='B'){
    if(d=='B'){
      cout << 1 << endl;
    }
    else{
      if(c=='A'){
        cout << rui(2,n-3) << endl;
      }
      else{
        cout << dp[n-3] << endl;
      }
    }
  }
  else{
    if(a=='A'){
      cout << 1 << endl;
    }
    else{
      if(c=='B'){
        cout << rui(2,n-3) << endl;
      }
      else{
        cout << dp[n-3] << endl;
      }
    }
  }

}

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string(string(s)); }
string to_string(bool b) { return to_string(int(b)); }
string to_string(vector<bool>::reference b) { return to_string(int(b)); }
string to_string(char b) { return "'" + string(1, b) + "'"; }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) {
	string res = "{";
	for (const auto& x : v) res += (res == "{" ? "" : ", ") + to_string(x);
	return res + "}";
}
void debug() { cerr << endl; }
template <typename Head, typename... Tail>
void debug(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug(T...);
}
#define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define db(...) 42
#endif
typedef long long ll;
typedef long double ld;
const int MAXN = 100005;
int val[MAXN];
vector<pair<int, int>> E[MAXN];
int n;
void go(int x) {
	for (auto& e : E[x]) {
		int y = e.first, c = e.second;
		if (val[y]) continue;
		if (c == val[x]) val[y] = (c == n ? 1 : c + 1);
		else val[y] = c;
		go(y);
	}
}
int main() {
	int m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) {
		int u, v, c;
		scanf("%d%d%d", &u, &v, &c);
		E[u].push_back({v, c});
		E[v].push_back({u, c});
	}
	val[1] = 1;
	go(1);
	for (int i = 1; i <= n; ++i) printf("%d\n", val[i]);
}