//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int MOD=1000000007;

int n,m;
string grid[2005];
ll p2[4000005];

int l[2005][2005];
int r[2005][2005];
int up[2005][2005];
int down[2005][2005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);

	cin>>n>>m;
	rep(x,0,n) cin>>grid[x];

	p2[0]=1;
	rep(x,1,4000005) p2[x]=p2[x-1]*2%MOD;

	ll tot=0;

	rep(x,0,n) rep(y,0,m) if (grid[x][y]=='.') tot++;
	ll ans=tot*p2[tot]%MOD;

	rep(x,0,n) rep(y,0,m){
		if (grid[x][y]=='#') l[x][y]=0;
		else if (y==0) l[x][y]=1;
		else l[x][y]=l[x][y-1]+1;
	}

	rep(x,0,n) rep(y,m,0){
		if (grid[x][y]=='#') r[x][y]=0;
		else if (y==m-1) r[x][y]=1;
		else r[x][y]=r[x][y+1]+1;
	}

	rep(x,0,n) rep(y,0,m){
		if (grid[x][y]=='#') down[x][y]=0;
		else if (x==0) down[x][y]=1;
		else down[x][y]=down[x-1][y]+1;
	}

	rep(x,n,0) rep(y,0,m){
		if (grid[x][y]=='#') up[x][y]=0;
		else if (x==n-1) up[x][y]=1;
		else up[x][y]=up[x+1][y]+1;
	}

	rep(x,0,n) rep(y,0,m) if (grid[x][y]=='.'){
		int curr=l[x][y]+r[x][y]+up[x][y]+down[x][y]-3;

		ans=(ans-p2[tot-curr]+MOD)%MOD;

		//cout<<curr<<endl;
	}

	cout<<ans<<endl;
}

#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define debugArray(x, n)                                      \
  cerr << __LINE__ << ": " << #x << " = {";                   \
  for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];                   \
  cerr << "}" << '\n'
#define debugMatrix(x, h, w)                                         \
  cerr << __LINE__ << ": " << #x << " =\n";                          \
  for (long long hoge = 0; (hoge) < (long long)(h); ++(hoge)) {      \
    cerr << ((hoge ? " {" : "{{"));                                  \
    for (long long fuga = 0; (fuga) < (long long)(w); ++(fuga))      \
      cerr << ((fuga ? ", " : "")) << x[hoge][fuga];                 \
    cerr << "}" << (hoge + 1 == (long long)(h) ? "}" : ",") << '\n'; \
  }
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#define debugMatrix(x, h, w) (void(0))
#endif

template <int mod>
struct ModInt {
  int64_t x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod)) {}
  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) { return *this *= p.inverse(); }
  ModInt operator-() const { return ModInt() - *this; }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b) t = a / b, swap(a -= t * b, b), swap(u -= t * v, v);
    return ModInt(u);
  }
  ModInt pow(int64_t e) const {
    ModInt ret(1);
    for (ModInt b = *this; e; e >>= 1, b *= b)
      if (e & 1) ret *= b;
    return ret;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int modulo() { return mod; }
  int get() const { return x; }
};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  using Mint = ModInt<int(1e9 + 7)>;
  int H, W;
  cin >> H >> W;
  string S[H];
  for (int i = 0; i < H; i++) cin >> S[i];
  Mint ans = 0;
  int u[H][W], l[H][W];
  int K = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      u[i][j] = 0;
      l[i][j] = 0;
      if (S[i][j] == '#') continue;
      u[i][j] = 1;
      l[i][j] = 1;
      K++;
      if (i > 0) u[i][j] += u[i - 1][j];
      if (j > 0) l[i][j] += l[i][j - 1];
    }
  }
  int d[H][W], r[H][W];
  for (int i = H - 1; i >= 0; i--) {
    for (int j = W - 1; j >= 0; j--) {
      d[i][j] = 0;
      r[i][j] = 0;
      if (S[i][j] == '#') continue;
      d[i][j] = 1;
      r[i][j] = 1;
      if (i + 1 < H) d[i][j] += d[i + 1][j];
      if (j + 1 < W) r[i][j] += r[i][j + 1];
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') continue;
      int k = u[i][j] - 1 + d[i][j] - 1 + l[i][j] - 1 + r[i][j] - 1 + 1;
      ans += (Mint(2).pow(k) - 1) * Mint(2).pow(K - k);
    }
  }
  cout << ans << '\n';
  return 0;
}


// C++ program to implement Best First Search using priority
// queue
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, int> pi;

struct node {
    int next, c, d;
    node(int next, int c, int d) {
        this->next = next;
        this->c = c;
        this->d = d;
    }
};

vector<vector<node> > graph;

// Function for adding edges to graph
void addedge(int a, int b, int c, int d)
{
	graph[a-1].push_back(node(b-1, c, d));
	graph[b-1].push_back(node(a-1, c, d));
}

// Function For Implementing Best First Search
// Gives output path having lowest cost
long long dijkstra(int source, int target, int n)
{
    vector<bool> visited(n, false);

	// MIN HEAP priority queue
	priority_queue<pi, vector<pi>, greater<pi> > pq;
	// sorting in pq gets done by first value of pair
	pq.push(make_pair(0, source));

	while (!pq.empty()) {
		int x = pq.top().second;
		long long t = pq.top().first;
		// Displaying the path having lowest cost
        // cout << x << "," << t << ' ';
		pq.pop();

		if (visited[x])
		    continue;
		visited[x] = true;

		if (x == target)
			return t;

		for (node v: graph[x]) {
			if (!visited[v.next]) {
			    long long t_best = ceil(sqrt((double)v.d))-1;
			    if (t_best < t)
			        t_best = t;
			    long long t_next = t_best + (long long)v.c + floor((double)v.d / (t_best+1));
				pq.push(make_pair(t_next, v.next));
			}
		}
	}
	return -1;
}

// Driver code to test above methods
int main()
{
	int n, m;
	cin >> n >> m;

	graph.resize(n);

	int a, b, c, d;
	for (int i = 0; i < m; i++) {
	    cin >> a >> b >> c >> d;
	    addedge(a, b, c, d);
	}

	// Function call
	cout << dijkstra(0, n-1, n);

	return 0;
}

#include <cstdio>
#include <algorithm>
#include <ctype.h>
const int bufSize = 1e6;
#define int long long
inline char nc()
{
    #ifdef DEBUG
    return getchar();
    #endif
    static char buf[bufSize], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufSize, stdin), p1 == p2) ? EOF : *p1++;
}
inline void read(char *s)
{
    static char c;
    for (; !isalpha(c); c = nc());
    for (; isalpha(c); c = nc()) *s++ = c;
    *s = '\0';
}
template<typename T>
inline T read(T &r)
{
    static char c;
    static int flag;
    flag = 1, r = 0;
    for (c = nc(); !isdigit(c); c = nc()) if (c == '-') flag = -1;
    for (; isdigit(c); c = nc()) r = r * 10 + c - 48;
    return r *= flag;
}
const int maxn = 2e5 + 100;
int n, a[maxn], b[maxn],res;
signed main()
{
    read(n);
    long long now = 0;
    for (int i = 1; i <= n; ++i) read(a[i]),read(b[i]),now -= a[i],a[i] = b[i] + 2 * a[i];
    std::sort(a + 1,a + 1 + n);
    for(int i = n;i;--i)
    {
        if (now > 0) { printf("%lld\n", res); return 0; }
        now += a[i], ++res;
    }
    printf("%lld\n", res);
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;
#define ar array
clock_t time_req = clock()*1.0/CLOCKS_PER_SEC;

map<int,pair<int,int>> read(int n , int L){
	vector<int> v{0};
	for(int i = 1 ; i <= n + 1; i++){
		int ai = L+1;
		if(i <= n){
			cin >> ai;
		}
		v.push_back(ai-i);
	}
	map<int,pair<int,int>> interval;
	for(int i = 0 ; i < (int)v.size() ; i++){
		if( i == 0 || v[i] != v[i-1]){
			interval[v[i]].first = i;
		}
		interval[v[i]].second = i;
	}
	return interval;
}

void test_case() {
	int n , L;
	cin >> n >> L;
	auto a = read(n,L);
	auto b = read(n,L);
	debug() << imie(a);
	debug() << imie(b);
	ll answer = 0;
	for(auto pp : b){
		int value = pp.first;
		if(!a.count(value)){
			puts("-1");
			return;
		}
		answer += max(0,a[value].first - b[value].first) + max(0,b[value].second - a[value].second);
	}
	cout<<answer<<"\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T = 1;
	//cin >> T;
	while(T--){
		test_case();
	}
}

#include<bits/stdc++.h>

typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 mrand(42);
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define al(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define asdd cout<<"okok"<<endl;
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl;
#define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl;
#define pc(x) __builtin_popcount(x)
#define pb push_back
#define PS string qqwwee;cin>>qqwwee;
typedef pair<int,int> pii;

int a[100005], b[100005];
ll solve(int l, int r, int L, int R) {
    if(l > r) return 0;
    int left = 0, right = 0;
    for(int i=l;i<=r;++i) {
        if(b[i] < a[i]) left = i;
        else if(a[i] < b[i]) {
            if(!right) right = i;
        } else assert(0);
    }
    if(left && right) {
        if(left > right) return -1;
        assert(left + 1 == right);
        ll tmp1 = solve(l, left, L, a[left]+1);
        ll tmp2 = solve(right, r, a[left], R);
        if(tmp1 == -1 || tmp2 == -1) return -1;
        return tmp1 + tmp2;
    }
    if(right) {
        for(int i=l;i<=r;++i) a[i]=-a[i],b[i]=-b[i];
        reverse(a+l,a+r+1);
        reverse(b+l,b+r+1);
        L=-R;
    }
    unordered_map<int,int> mp;
    ll ret=0;
    mp[L-(l-1)]=l-1;
    for(int i=l;i<=r;++i) {
        if(!mp.count(b[i]-i)) return -1;
        ret+=i-mp[b[i]-i];
        mp[b[i]-i]=mp[a[i]-i]=i;
    }
    return ret;
}
int main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n, l;
    cin >> n >> l;
    for(int i=1;i<=n;++i) cin >> a[i];
    for(int i=1;i<=n;++i) cin >> b[i];
    ll ans = 0, lst = 1, lstl = 0;
    for(int i=1;i<=n;++i) {
        if(a[i] == b[i]) {
            ll tmp = solve(lst, i-1, lstl, b[i]);
            if(tmp < 0) {
                ans = -1;
                break;
            }
            ans += tmp;
            lst = i+1;
            lstl = a[i];
        }
    }
    if(ans != -1) {
        ll tmp = solve(lst, n, lstl, l+1);
        if(tmp < 0) ans = -1;
        else ans += tmp;
    }
    cout << ans << endl;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <ctime>
#pragma warning(disable:4996)

#include <iostream>
#include <iomanip>

using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
template<typename T1, typename T2> bool chmin(T1 &a, T2 b) { if (a <= b)return 0; a = b; return 1; }
template<typename T1, typename T2> bool chmax(T1 &a, T2 b) { if (a >= b)return 0; a = b; return 1; }
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
long double eps = 1e-9;
long double pi = acos(-1);

template< int mod = 1000000007 >
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {
        if ((x += p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if ((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt< mod >(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

// const int mod = 1000000007;
const int mod = 998244353;
using mint = ModInt< mod >;
const int MAX = 200005;

mint 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;
    }
    finv[MAX - 1] = fac[MAX - 1].inverse();
    for (int i = MAX - 2; i >= 1; i--) {
        finv[i] = finv[i + 1] * (i + 1);
        inv[i + 1] = fac[i] * finv[i + 1];
    }
}

// 二項係数計算
mint 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]);
}

mint ans = 0;
ll n, m;
ll mp[200020][20];

mint dfs(ll now, ll cnt) {
    if (mp[now][cnt]>=0) {
        return mp[now][cnt];
    }
    mint ret = COM(n - 1, cnt - 1);
    for (ll i = 2; i <= m; i++) {
        if (now*i <= m)ret += dfs(now*i, cnt + 1);
        else break;
    }
    mp[now][cnt] = ret.x;
    return ret;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    cin >> n >> m;

    fill(mp[0], mp[200005], -1);

    COMinit();
    for (int i = 1; i <= m; i++) {
        ans += dfs(i, 1);
    }
    cout << ans << endl;
}

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

typedef long long ll;
const ll MOD = 1000000007;
const int M = 998244353;

int n,m;
vector<bool> num(210000,true);
vector<int> prime(210000,-1);

vector<ll> fac(210000); //n!(mod M)
vector<ll> ifac(210000); //k!^{M-2} (mod M)

inline ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

inline ll comb(int a, int b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

void Eratos(){
    num[0] = num[1] = false;
    int itr = 0;
    for(int i = 2;i < 210000;i++){
        if(num[i]){
            for(int j = 2*i;j <= 210000;j += i){
                num[j] = false;
            }
            prime[itr] = i;
            itr++;
        }
    }
}

ll solve(int n,int m){
    ll res = 0;
    ll add = 1;
    for(int j = 1;j <= m;j++){
        add = 1;
        int num = j;
        for(int i = 0;prime[i] != -1 && prime[i] <= num;i++){
            int cnt = 0;
            while(num % prime[i] == 0){
                cnt++;
                num /= prime[i];
            }
            // cout << j << sp << prime[i] << sp << cnt << sp << endl;
            // cout << "comb" << n-2+cnt << sp << cnt << sp << comb(n-2+cnt,cnt) << endl;
            add *= comb(n-2+cnt,cnt);
            add %= M;
        }
        //cout << add << endl;
        res += add*(m/j);
        res %= M;
    }
    return res;
}

int main(){
    cin >> n >> m;
    Eratos();
    fac[0] = 1;
    ifac[0] = 1;
    for(int i = 0;i <= 210000;i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    cout << solve(n,m) << endl;
}


// Problem: E - Unique Color
// Contest: AtCoder - AtCoder Beginner Contest 198
// URL: https://atcoder.jp/contests/abc198/tasks/abc198_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define int long long
#define ld long double
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#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 vii vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define w(x)  int x; cin>>x; while(x--)
#define in(a) for(auto &x: a)cin>>x;
#define out(a) for(auto x: a){cout<<x<<'\n';}
#define inf 1000000000
//#define mm 1000000007 998244353
void print(bool n){if(n)cout<<"YES";else cout<<"NO";}
vector<vi> adj;
vi c;
vi ans;
multiset <int, greater <int>> col;
void dfs(int v,int par){
	if(col.empty() || col.find(c[v])==col.end())ans.pb(v+1);
	col.insert(c[v]);
	for(auto u: adj[v]){
		if(u==par)continue;
		dfs(u,v);
	}
	col.erase(col.find(c[v]));
}
signed main(){
	fastio
	int n;
	cin>>n;
	c.resize(n);
	in(c);
	adj.resize(n);
	rep(i,0,n-1){
		int x,y;
		cin>>x>>y;
		--x;--y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	dfs(0,-1);
	sort(all(ans));
	out(ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int mod=998244353;
int n;
int a[200005];
int b[200005];
int vis[200005];

int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        b[a[i]]++;
    }
    int tmp=1;
    for (int i=1;i<=n;i++)
    {
        if (vis[i]==0 && b[i]>0)
        {
            vis[i]=i;
            int x=a[i];
            while (vis[x]==0)
            {
                vis[x]=i;
                x=a[x];
            }
            if (vis[x]==i) tmp=tmp*2%mod;
        }
    }
    cout<<tmp-1<<endl;
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

typedef long long tnum;

#define loop(i, num) for(int i = 0; i < num; i++)

tnum* tnumAlloc(int num);
tnum getNumStdin();
tnum* getNumsStdin(int);
char* getCharsStdin(int maxlength);
string getStringStdin();
void printlnNums(int count, tnum* nums);
void printlnNum(tnum num);
void printString(string str);

#define min(a,b) (a <= b ? a : b)
#define max(a,b) (a >= n ? a : b)

/*void sort(T* start, T* end) (in <algorithm>)
example:
	int a[5] = {2, 1, 3, 5, 4};
	sort(a, a + 5);
	-> a: {1, 2, 3, 4, 5}
*/

int main() {
	loop(i, 101) {
		char c = (char) getchar();
		if (c == '\n' || c == '\r' || c == '.' || c == ' ') {
			break;
		}
		printf("%c", c);
	}

	return 0;
}

//have to be free()
tnum* tnumAlloc(int num) {
	return (tnum*)calloc(num,sizeof(tnum));
}

tnum getNumStdin() {
	tnum ret;
	cin >> ret;

	return ret;
}

//have to be free()
tnum* getNumsStdin(int num) {
	tnum* buf;
	tnum* tmp;
	buf = tnumAlloc(num);
	for (int i = 0; i < num; i++) {
		cin >> buf[i];
	}

	return buf;
}

//have to be free()
char* getCharsStdin(int maxlength) {
	char* ret = (char*)malloc(maxlength+1);
	scanf("%s", ret);

	return ret;
}

//have to be free()
string getStringStdin() {
	string ret;
	cin >> ret;
	return ret;
}

void printlnNum(tnum num) {
	cout << num << endl;
}

// can be used for debugging
void printlnNums(int count, tnum *nums) {
	loop(i, count) {
		cout << nums[i];
		if (i != count - 1) printf(" ");
	}
	printf("\n");
}

void printString(string str) {
	cout << str;
}

/*
 * @Author: Krishnakant
 * @Date: 2021-03-19 23:18:20
 * @Last Modified by: Krishnakant
 * @Last Modified time: 2021-03-20 01:23:11
 */
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
typedef long long ll;
#define _cin                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);
#define endl "\n"
#define pb push_back
#define rp(i, b) for (ll i = 0; i < b; ++i)
#define rpd(i, a) for (ll i = a; i >= 0; --i)
#define mp make_pair
#define hell 1000000007
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define mll map<ll, ll>
#define sz(x) (ll) x.size()
#define sll set<ll>
#define pll pair<ll, ll>
#define F first
#define S second
#define eb emplace_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define precise(x) cout << fixed << setprecision(x)
const ll MAX = 1000004;
const ll INF = 1e18L + 5;
template <class T, class U>
void chmin(T &t, const U &u)
{
    if (t > u)
        t = u;
}
template <class T, class U>
void chmax(T &t, const U &u)
{
    if (t < u)
        t = u;
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << H;
    debug_out(T...);
}
template <typename Arg1>
void pn(Arg1 &&arg1)
{
    cout << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void pn(Arg1 &&arg1, Args &&...args)
{
    cout << arg1 << "\n";
    pn(args...);
}
template <typename Arg1>
void ps(Arg1 &&arg1)
{
    cout << arg1 << " ";
}
template <typename Arg1, typename... Args>
void ps(Arg1 &&arg1, Args &&...args)
{
    cout << arg1 << " ";
    ps(args...);
}
template <typename Arg1>
void read(Arg1 &&arg1)
{
    cin >> arg1;
}
template <typename Arg1, typename... Args>
void read(Arg1 &&arg1, Args &&...args)
{
    cin >> arg1;
    read(args...);
}

void solve()
{
    string s;
    read(s);
    string ans = "";
    for (auto i : s)
    {
        if (i == '.')
            break;
        ans += i;
    }
    pn(ans);
}

int main()
{

    _cin
        ll tc = 1;
    // cin >> tc;
    while (tc--)
    {
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;

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

    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
    for (int i = 0; i <= n; i++)
    {
        dp[i][0] = 1;
    }

    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= m; j++)
        {
            if (j - a[i - 1] >= 0 && dp[i - 1][j - a[i - 1]] == 1)
            {
                dp[i][j] = 1;
            }
            if (j + a[i - 1] <= m && dp[i - 1][j] == 1)
            {
                dp[i][j + a[i - 1]] = 1;
            }
            if (dp[i][j] == 0)
            {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    int ans = INF;

    // for (int i = 0; i <= n; i++)
    // {
    //     for (int j = 0; j <= m; j++)
    //     {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    for (int i = 0; i <= m; i++)
    {
        if (dp[n][i] == 1)
        {
            ans = min(ans, max(m - i, i));
        }
    }
    cout << ans << endl;

    return 0;
}

#include<iostream>
#include<algorithm>
#include<numeric>
#include<queue>
#include<vector>
using namespace std;
const int BUF = 400005;

int nVal;
int val[BUF];

void read() {
    cin >> nVal;
    nVal *= 2;
    for (int i = 0; i < nVal; ++i) {
        cin >> val[i];
    }
}

void work() {
    long long sum = accumulate(val, val + nVal, 0LL);
    priority_queue<int, vector<int>, greater<int> > Q;
    for (int i = 0, L = nVal / 2 - 1, R = nVal / 2; i < nVal; i += 2, --L, ++R) {
        Q.push(val[L]);
        Q.push(val[R]);
        sum -= Q.top();
        Q.pop();
    }

    cout << sum << endl;
}

int main() {
    read();
    work();
    return 0;
}


#include <bits/stdc++.h>

#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;

class SegmentTree
{
private:
	int n;
	vector<ll>a;
	vector<ll>t;
private:
	void build(int i, int l, int r){
		if (l == r){
			t[i] = a[l];
			return;
		}
		int m = (l+r)>>1;
		build(i<<1, l, m);
		build(i<<1|1, m+1, r);
		t[i] = (t[i<<1]^t[i<<1|1]);
	}

	void updatePoint(int i, int l, int r, int pos, int v){
		if (l == r){
			t[i] ^= v;
			return;
		}
		int m = (l+r)>>1;
		if (pos <= m) updatePoint(i<<1, l, m, pos, v);
		else updatePoint(i<<1|1, m+1, r, pos, v);
		t[i] = (t[i<<1]^t[i<<1|1]);
	}

	int XORsum(int i, int l, int r, int pl, int pr){
		if (l >= pl && r <= pr)
			return t[i];
		if (pl > r || pr < l)
			return 0;
		int m = (l+r)>>1;
		return (XORsum(i<<1, l, m, pl, pr)^XORsum(i<<1|1, m+1, r, pl, pr));
	}

public:
	SegmentTree(const vector<ll> &_A){
		a = _A; n = a.size();
		t.assign(n<<2, 0);
		build(1, 0, n-1);
	}

	void PointUpdate(int pos, int val){
		updatePoint(1, 0, n-1, pos-1, val);
	}

	int XORsum(int l, int r){
		return XORsum(1, 0, n-1, l-1, r-1);
	}
};

vector<ll>v;

int main(){
	setIO();
	int n, q;
	cin >> n >> q;
	v.resize(n);
	for (auto &x : v)
		cin >> x;
	SegmentTree St(v);
	for (int i = 0; i < q; i++){
		int t, l, r;
		cin >> t >> l >> r;
		if (t&1) St.PointUpdate(l, r);
		else cout << St.XORsum(l, r) << endl;
	}
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll> ;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inf 1LL<<60;
ll min(ll a,ll b){return a>=b ? b:a;}
ll max(ll a,ll b){return a>=b ? a:b;}

ll dist[1<<18];

typedef struct{
    ll to;
    ll c;
    ll d;
}town;

vector<town> G[1LL<<18];

ll func(ll t,ll d){
    ll rd=sqrt(d);
    ll ret=d/(t+1);
    for (ll i=-10;i<=10;++i){
        if (rd+i-t-1<0) continue;
        ll k=rd-t+i-1+d/(rd+i);
        ret=min(ret,k);
    }
    return ret;
}

void dijkstra(ll st){
    priority_queue<P,vector<P>,greater<>> q;
    dist[st]=0;
    q.push(P(0,st));
    while (!q.empty()){
        ll D=q.top().first;
        ll pos=q.top().second;q.pop();
        if (dist[pos]!=D) continue;
        rep(i,(ll)G[pos].size()){
            ll to=G[pos][i].to;
            ll cost=G[pos][i].c;
            ll di=G[pos][i].d;
            ll ct=func(dist[pos],di);
            if (dist[to]>dist[pos]+ct+cost){
                dist[to]=ct+cost+dist[pos];
                q.push(make_pair(dist[to],to));
            }
        }
    }
}

int main(){
    ll n,m;
    cin >> n >> m;
    rep(i,m){
        ll a,b,c,d;
        cin >> a >> b >> c >>d;
        a--;b--;
        G[a].push_back(town({b,c,d}));
        G[b].push_back(town({a,c,d}));
    }
    rep(i,n+1) dist[i]=1LL<<60;
    dijkstra(0);
    if (dist[n-1]==1LL<<60){
        cout << -1 << endl;
    }
    else cout << dist[n-1] << endl;
}


#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

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

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
  FAST/**/

  ll n;
  cin>>n;

  ll arr[n], arr1[n];
  rep(n)
        cin>>arr[i];
  rep(n)
        cin>>arr1[i];
  ll ans = 0;
  rep(n)
        ans+=(arr[i]*arr1[i]);
  if(ans == 0)
    cout<<"Yes"<<'\n';
  else cout<<"No\n";

  return 0;
}

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

const int N=500010;
char s[N],t[N];
int sta[N],top;
int n;

void fail(){printf("-1\n");exit(0);}

int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	scanf("%s",t+1);
	int las=0;
	for(int i=n;i>=1;i--) if(t[i]=='1') sta[++top]=i;
	long long ans=0;
	for(int i=1;i<=n;i++)
		if(s[i]=='1'){
			if(las) ans+=i-las,las=0;
			else if(top && sta[top]<=i) ans+=i-sta[top],top--;
			else las=i;
		}
	if(las || top) fail();
	printf("%lld\n",ans);
}


//Author: RingweEH
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
#define db double
using namespace std;
const int L=1<<20;
char buf[L],*p1,*p2;
#define getchar() (p1==p2?(p2=buf+fread(p1=buf,1,L,stdin),p1==p2?EOF:*p1++):*p1++)
int read()
{
    int x=0,w=1; char ch=getchar();
    while ( ch>'9' || ch<'0' ) { if ( ch=='-' ) w=-1; ch=getchar(); }
    while ( ch<='9' && ch>='0' ) x=x*10+ch-'0',ch=getchar();
    return x*w;
}

const int N=510;
int n,a[N],c[N][N],d[N][N];

int main()
{
//freopen( "exam.in","r",stdin );

	memset( a,0x7f,sizeof(a) );
	n=read();
	for ( int i=1; i<=n; i++ )
		for ( int j=1; j<=n; j++ )
		{
			c[i][j]=read(); a[i]=min(a[i],c[i][j]);
			d[i][j]=c[i][j]-c[i][1];
		}

	for ( int i=1; i<=n; i++ )
		for ( int j=1; j<=n; j++ )
			if ( d[i][j]^d[1][j] ) { puts("No"); return 0; }
	puts("Yes");
	for ( int i=1; i<=n; i++ ) printf("%d ",a[i] );
	puts("");
	for ( int i=1; i<=n; i++ ) printf("%d ",c[1][i]-a[1] );
	puts("");

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int beamwidth = 300;
const double TL=1.9;
double start;

int n=50;
int sx, sy;
VVI t(n,VI(n));
VVI p(n,VI(n));

struct status{
    int x;
    int y;
    int score;
    int eval;
    VI path;
    VI used;
    bool operator<(const status &another) const {return eval < another.eval;};
};

vector<status> search(const status &base){
    vector<status> res;
    REP(i,4){
        int tox=base.x+dx[i];
        int toy=base.y+dy[i];
        if(tox<0||tox>=n||toy<0||toy>=n)
            continue;
        if(base.used[t[tox][toy]])
            continue;
        int anotp=p[tox][toy];
        REP(j,4){
            int toox=tox+dx[j];
            int tooy=toy+dy[j];
            if(toox<0||toox>=n||tooy<0||tooy>=n)
                continue;
            if(t[tox][toy]==t[toox][tooy]){
                anotp=p[toox][tooy];
                break;
            }
        }
        int newscore=base.score+p[tox][toy]-max(0,anotp-p[tox][toy]);
        int dlx=min(tox,49-tox), dly=min(toy,49-toy);
        int neweval=newscore-(3*(dlx+dly)+min(dlx,dly))*100;
        res.push_back((status){tox,toy,newscore,neweval,base.path,base.used});
        res[res.size()-1].used[t[tox][toy]]=1;
        res[res.size()-1].path.push_back(i);
    }
    return res;
}

int main(){
    start=clock();
    cin >> sx >> sy;
    int maxt=0;
    REP(i,n)REP(j,n){
        cin >> t[i][j];
        maxt=max(maxt,t[i][j]);
    }
    REP(i,n)REP(j,n) cin >> p[i][j];
    priority_queue<status> que, backup;
    VI initused(maxt+1,0); initused[t[sx][sy]]=1;
    que.push({sx,sy,p[sx][sy],0,VI(0),initused});
    int maxscore=0; VI ans;
    int cnt=0;
    while(1){
        priority_queue<status> nxtque;
        VVI mxs(n,VI(n,0));
        while(nxtque.size()<beamwidth){
            if(que.empty())
                break;
            if(que.top().score>maxscore){
                maxscore=que.top().score;
                ans=que.top().path;
            }
            vector<status> res=search(que.top());
            for(auto j:res){
                if(mxs[j.x][j.y]<10){
                    mxs[j.x][j.y]++;
                    nxtque.push(j);
                }
            }
            que.pop();
        }
        if(cnt%10==0&&que.size()>=5){
            REP(j,5){
                vector<status> res=search(que.top());
                for(auto j:res){
                    backup.push(j);
                }
                que.pop();
            }
        }
        que=nxtque;
        double tim=(double)(clock()-start)/CLOCKS_PER_SEC/TL;
        if(tim>=1.0)
            break;
        if(que.empty())
            que=backup;
        cnt++;
    }
    string dir="DRUL";
    for(auto i:ans)
        cout << dir[i];
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int X, Y, Z;
    cin >> X >> Y >> Z;
    if(Z * Y % X == 0) cout << Z * Y / X - 1 << endl;
    else cout << Z * Y / X << endl;
}

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ALL(obj) obj.begin(),obj.end()
#define SORT(obj) sort(obj.begin(),obj.end())
#define pb(obj) push_back(obj)
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
ll const MOD=1e9+7;
const ll INF = 9000000000000000000;
vector<bool> seen;//グラフ用の配列
long long pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % MOD;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}
int kakuketa(int n){
    int ans = 0;
    while(n>0){
        ans += n%10;
        n /= 10;
    }
    return ans;
}
void dfs2(int y,int x,vector<vector<bool>> &flags,Graph &G){//二次元dfs
    if(G[y][x] == 0) return;
    if(flags[y][x] == true) return;
    else{
        flags[y][x] = true;
    }
    dfs2(y+1,x,flags,G);
    dfs2(y+1,x+1,flags,G);
    dfs2(y+1,x-1,flags,G);
    dfs2(y,x+1,flags,G);
    dfs2(y,x-1,flags,G);
    dfs2(y-1,x+1,flags,G);
    dfs2(y-1,x,flags,G);
    dfs2(y-1,x-1,flags,G);
}

int main(){
    int x,y,z;
    cin>>x>>y>>z;
    double a = (double)y*z/x;
  //cout<<a<<endl;
    if(ceil(a) == floor(a)){
        cout<<(int)a-1<<endl;
        return 0;
    }
    else{
        cout<<floor(a)<<endl;
        return 0;
    }
}


#include<bits/stdc++.h>
using namespace std;
int x,y,z;
int b;
int main()
{
	cin>>x>>y>>z;
	if((y/x)*x==y)cout<<y/x*z-1;
	else
	{
		b=y/x*z;
		while(b*x<y*z)b++;
		cout<<b-1;
	}
    return 0;
}

#pragma region my_template
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

#define range(i, l, r) for(int i = (int)(l); i < (int)(r); i++)
#define rrange(i, l, r) for(int i = (int)(r)-1; i >= (int)(l); i--)
#define rep(i, n) range(i, 0, n)
#define rrep(i, n) rrange(i, 0, n)
#define len(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sum(a) accumulate(all(a), 0)
#define uni(a) (a).erase(unique(all(a)), (a).end());
#define append push_back
#define mp make_pair
#define elif else if

constexpr int MOD = 1e9+7;
//constexpr int MOD = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;

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

constexpr int K = 1000;

void solve() {
    rep(i, K) {
        int sy, sx, ty, tx;
        cin >> sy >> sx >> ty >> tx;
        string ans;

        if (sy > ty) {
            rep(_, sy-ty) ans.append('U');
        } else {
            rep(_, ty-sy) ans.append('D');
        }
        if (sx > tx) {
            rep(_, sx-tx) ans.append('L');
        } else {
            rep(_, tx-sx) ans.append('R');
        }

        cout << ans << endl;
        int t; cin >> t;

    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    solve();
    return 0;
}


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

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

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

	int N,M; cin >> N >> M;
	if(N == 1 && M == 0){
		cout << 1 << " " << 2 << endl;
		return 0;
	}
	if(M < 0 || M == N || M == N-1){
		cout << -1 << endl;
		return 0;
	}
	rep(i,N-(M+1)){
		cout << i+1 << " " << i+1 + TEN(8) << endl;
	}
	rep(i,M+1){
		cout << TEN(7) + i*2 << " " << TEN(7) + i*2+1 << endl;
	}
}

#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int64_t> A(N), B(N);
    vector<int> P(N), inv(N);

    for (auto &a : A)
        cin >> a;

    for (auto &b : B)
        cin >> b;

    for (auto &p : P) {
        cin >> p;
        p--;
    }

    for (int i = 0; i < N; i++)
        inv[P[i]] = i;

    for (int i = 0; i < N; i++)
        if (i != P[i] && A[i] <= B[P[i]]) {
            cout << -1 << '\n';
            return 0;
        }

    vector<int> B_order(N);
    iota(B_order.begin(), B_order.end(), 0);
    sort(B_order.begin(), B_order.end(), [&](int x, int y) {
        return B[x] < B[y];
    });

    vector<array<int, 2>> ops;

    for (int b : B_order) {
        while (inv[b] != b) {
            int x = inv[b];
            int i = inv[x];
            ops.push_back({i, x});
            swap(inv[x], inv[b]);
            swap(P[i], P[x]);
        }
    }

    cout << ops.size() << '\n';

    for (auto &op : ops)
        cout << op[0] + 1 << ' ' << op[1] + 1 << '\n';
}


// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using vi = vector<int>;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
LL a[22];

int main(){

    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    rep(i, N) scanf("%lld", &a[i]);

    // 2. 2 の 冪乗 を 保存.
    vi cPow2;
    int count = 0;
    cPow2.pb(1);
    while(count < N){
        // 最大値を2倍.
        int p = 2 * cPow2.back();

        // 保存.
        cPow2.pb(p);

        // インクリメント.
        count++;
    }

    // 3. 区間を生成し, 最小値を探索.
    LL ans = 202020202020202020;
    rep(i, 1 << N){
        // 3-1. 区間を生成.
        int bef = -1, cur;
        vi v;
        rep(j, N){
            // 今回分更新.
            cur = (cPow2[N - 1 - j] & i) ? 1 : 0;

            // 前回と異なる場合は, 区間開始地点と見て保存.
            if(bef != cur) v.pb(j);

            // 前回分更新.
            bef = cur;
        }

        // 3-2. 番兵.
        v.pb(N);

        // 3-3. XOR生成.
        LL cXOR = 0;
        rep(j, v.size() - 1){
            // 区間開始地点, 区間終了地点.
            LL cOR = 0;
            int s = v[j];
            int e = v[j + 1];

            // 区間内の数のビット単位OR を計算.
            repx(k, s, e) cOR |= a[k];

            // 全ての値のビット単位XOR を計算.
            cXOR ^= cOR;
        }

        // 3-4. 最小値更新.
        ans = min(ans, cXOR);
    }

    // 4. 出力.
    printf("%lld\n", ans);
    return 0;

}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={0,1,-1,0,1,1,-1,-1,0};
const ll dx[9]={1,0,0,-1,1,-1,1,-1,0};
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;
}
int main(){
    ll n;cin >> n;
    cout << (1<<n)-1 <<endl;
    repl(bit,1,1<<n){
        rep(cit,1<<n){
            if(__builtin_popcount(bit&cit)%2){
                cout << "A";
            }
            else cout << "B";
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define init(a,i) for(int k=0;k<(i);k++)(a)[k]=0
#define in(a,i) for(int k=0;k<(i);k++)cin>>(a)[k]
#define all(a)  (a).begin(),(a).end()
#define inf 2147483647
#define range(x,a,b) (a)<=x&&x<=(b)
#define mod 323
int top(int *unionfind,int a){
	int c=unionfind[a];
	if(c==a)return a;
	unionfind[a]=top(unionfind,c);
	return unionfind[a];
}

int bind(int *unionfind,int a,int b){
	int c=unionfind[a];
	if(c==a){
		unionfind[a]=b;
		return b;
	}
	unionfind[a]=bind(unionfind,unionfind[a],b);
	return unionfind[a];
}

int add(int *unionfind,int a,int number,ll *num){
	int c=unionfind[a];
	if(c==a){
		num[a]+=number;
		return a;
	}
	unionfind[a]=add(unionfind,unionfind[a],number,num);
	return unionfind[a];
}

int main(){
	int n,m;
	cin>>n>>m;
	int a[n],b[n];
	in(a,n);in(b,n);
	int ab[n];
	rep(i,n)ab[i]=a[i]-b[i];
	if(m==0){
		int flag=1;
		rep(i,n){
			if(ab[i]!=0)flag=0;
		}
		if(flag==1) cout<<"Yes";
		else cout<<"No";
		return 0;
	}
	int c[m],d[m],tmp;
	rep(i,m){
		cin>>tmp;
		c[i]=tmp-1;
		cin>>tmp;
		d[i]=tmp-1;
	}
	int unionfind[n];
	rep(i,n)unionfind[i]=i;
	rep(i,m) bind(unionfind,c[i],top(unionfind,d[i]));
	ll num[n];
	rep(i,n)num[i]=0;
	rep(i,n){
		add(unionfind,i,ab[i],num);
	}
	int flag=1;
	rep(i,n)if(num[i]!=0)flag=0;
	if(flag==1) cout<<"Yes";
	else cout<<"No";
	return 0;
}

/*  union_find_tree_size.cpp
    素集合系を union-find tree で管理するライブラリ
    併合時の工夫：union by size

    verified: AtCoder ABC157 D - Friend Suggestions
        https://atcoder.jp/contests/abc157/tasks/abc157_d
*/

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

/* UnionFind：素集合系管理の構造体(union by size)
    isSame(x, y): x と y が同じ集合にいるか。 計算量はならし O(α(n))
    unite(x, y): x と y を同じ集合にする。計算量はならし O(α(n))
    treeSize(x): x を含む集合の要素数。
*/
struct UnionFind {
    vector<int> size, parents;
    UnionFind() {}
    UnionFind(int n) {  // make n trees.
        size.resize(n, 0);
        parents.resize(n, 0);
        for (int i = 0; i < n; i++) {
            makeTree(i);
        }
    }
    void makeTree(int x) {
        parents[x] = x;  // the parent of x is x
        size[x] = 1;
    }
    bool isSame(int x, int y) { return findRoot(x) == findRoot(y); }
    bool unite(int x, int y) {
        x = findRoot(x);
        y = findRoot(y);
        if (x == y) return false;
        if (size[x] > size[y]) {
            parents[y] = x;
            size[x] += size[y];
        } else {
            parents[x] = y;
            size[y] += size[x];
        }
        return true;
    }
    int findRoot(int x) {
        if (x != parents[x]) {
            parents[x] = findRoot(parents[x]);
        }
        return parents[x];
    }
    int treeSize(int x) { return size[findRoot(x)]; }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);  // Union-Find Tree で考える

    vector<long long> a(N), b(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> b[i];
    }

    for (int i = 0; i < M; i++) {
        int c, d;
        cin >> c >> d;
        c--, d--;
        uf.unite(c, d);
    }

    map<int, long long> m;
    for (int i = 0; i < N; i++) {
        m[uf.findRoot(i)] += (a[i] - b[i]);
    }

    for (auto p : m) {
        if (p.second != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}


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

int main() {

	ll a,b,c;
	cin >> a>> b >> c;
	if (a*a + b*b < c*c)cout << "Yes";
	else cout << "No";

}

//https://atcoder.jp/contests/abc190/tasks/abc190_b
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;

int main ()
{
    ios_base::sync_with_stdio (0); cin.tie (0); cout.tie (0);
    int n, s, d;
    cin >> n >> s >> d;
    int chk = 0;
    while (n--)
    {
        int x, y;
        cin >> x >> y;
        if (x < s && y > d) chk = 1;
    }
    cout << (chk ? "Yes" : "No");
}


#include <bits/stdc++.h>

using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

class rep {
    struct Iter {
        usize itr;
        constexpr Iter(const usize pos) noexcept: itr(pos) { }
        constexpr void operator ++ () noexcept { ++itr; }
        constexpr bool operator != (const Iter& other) const noexcept { return itr != other.itr; }
        constexpr usize operator * () const noexcept { return itr; }
    };
    const Iter first, last;
public:
    explicit constexpr rep(const usize first, const usize last) noexcept: first(first), last(std::max(first, last)) { }
    constexpr Iter begin() const noexcept { return first; }
    constexpr Iter end() const noexcept { return last; }
};

template <class T>
using Vec = std::vector<T>;

using Point = std::complex<double>;
constexpr double PI = std::acos(-1.0);

void D_main() {
    usize N;
    std::cin >> N;
    Point p, q;
    double px, py, qx, qy;
    std::cin >> px >> py >> qx >> qy;
    p.real(px);
    p.imag(py);
    q.real(qx);
    q.imag(qy);
    const auto c = (p + q) / 2.0;
    const auto v = (p - c) * std::polar(1.0, 2.0 * PI / N);
    const auto ans = c + v;
    std::cout << ans.real() << ' ' << ans.imag() << '\n';
    return;
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(10);
    D_main();
    return 0;
}

#include <iostream>
using namespace std;

const int N = 35;

int prims[N], idx;
bool st[N];

int main() {

	for (int i = 2; i <= 30; i ++) {
		if (!st[i]) prims[idx ++] = i;
		for (int j = 0; prims[j] <= 30 / i; j ++) {
			st[prims[j] * i] = true;
			if (i % prims[j] == 0) break;
		}
	}
	// for (int i = 0; i < idx; i ++) cout << prims[i] << ' ';
	// cout << endl;
	// cout << idx << endl;
	long long t = 1;
	for (int i = 0; i < idx; i ++) t *= prims[i];
	t *= 8;
	t *= 9;
	t *= 5;
	cout << t + 1;
	return 0;

}


#include <bits/stdc++.h>
#include <math.h>
#define REP(i,a,b) for (int i=a; i<b; i++)
#define ALL(v) (v).begin(), (v).end()
#define FORE(i,a) for(auto &i:a)
using namespace std;
typedef long long ll;
const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (a>b) { a=b; return 1; } return 0; }
//#pragma GCC optimize ("-O3")
void _main(); int main() {cin.tie(0); ios::sync_with_stdio(false); _main(); }

int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

void _main() {
  ll N;
  cin >> N;

  ll extra;
  ll ans = 0;
  ll base = 1;
  ll ct = 0;
  while (N >= base*1000) {
    ans += (base*1000 - base)*ct;
    ct++;
    base *= 1000;
  }

  extra = N-base+1;
  ans += extra*ct;

  cout << ans << endl;
}

// Problem: B - Palindrome with leading zeros
// Contest: AtCoder - AtCoder Beginner Contest 198
// URL: https://atcoder.jp/contests/abc198/tasks/abc198_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define it insert
#define pob pop_back
#define pub push_back
#define emb emplace_back
#define all(v) (v).begin(), (v).end()
#define mkp(a, b) make_pair(a, b)
using LL = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
const double EPS = 1e-6;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 7;

int main() {
    int x;
    cin >> x;
    int t = x;
    int ans = 0;
    while (t) {
        ans = ans * 10 + t % 10;
        t /= 10;
    }
    while (x && x % 10 == 0) x /= 10;
    if (x == ans)
        cout << "Yes";
    else
        cout << "No";

    return 0;
}


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

#define M_PI	3.14159265358979323846

typedef pair<int, int> P;

int main(){
    string s[3];
    int num = 0;
    vector<int> kaisu(26, 0);
    vector<int> jun(26, 0);

    REP(i, 3) {
        cin >> s[i];
        REP(j, s[i].size()) kaisu[s[i][j] - 'a']++;
    }

    REP(i, kaisu.size()) {
        if(0 < kaisu[i]) {
            jun[i] = num;
            num++;
        }
        if(num > 10) {
            cout << "UNSOLVABLE" << endl;
            return 0;
        }
    }

    vector<int> v(10);
    REP(i, v.size()) v[i] = i;

    do{
        bool b = false;
        vector<string> ss(3);
        REP(i, ss.size()) ss[i] = s[i];
        REP(i, 3) {
            REP(j, s[i].size()) {
                int n = v[jun[s[i][j] - 'a']];
                ss[i][j] = '0' + n;
            }

            if(ss[i][0] == '0') b = true;
        }
        if(b) continue;

        vector<ll> ans(3);
        REP(i, ans.size()) ans[i] = stol(ss[i]);

        if(ans[0] + ans[1] == ans[2]) {
            cout << ans[0] << endl;
            cout << ans[1] << endl;
            cout << ans[2] << endl;
            return 0;
        }
    } while(next_permutation(v.begin(), v.end()));

    cout << "UNSOLVABLE" << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fcout cout << fixed << setprecision(18)

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

  ll N; cin >> N;
  double M; cin >> M;
  ll K; cin >> K;

  vector<ll> A(N + 10, 0);
  for (ll i = 0; i < K; i++) {
    ll X; cin >> X;
    A[X] = 1;
  }

  ll check = 0;
  for (ll i = 0; i < N + 1; i++) {
    if (A[i] == 1) check++;
    else check = 0;
    if (check >= M) {
      cout << -1 << '\n';
      return 0;
    }
  }

  double l = 0, r = 1e12;
  while (l + 0.00001 < r) {
    double m = (l + r) / 2.0;
    vector<double> E(N + M + 10, 0);

    double sum = 0;
    for (ll i = N - 1; i >= 0; i--) {
      sum += (E[i + 1] - E[i + M + 1]);
      if (A[i] == 1) {
        E[i] = m;
      } else {
        E[i] = 1.0 + sum / M;
      }
    }
    if (E[0] > m) {
      l = m;
    } else {
      r = m;
    }
  }

  fcout << l << '\n';
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
struct vals{
    double val1;
    double val2;
    vals():val1(0.f),val2(0.f){};
    vals  operator +(const vals & b){
        vals tmp;
        tmp.val1 = b.val1 + val1;
        tmp.val2 = b.val2 + val2;
        return tmp;
    }
    vals  operator -(const vals & b){
        vals tmp;
        tmp.val1 = val1 - b.val1;
        tmp.val2 = val2 - b.val2;
        return tmp;
    }
    void  operator =(const vals & b){
        this -> val1 = b.val1;
        this -> val2 = b.val2;
    }
};
int main(){

    cout << setprecision(15);
    cout << fixed;
    int n,m,k;
    cin >> n >> m >> k;
    set<int>badpos;
    for(int i = 0; i < k; ++i){
        int tmp;
        cin >> tmp;
        badpos.insert(tmp);
    }
    vector<vals>dp(n+m+1);
    vals orig;
    for(int i = n; i >= 0; --i){
        if(badpos.count(i)){
            dp[i].val2 = 1;
        } else {
            dp[i] = orig;
            dp[i].val1 /= double(m);
            dp[i].val2 /= double(m);
            if(i != n)dp[i].val1 += 1.f;
        }
        orig = orig - dp[i + m];
        orig = orig + dp[i];
        //cerr << dp[i].val1 << " , "<< dp[i].val2 << " is the expected number of moves \n";
    }
    long double den = 1.0 - dp[0].val2;
    if(fabs(den) < 1e-9){
        cout <<"-1\n";
    } else {
        cout << dp[0].val1/den << "\n";
    }
    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define pf push_front

using namespace std;
typedef long long int lli;
lli n,k,m,t,a,b,l,r,h,u,x,y,temp1,temp2,temp,q,d,mod=1e9+7,w,p,c,z;

lli gcd(lli a,lli b)
{
	if(b == 0)return a;

	return gcd(b, a%b);
}

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

    cin>>n;

    vector<lli>v(n+2);
    lli mn = 1e9+7;

    for(int i=0;i<n;i++)
	{
		cin>>v[i];
		mn = min(mn,v[i]);
	}

    unordered_map<lli,lli>mp;

    for(auto x:v)
    {
    	lli sq = sqrt(x);

    	for(int i=1;i<=sq;i++)
    	{
    		if( x%i == 0 )
    		{
    			if(mp.find(i) == mp.end())
    			{
    				mp[i] = x;
    			}
    			else
    			{
    				mp[i] = gcd(mp[i], x);
				}

				if(mp.find(x/i) == mp.end())
    			{
    				mp[x/i] = x;
    			}
    			else
    			{
    				mp[x/i] = gcd(mp[x/i], x);
				}
    		}
    	}
    }

    lli ans = 0;

    for(auto x:mp)
    {
    	if(x.first 	<= mn)
    	{
    		if(x.second == x.first) ans++;
    	}
    }

    cout<<ans<<endl;
}

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

const int M = 1e5;
int main()
{
    int n;
    cin >> n;
    vector<int> t(n);
    rep(i, n) cin >> t[i];
    int sum = 0;
    rep(i, n) sum += t[i];

    vector<vector<int>> dp(n+5, vector<int>(2*M,-1));

    dp[0][0] = 1;
    rep(i, n)
    {
        rep(j, M + 2)
        {
            dp[i + 1][j] = max(dp[i][j],dp[i+1][j]);
            dp[i + 1][j + t[i]] = max(dp[i][j], dp[i + 1][j+t[i]]);
        }
    }
    int ans = M;
    rep(i, M)
    {
        if (dp[n][i] == 1)
        {
            int a = i;
            int b = sum - i;
            ans = min(ans, max(a, b));
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
  int n, s, d;
  cin >> n >> s >> d;
  string ans = "No";
  for(int i = 0; i < n; i++){
    int x, y;
    cin >> x >> y;
    if(x < s && y > d){
      ans = "Yes";
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
//kaizen_philosopher
//Al Waris
/*-----------------------------------------------------------------------*/
#define fastio ios::sync_with_stdio(false);cin.tie(0);
#define ll long long int
//loops
#define lp0(i,a) for(i=0;i<a;i++)
#define lp1(i,a) for(i=1;i<=a;i++)
//file input output(T.N.T.I)
#define f_input freopen("input.txt","r",stdin)
#define f_output freopen("output.txt","w",stdout)
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vc vector<char>
#define si stack<int>
#define qi queue<int>
#define sq(a) ((a)*(a))
#define sf scanf
#define pf printf
#define endl "\n"
const double pi=acos(-1);
/*---------------------------------------------------------------------*/

void solve(){
    ll a,x,y,i,j;
    cin>>a>>x>>y;
    ll ar[a][2];
    lp0(i,a){
        cin>>ar[i][0];
        cin>>ar[i][1];
    }

    bool flag=false;

    lp0(j,a){
        if(ar[j][0]<x && ar[j][1]>y) flag=true;
    }
    if(flag==true)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}

int main(){
    fastio
    int t=1;

    while(t--)solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

main() {
    int N; scanf("%d", &N);
    int A[N + 5], B[N + 5];
    for (int k = 0; k < 2; k++) {
        for (int i = 0; i < N; i++) {
            if (k == 1) scanf("%d", &B[i]);
            else scanf("%d", &A[i]);
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) ans += A[i] * B[i];

    if (ans == 0) printf("Yes");
    else printf("No");
}

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <iostream>
#include <stdio.h>
#include <time.h>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)

#define MOD 1000000007

ll d[100100];

int main(){
  clr(d,0);
  ll n;
  cin>>n;
  vector<ll> v;
  ll sum = 0;
  rep(i,0,n){
    ll a;
    cin>>a;
    v.pb(a);
  }
  sort(all(v));
  rep(i,0,v.sz){
    d[i] += v[i];
    d[i+1] += d[i];
  }
  double mn = 1000000000000000000.;
  rep(i,0,v.sz){
    double e = 1.*v[i]/2+(1.*d[n]-1.*d[i]-1.*v[i]*(n-1-i))/n;
    mn = min(mn,e);
  }
  printf("%20.20f\n", mn);
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <bitset>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define ll long long
#define MOD 1000000007
#define rep(i, n) for( ll int i = 0; i < (n); i++ )

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

    vector<ll int> a(n);
    rep(i, n) cin >> a.at(i);

    map<ll int, ll int> mp;
    rep(i, n){
        if( mp.count( a.at(i) ) ){
            mp[ a.at(i) ] += 1;
        }
        else{
            mp[ a.at(i) ] = 1;
        }
    }

    ll int ans = n * (n-1) / 2;
    for( auto k : mp ){
        if( k.second >= 2 ){
            ans -= k.second * (k.second-1) / 2;
        }
    }
    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define each(e, v) for(auto &e: v)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct io_setup{
    io_setup(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

template<int mod>
struct Mod_Int{
    int x;

    Mod_Int() : x(0) {}

    Mod_Int(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    Mod_Int &operator += (const Mod_Int &p){
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }

    Mod_Int &operator -= (const Mod_Int &p){
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    Mod_Int &operator *= (const Mod_Int &p){
        x = (int) (1LL * x * p.x % mod);
        return *this;
    }

    Mod_Int &operator /= (const Mod_Int &p){
        *this *= p.inverse();
        return *this;
    }

    Mod_Int &operator ++ () {return *this += Mod_Int(1);}

    Mod_Int operator ++ (int){
        Mod_Int tmp = *this;
        ++*this;
        return tmp;
    }

    Mod_Int &operator -- () {return *this -= Mod_Int(1);}

    Mod_Int operator -- (int){
        Mod_Int tmp = *this;
        --*this;
        return tmp;
    }

    Mod_Int operator - () const {return Mod_Int(-x);}

    Mod_Int operator + (const Mod_Int &p) const {return Mod_Int(*this) += p;}

    Mod_Int operator - (const Mod_Int &p) const {return Mod_Int(*this) -= p;}

    Mod_Int operator * (const Mod_Int &p) const {return Mod_Int(*this) *= p;}

    Mod_Int operator / (const Mod_Int &p) const {return Mod_Int(*this) /= p;}

    bool operator == (const Mod_Int &p) const {return x == p.x;}

    bool operator != (const Mod_Int &p) const {return x != p.x;}

    Mod_Int inverse() const{
        assert(*this != Mod_Int(0));
        return pow(mod-2);
    }

    Mod_Int pow(long long k) const{
        Mod_Int now = *this, ret = 1;
        for(; k > 0; k >>= 1, now *= now){
            if(k&1) ret *= now;
        }
        return ret;
    }

    friend ostream &operator << (ostream &os, const Mod_Int &p){
        return os << p.x;
    }

    friend istream &operator >> (istream &is, Mod_Int &p){
        long long a;
        is >> a;
        p = Mod_Int<mod>(a);
        return is;
    }
};

using mint = Mod_Int<MOD>;

int main(){
    int N, P; cin >> N >> P;

    mint ans = P-1;
    ans *= mint(P-2).pow(N-1);

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


#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll =long long;
using vi = vector<ll>;
using vc = vector<char>;
using vs = vector<string>;
using P = pair<ll , ll>;
using vp = vector<P>;
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define rep2(i, s, n) for (int i = (s); i < n; i++)
#define sort(A) sort(A.begin(),A.end());
#define reverse(A) reverse(A.begin(),A.end());
#define vecint2(A, n, m) vector<vector<long long int>> A(n, vector<long long int>(m));
#define vecchar2(A, n, m) vector<vector<char>> A(n, vector<char>(m));
#define k(s) cout << fixed << setprecision(s);
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
const long double pi=3.14159265358979323846;

int main() {
  int N;
  cin>>N;
  vi X(N),Y(N);
  rep(i,N) cin>>X[i]>>Y[i];
  int M;
  cin>>M;
  vi sita(M+1);
  vi xc(M+1),xd(M+1);
  vi yc(M+1),yd(M+1);
  vi seijou(M+1,0);
  seijou[0]=1;
  rep(i,M){
    int t;
    cin>>t;
    if(t==1){
      xd[i+1]=yd[i];
      yd[i+1]=-xd[i];
      if(seijou[i]==1){
        seijou[i+1]=0;
        xc[i+1]=xc[i]+1;
        yc[i+1]=yc[i];
      }else if(seijou[i]==0){
        seijou[i+1]=1;
        xc[i+1]=xc[i];
        yc[i+1]=yc[i]+1;
      }
    }else if(t==2){
      sita[i+1]=sita[i]+1;
      xc[i+1]=xc[i];
      xd[i+1]=-yd[i];
      yc[i+1]=yc[i];
      yd[i+1]=xd[i];
      if(seijou[i]==1){
        seijou[i+1]=0;
        xc[i+1]=xc[i];
        yc[i+1]=yc[i]+1;
      }else if(seijou[i]==0){
        seijou[i+1]=1;
        xc[i+1]=xc[i]+1;
        yc[i+1]=yc[i];
      }
    }else if(t==3){
      ll p;
      cin>>p;
      if(seijou[i]==1){
        xc[i+1]=xc[i]+1;
        yc[i+1]=yc[i];
      }else{
        xc[i+1]=xc[i];
        yc[i+1]=yc[i]+1;
      }
      xd[i+1]=2*p-xd[i];
      yd[i+1]=yd[i];
      seijou[i+1]=seijou[i];
    }else{
      ll p;
      cin>>p;
      xd[i+1]=xd[i];
      if(seijou[i]==1){
        yc[i+1]=yc[i]+1;
        xc[i+1]=xc[i];
      }else{
        xc[i+1]=xc[i]+1;
        yc[i+1]=yc[i];
      }
      yd[i+1]=2*p-yd[i];
      seijou[i+1]=seijou[i];
    }
  }
  int Q;
  cin>>Q;
  rep(i,Q){
    int A,B;
    cin>>A>>B;
    ll tx=X[B-1],ty=Y[B-1];
    ll atx,aty;
    if(seijou[A]==1){
      if(xc[A]%2==0) atx=xd[A]+tx;
      else atx=xd[A]-tx;
      if(yc[A]%2==0) aty=yd[A]+ty;
      else aty=yd[A]-ty;
    }else{
      if(yc[A]%2==0) atx=xd[A]+ty;
      else atx=xd[A]-ty;
      if(xc[A]%2==0) aty=yd[A]+tx;
      else aty=yd[A]-tx;

    }
    cout<<atx<<" "<<aty<<endl;
  }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
template <typename T>
inline void read(T &x)
{
    T data = 0, f = 1;
    char ch = getchar();
    while (!isdigit(ch))
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        data = (data << 3) + (data << 1) + ch - '0';
        ch = getchar();
    }
    x = f * data;
}
template <typename T, typename... Args>
inline void read(T &t, Args &...args)
{
    read(t);
    read(args...);
}
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int maxn = 2e5 + 9;
const ll mod = 998244353;
struct point
{
    ll x, y;
    point() {}
    point(int a, int b) : x(a), y(b) {}
};
point p[maxn];
ll mat[maxn][4][4];

signed main()
{
    int n, m, q;
    read(n);
    for (int i = 1; i <= n; ++i)
        read(p[i].x, p[i].y);
    read(m);
    mat[0][1][1] = mat[0][2][2] = mat[0][3][3] = 1;
    for (int i = 1, op, d; i <= m; ++i)
    {
        read(op);
        if (op <= 2)
        {
            if (op == 1)
            {
                for (int j = 1; j <= 3; ++j)
                {
                    mat[i][1][j] = mat[i - 1][2][j];
                    mat[i][2][j] = -mat[i - 1][1][j];
                    mat[i][3][j] = mat[i - 1][3][j];
                }
            }
            else
            {
                for (int j = 1; j <= 3; ++j)
                {
                    mat[i][1][j] = -mat[i - 1][2][j];
                    mat[i][2][j] = mat[i - 1][1][j];
                    mat[i][3][j] = mat[i - 1][3][j];
                }
            }
        }
        else
        {
            read(d);
            if (op == 3)
            {
                for (int j = 1; j <= 3; ++j)
                {
                    mat[i][1][j] = -mat[i - 1][1][j] + 2LL * d * mat[i - 1][3][j];
                    mat[i][2][j] = mat[i - 1][2][j];
                    mat[i][3][j] = mat[i - 1][3][j];
                }
            }
            else
            {
                for (int j = 1; j <= 3; ++j)
                {
                    mat[i][2][j] = -mat[i - 1][2][j] + 2LL * d * mat[i - 1][3][j];
                    mat[i][1][j] = mat[i - 1][1][j];
                    mat[i][3][j] = mat[i - 1][3][j];
                }
            }
        }
    }
    read(q);
    while (q--)
    {
        int a, b;
        read(a, b);
        ll x = p[b].x * mat[a][1][1] + p[b].y * mat[a][1][2] + mat[a][1][3];
        ll y = p[b].x * mat[a][2][1] + p[b].y * mat[a][2][2] + mat[a][2][3];
        printf("%lld %lld\n", x, y);
    }
    return 0;
}


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

template <class T>
using idx_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define ull unsigned long long
#define arr array
#define vt vector
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define all(v) (v).begin(), (v).end()
#define pi acosl(-1)

//ofstream out("debug.txt");

const int MxN = 1e5, md = 1e9 + 7;

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

	bool sat = 0;
	int n;
	cin >> n;
	set<string> s;
	string t, r;
	for (int i = 0; i < n; ++i)
	{
		cin >> t;
		if (t[0] == '!')
		{
			if (s.count(t.substr(1)))
			{
				sat = 1;
				r = t.substr(1);
			}
		}
		else
		{
			if (s.count('!'+t))
			{
				sat = 1;
				r = t;
			}
		}
		s.insert(t);
	}
	if (sat)
		cout << r << '\n';
	else
		cout << "satisfiable\n";
}


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

#define pb push_back

#define int ll
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;

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

template<typename T, typename U>
ostream& operator<<(ostream& o, const map<T,U>& m) {
  o << "{";
  for (const pair<T,U>& p : m)
    o << p.first << ": " << p.second << ",";
  return o << "}";
}

template<typename T>
ostream& operator<<(ostream& o, const set<T>& s) {
  o << "{";
  for (const T& e : s)
    o << s << ",";
  return o << "}";
}

template<typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (const T& x : v)
    o << x << ",";
  return o << "]";
}

template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T>>& v) {
  o << "[";
  for (const vector<T>& x : v)
    o << x << ",\n";
  return o << "]";
}

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

    int n;
    string s;
    cin >> n >> s;

    if (s[0] != s[n-1]) {
        cout << "1\n";
        return 0;
    }
    for (int i=1; i<n-2; ++i) {
        if (s[0] != s[i] && s[i+1] != s[n-1]) {
            cout << "2\n";
            return 0;
        }
    }
    cout << "-1\n";
}

// chrono::system_clock::now().time_since_epoch().count()
#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

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

const int MAXN = (int)1e5 + 5;
const int INF = (int)1e9;

int dp[MAXN], mem[26];
int n;
string s;

void solve() {
    cin >> n;
    cin >> s;
    s = '#' + s;
    fill(dp, dp + n + 1, INF);
    fill(mem, mem + 26, INF);
    dp[0] = 0;
    mem[s[1] - 'a'] = 0;

    rep (i, 1, n + 1) {
        rep (j, 0, 26) {
            if (s[i] != j + 'a') {
                dp[i] = min(dp[i], mem[j] + 1);
            }
        }

        if (i < n) {
            mem[s[i + 1] - 'a'] = min(mem[s[i + 1] - 'a'], dp[i]);
        }
    }

    if (dp[n] == INF) {
        dp[n] = -1;
    }

    cout << dp[n] << '\n';
}

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

    int tt = 1;

    for (int i = 1; i <= tt; ++i) {
        solve();
    }

    return 0;
}


    /*

      (                                 _
       )                               /=>
      (  +____________________/\/\___ / /|
       .''._____________'._____      / /|/\
      : () :              :\ ----\|    \ )
       '..'______________.'0|----|      \
                        0_0/____/        \
                            |----    /----\
                           || -\\ --|      \
                           ||   || ||\      \
                            \\____// '|      \
    Bang! Bang!                     .'/       |
                                   .:/        |
                                   :/_________|

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     BALJOT SINGH
     EVERYONE HAS THEIR OWN TIME
     DEBUG->COMMENT FAST
    ~~~~~~~~~~~~~~~~~~~~~~
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #define fi first
    #define se second
    #define loop(i,a,b)               for(int i = a; i<=b ; i++)
    #define rep(i,a,b)              for(int i = a; i>=b ; i--)
    #define pb push_back
    #define mp make_pair
    #define setbits(x)      __builtin_popcountll(x)
    #define zerobits(x)      __builtin_ctzll(x)
    #define FAST ios_base :: sync_with_stdio (false); cin.tie (NULL) ;cout.tie(NULL);
    using namespace std;
    using namespace __gnu_pbds;
    using ll =long long ;

    template<class T> using pbds =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

    const ll M = 1e9 + 7;
    const ll iM = 1e5 + 5;
    const ll inf = 2e18;

    //modular arithmetic worst part-----------------------------------
    ll mod(ll x){  return (x%M+M)%M;}
    ll mod_min(ll a, ll b){ ll ans= (mod(a)-mod(b)); if(ans<0) ans=mod(ans+M); return ans;}
    ll mod_mul(ll a,ll b){  return mod(mod(a)*mod(b));}
    ll mod_add(ll a,ll b){ return mod(mod(a)+mod(b));}
    ll power(ll x,ll y)  {  ll res = 1;if (x == 0) return 0;while (y > 0){if (y & 1) res=mod_mul(res,x); y = y>>1; x=mod_mul(x,x);} return res;}
    ll gcd_extend(ll a, ll b, ll& x, ll& y) {if (b == 0) {x = 1;y = 0;return a;}ll x1, y1;ll d = gcd_extend(b, a % b, x1, y1);x = y1;y = x1 - y1 * (a / b);return d;}
    ll modinverse(ll value) {ll x, y;ll res=gcd_extend(value,M,x,y);if(res!=1)return -1;return mod(x);}
    //----------------------------------------------------------------------------------------------------------------------------------

    int main()
    {
        FAST;

        ll n;
        cin>>n;
        if(n<=7)
        {
            cout<<"-1";
            return 0;
        }

       for(ll i=1;i<log(inf)/log(5);i++)
        for(ll j=1;j<log(inf)/log(3);j++)
            if(((ll)powl(5,i)+(ll) powl(3,j))==n)
       {
           cout<<j<<" "<<i;
           return 0;
       }

        cout<<"-1";

    }

//
//  main.cpp
//  atcoder
//
//  Created by 荣恒嬉 on 2020/10/24.
//

#include <bits/stdc++.h>
#define ll unsigned long long
using namespace std;
int main() {
	ll a;
	cin>>a;
	ll x=1,y=1;
	for(int i=1;i<38;i++){
		x*=3;
		ll y=1;
		for(int j=1;j<28;j++){
			y*=5;
			if(x+y==a)
			{
				cout<<i<<" "<<j;
				return 0;
			}
		}
	}
	cout<<-1;
	return 0;
}


 #include<bits/stdc++.h>
#define ar long long int
using namespace std;

int main() {
  ar n;
  cin>>n;
  ar a[n];

  for(ar i=0; i<n; i++){
    cin>>a[i];
  }
  ar sum = 0;

  for(ar i=0; i<n; i++){
    if(a[i] <= 10){
      continue;
    } else {
      sum = sum + (a[i] - 10);
    }
  }

  cout<<sum<<endl;

  return 0;
}

#include <bits/stdc++.h>
#define gc() getchar()
using namespace std;
typedef long long ll;

template <typename T> void rd(T &x){
	ll f=1;x=0;char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	x*=f;
}

int main(){
	int n,a,ans=0;
	rd(n);
	for(;n;--n)rd(a),ans+=max(0,a-10);
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  for(int i=1;i<=N;i++)
    cout<<(i*2%N==0? N:i*2%N)<<" "<<((i*2+1)%N==0? N:(i*2+1)%N)<<endl;
}

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>

#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

using namespace std;

void IO(){
    #ifndef ONLINE_JUDGE
        freopen("test.txt","r",stdin);
    #endif
}

const int N = 1e6 + 7, K = 26, M = 5e3 + 5, mod = 1e9 + 7, dx[] = {0,1,-1,0}, MOD = 998244353,
                                                           dy[] = {1,0,0,-1};

int tc = 1, n, m, a[M][M], b[N], ans, k, cnt[N], grid[M][M], L[N], R[N], pre[N];

char s[N];

void test_case(){
    scanf("%d", &n);
    for(int i = 1 ; i <= n ; i++){
        bool ok = true;
        int j = i;
        while(j){
            ok &= (j % 10) != 7;
            j /= 10;
        }
        j = i;
        while(j){
            ok &= (j % 8) != 7;
            j /= 8;
        }
        ans += ok;
    }
    printf("%d\n", ans);
}

int main(){
    //IO();
    //scanf("%d", &tc);
    while(tc--){
        test_case();
    }
}


#include <bits/stdc++.h>

const long long INF = 1ll << 61;

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;

  vector<vector<pair<int, int>>> edges(26);

  for (int e = 0; e < M; e++) {
    int A, B;
    char C;
    cin >> A >> B >> C;

    edges[C - 'a'].push_back({--A, --B});
  }

  vector<vector<int>> graph(N * N);

  auto index = [&](int u, int v) {
    return min(u, v) * N + max(u, v);
  };

  for (int ch = 0; ch < 26; ch++) {
    for (auto [u, v] : edges[ch]) {
      for (auto [w, x] : edges[ch]) {
        graph[index(u, w)].push_back(index(v, x));
        graph[index(u, x)].push_back(index(v, w));
        graph[index(v, w)].push_back(index(u, x));
        graph[index(v, x)].push_back(index(u, w));
      }
    }
  }

  priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;

  vector<long long> dist(N * N, INF);

  pq.push({0ll, index(0, N - 1)});
  dist[index(0, N - 1)] = 0;

  while (!pq.empty()) {
    auto [cost, node] = pq.top();
    pq.pop();

    if (dist[node] < cost) continue;

    for (int next : graph[node]) {
      if (dist[next] <= cost + 1) continue;

      dist[next] = cost + 1;
      pq.push({dist[next], next});
    }
  }

  long long ans = INF;

  for (int i = 0; i < N; i++) {
    ans = min(dist[index(i, i)] * 2, ans);
  }

  for (int ch = 0; ch < 26; ch++) {
    for (auto [u, v] : edges[ch]) {
      ans = min(dist[index(u, v)] * 2 + 1, ans);
    }
  }

  cout << (ans < INF ? ans : -1) << endl;

  return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)
#define popcount __builtin_popcount

const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

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

struct dijkstra {

  ll N;
  struct edge { ll to, d; };
  vector<vector<edge>> adj;
  vector<ll> minlen;

  dijkstra(ll n) { N = n; adj.resize(N); minlen.assign(N,LLINF); }
  ll operator[](const ll &x) const { return minlen[x]; }

  void add_edge(ll from, ll to, ll d){
    adj[from].push_back({to,d});
  }
  vector<ll> calc(ll n=0) {
    auto c = [](const p_ll &x, const p_ll &y){return x.second>y.second;};
    priority_queue<p_ll, vector<p_ll>, decltype(c)> q(c);
    minlen[n] = 0; q.push(make_pair(n,0));
    while(q.size()) {
      p_ll now = q.top(); q.pop();
      ll np = now.first, nd = now.second;
      if (nd>minlen[np]) continue;
      for (auto x: adj[np]) {
        if (minlen[x.to]<=minlen[np]+x.d) continue;
        q.push(make_pair(x.to, minlen[np]+x.d));
        minlen[x.to] = minlen[np]+x.d;
      }
    }
    return minlen;
  }

};

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

ll R, C;
ll gid(ll i, ll j, bool ura) { return i*C + j + ura*(R*C); }

int main() {
  cin >> R >> C;
  ll A[R][C-1]; rep(i,R) rep(j,C-1) cin >> A[i][j];
  ll B[R-1][C]; rep(i,R-1) rep(j,C) cin >> B[i][j];

  dijkstra ds(R*C*2);
  rep(i,R) rep(j,C-1) {
    ds.add_edge(gid(i,j,false), gid(i,j+1,false), A[i][j]);
    ds.add_edge(gid(i,j+1,false), gid(i,j,false), A[i][j]);
  }
  rep(i,R-1) rep(j,C) {
    ds.add_edge(gid(i,j,false), gid(i+1,j,false), B[i][j]);
    ds.add_edge(gid(i+1,j,true), gid(i,j,true), 1);
  }
  rep(i,R) rep(j,C) {
    ds.add_edge(gid(i,j,false), gid(i,j,true), 1);
    ds.add_edge(gid(i,j,true), gid(i,j,false), 0);
  }

  vector<ll> d = ds.calc();
  ll result = ds[gid(R-1,C-1,false)];
  cout << result << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const long nPrime = 998244353;
int main() {
    long n,m;
    cin >> n >> m;
    vector<long> viPowSum(n,0);
    vector<long> viPow(m,1);
    for(long i = 0; i < n; i++){
        for(long j = 0; j < m; j++){
            viPowSum[i] += viPow[j];
            viPow[j] *= j;
            viPow[j] %= nPrime;
        }
        viPowSum[i] %= nPrime;
    }
    vector<long> viPowM(n+1,1);
    for(long i = 1; i < n+1; i++){
        viPowM[i] = viPowM[i-1] * m;
        viPowM[i] %= nPrime;
    }

    vector<long> viDP(n+1,0);
    for(long i = 1; i < n+1; i++){
        viDP[i] = viDP[i-1] * m;
        long nCount0 = 0;
        for(long j = 0; j < i-1; j++){
            nCount0 += viPowSum[j] * viPowM[i-j-2];
            nCount0 %= nPrime;
        }
        viDP[i] += (viPowM[i] - nCount0);
        viDP[i] %= nPrime;
        if(viDP[i] < 0){
            viDP[i] += nPrime;
        }
    }
    cout << viDP[n] << endl;
}

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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

// const ll mod = 1000000007;
const ll mod = 998244353;

const int MAX_N = 100010;
ll fact[MAX_N],fact_inv[MAX_N],inv[MAX_N];

ll pow_mod(ll a,ll b) {
    ll ret;
    if (b < 0) ret = pow_mod(a,mod+b-1);
    else if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow_mod(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

void init(int x) {
    fact[0] = 1;fact[1] = 1;
    for (int i = 2;i <= x;++i) fact[i] = fact[i-1]*i%mod;
    fact_inv[x] = pow_mod(fact[x],-1);
    for (int i = x;i > 0;--i) fact_inv[i-1] = fact_inv[i]*i%mod;
    for (int i = 1;i <= x;++i) inv[i] = fact_inv[i]*fact[i-1]%mod;
}

ll combi(ll a, ll b) {
    return fact[a]*fact_inv[b]%mod*fact_inv[a-b]%mod;
}

ll permu(ll a, ll b) {
    return fact[a]*fact_inv[a-b]%mod;
}

int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<ll>> a(m+1,vector<ll>(n+1,1));
    for (int i = 0;i < m+1;++i) for (int j = 0;j < n;++j) a[i][j+1] = a[i][j]*i%mod;
    ll ans = n*a[m][n]%mod;
    for (int i = 1;i < n;++i) for (int j = 0;j < m;++j) {
        (ans -= (n-i)*a[m-j-1][i-1]%mod*a[m][n-i-1]%mod) %= mod;
    }
    cout << (ans+mod)%mod << newl;
}


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

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

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if ((ct = *ci++) >= '0') {
				tmp = tmp * 10 + ct - '0';
				ci++;
			}
		}
	}
	return tmp;
}
ll tmp[200001];
void pakuri_sort(int N, ll A[]) {
	const int b = 8;
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}
bitset<400010> ST;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N = getint(), M = getint();
	ll XY[200000];
	int k = 0;
	int nm1 = N - M, nm2 = N + M;
	rep(i, M) {
		int x = getint();
		int y = getint();
		if (y < nm1 | y > nm2) continue;
		XY[k++] = x | (ll)(y - N + 200001) << 32;
	}
	M = k;
	pakuri_sort(M, XY);

	ST[200001] = 1;
	const ll ma = (1ll << 32) - 1;
	int m = 0;
	while (m < M) {
		int m0 = m;
		int x = (XY[m] & ma);
		while (m < M && (XY[m] & ma) == x) {
			int y = (XY[m] >> 32);
			if (ST[y - 1] | ST[y + 1]) XY[m] |= 1ll;
			else if (ST[y]) XY[m] &= (~1ll);
			else XY[m] = 0;
			m++;
		}
		for (int p = m0; p < m; p++) {
			int y = (XY[p] >> 32);
			if (XY[p] & 1) ST[y] = 1;
			else if (XY[p]) ST[y] = 0;
		}
	}
	int kotae = ST.count();
	printf("%d\n", kotae);

	Would you please return 0;
}

#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <random>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
    int N;
    int M;
    vector<string> S(M, "");

    int L = 0;

    cin >> N >> M;
    for (int i = 0; i < M; i++)
    {
        cin >> S.at(i);
        L = max(L, (int)S.at(i).size());
    }

    /*
    todo 親和性の高い部分列同士をあらかじめ結合しておく

    //結合度3以上の二つを結合する。
    for(int ketsugou = L; L > 2; L--){
        for(int i = 0; i)
    }
    */

    //ランダムにあてはめる。
    vector<vector<char>> board(20, vector<char>(20, '.'));
    //todo:Sを並べ替える
    //mt19937 get_rand_mt;
    //shuffle( S.begin(), S.end(), get_rand_mt );
    //sort(S.begin(), S.end(), [](string &a, string &b){return a.size() >= b.size();});

    for (string s : S)
    {
        int best_score = -1;
        int best_pos = -1;
        //横0縦1
        bool best_muki_is_tate = true;
        for (int i = 0; i < 400; i++)
        {
            int pos_i = i / 20;
            int pos_j = i % 20;
            int goodness = 0;
            for (int s_index = 0; s_index < (int)s.size(); s_index++)
            {
                if (board.at((pos_i + s_index) % 20).at(pos_j) == '.')
                {
                    continue;
                }
                else if (board.at((pos_i + s_index) % 20).at(pos_j) == s.at(s_index))
                {
                    goodness += 1;
                }
                else
                {
                    goodness = -1;
                    break;
                }
            }
            if (goodness > best_score)
            {
                best_score = goodness;
                best_pos = i;
                best_muki_is_tate = false;
            }
            goodness = 0;
            for (int s_index = 0; s_index < (int)s.size(); s_index++)
            {
                if (board.at(pos_i).at((pos_j + s_index) % 20) == '.')
                {
                    continue;
                }
                else if (board.at(pos_i).at((pos_j + s_index) % 20) == s.at(s_index))
                {
                    goodness += 1;
                }
                else
                {
                    goodness = -1;
                    break;
                }
            }
            if (goodness > best_score)
            {
                best_score = goodness;
                best_pos = i;
                best_muki_is_tate = true;
            }
        }
        //boardを更新する。
        if (best_score == -1)
        {
            continue;
        }
        int pos_i = best_pos / 20;
        int pos_j = best_pos % 20;
        for (int s_index = 0; s_index < (int)s.size(); s_index++)
        {
            board.at((pos_i + !best_muki_is_tate * s_index)%20).at((pos_j + best_muki_is_tate * s_index)%20) = s.at(s_index);
        }
    }
    for(int i = 0; i < 20; i++){
        for(int j = 0; j < 20; j++){
            cout << board.at(i).at(j);
        }
        cout << endl;
    }
    return 0;
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

int pw(int n,int k){
  assert(k>=0);
  int res=1;
  while(k){
    if(k&1)res*=n;
    n*=n;
    k>>=1;
  }
  return res;
}

signed main(){
  string s;cin>>s;
  int ans=0;
  REP(i,10000){
    bool ok=1;
    set<int> se;
    REP(j,4)se.insert((i/pw(10,j))%10);
    REP(j,10){
      if(s[j]=='o'&&!se.count(j))ok=0;
      if(s[j]=='x'&&se.count(j))ok=0;
    }
    ans+=ok;
  }
  cout<<ans<<endl;
}

#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = ((n) - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

// inputs
#define VLLIN(x, n) vll x(n); REP(i, n) cin >> x[i];
#define VIIN(x, n) vin x(n); REP(i, n) cin >> x[i];
#define VLDIN(x, n) vld x(n); REP(i, n) cin >> x[i];
#define SIN(s, n) string s; cin >> s;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

template <typename T>
void print(vector<T>& x) {
    int N = x.size();
    REP(i, N) {
        if (i > 0) cout << " ";
        cout << x[i];
    }
    cout << "\n";
}

ll fact(ll n) {
    ll ans = 1;
    REP(i, n) ans *= i + 1;
    return ans;
}

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

    string s;
    cin >> s;

    ll ans = 0;
    REP(x, 10000) {
        int cur = x;
        set<int> ss;
        while(cur > 0) {
            ss.insert(cur % 10);
            cur /= 10;
        }

        if (x < 1000) ss.insert(0);

        bool f = true;
        REP(j, s.size()) {
            if (s[j] == 'x') {
                if (ss.count(j) > 0) {
                    f = false;
                    break;
                }
            } else if (s[j] == 'o') {
                if (ss.count(j) == 0) {
                    f = false;
                    break;
                }
            }
        }

        if (f) ans++;
    }

    print(ans);
}


#include<bits/stdc++.h>
using namespace std;
#define A(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define int long long
void _read();

int32_t main () { _read();

      int n;
      cin >> n;
      vector<char> vec;
      for( int i = 0; i < n; i++) {
            char c; cin >> c;
            if( c == 'x' && sz(vec) >= 2 && vec[sz(vec)-2] == 'f' && vec.back() == 'o') {
                  vec.pop_back();
                  vec.pop_back();
                  continue;
            }
            vec.push_back(c);
      }
      cout << sz(vec) << '\n';
      return 0;
};

void _read() {
      ios_base :: sync_with_stdio(false);
      cin.tie(NULL);
      #ifdef LOCAL
      freopen("input.txt","r",stdin);
      #endif
}

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define __ ios_base::sync_with_stdio(false);cin.tie(NULL);

const int maxn = 200007;

const int mod = 998244353;
int mod_pow(int a,int b){
    int x = 1;
    while(b){
        if(b&1)(x*=a)%=mod;
        (a*=a)%=mod;
        b>>=1;
    }
    return x;
}
vector<int> g[maxn],gr[maxn],graph[maxn];
vector<bool> used(maxn),vis(maxn);
vector<int> order, component;
void dfs1(int u) {
    used[u] = true;
    for(auto v:g[u]){
        if(!used[v])
            dfs1(v);
    }
    order.push_back(u);
}

void dfs2(int u) {
    used[u] = true;
    component.push_back(u);
    for(auto v:gr[u]){
        if(!used[v])
            dfs2(v);
    }
}

void dfs(int u){
    vis[u] = true;
    for(auto v:graph[u]){
        if(!vis[v])
            dfs(v);
    }
}

signed main(){__
    int n;
    cin>>n;
    vector<int> nums(n);
    for(auto &c:nums)cin>>c;
    vector<int> z[n+1];
    for(int i = 0;i<n;i++){
        g[i].push_back(nums[i]-1);
        gr[nums[i]-1].push_back(i);
        z[nums[i]].push_back(i);
    }

    for(int i= 0;i<=n;i++){
        for(int j = 1;j<z[i].size();j++){
            g[z[i][j-1]].push_back(z[i][j]);
            g[z[i][j]].push_back(z[i][j-1]);
            gr[z[i][j]].push_back(z[i][j-1]);
            gr[z[i][j-1]].push_back(z[i][j]);
        }
    }

    int c = 0;
    used.assign(n,false);
    for(int i=0;i<n;i++)
        if(!used[i])
            dfs1(i);
    used.assign(n,false);
    vector<int> p(n);
    for(int i=0;i<n;i++){
        int v = order[n-1-i];
        if(!used[v]){
            dfs2(v);
            for(auto d:component)
                p[d] = c;
            c++;
            component.clear();
        }
    }
    // for(auto d:p)cout<<d<<" ";
    // cout<<endl;
    for(int i = 0;i<n;i++){
        graph[p[nums[i]-1]].push_back(p[i]);
        graph[p[i]].push_back(p[nums[i]-1]);
    }

    int cont = 0;
    for(int i = 0;i<c;i++){
        if(!vis[i]){
            dfs(i);
            cont++;
        }
    }

    int ans = mod_pow(2,cont)-1;
    if(ans<0)ans+=mod;
    cout<<ans<<endl;
    return 0;
}