#include <bits/stdc++.h>
#define LL long long
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }

const int N  = 55,P = 998244353;
LL fac[N],ans = 1;
int a[N][N],n,k,fa[N],siz[N];
inline int Find(int x){ return x == fa[x] ? x : (fa[x] = Find(fa[x])); }
inline void Merge(int x,int y){ x = Find(x),y = Find(y),fa[x] = y; if (x!=y) siz[y]+=siz[x]; }
inline void solve(){
	int i,j,x,flag;
	for (i = 1; i <= n; ++i) fa[i] = i,siz[i] = 1;
	for (i = 1; i <= n; ++i) for (j = i+1; j <= n; ++j){
		flag = 1;
		for (x = 1; x <= n; ++x) if (a[i][x] + a[j][x] > k) flag = 0;
		if (flag) Merge(i,j);
	}
	for (i = 1; i <= n; ++i) if (i == Find(i)) ans = ans * fac[siz[i]] % P;
}
int main(){
	static int b[N][N];
	int i,j;
	fac[0] = 1;
	for (i = 1; i <= 54; ++i) fac[i] = fac[i-1] * i % P;
	cin >> n >> k;
	for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) cin >> a[i][j];
	solve();
	for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) b[i][j] = a[i][j];
	for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) a[i][j] = b[j][i];
	solve();
	cout << ans << '\n';
	return 0;
}

#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
using namespace std;

int main() {
	string n;
	cin >> n;
	int k;
	cin >> k;
	int nn = n.size();
	vector<vector<long long int>> v(nn + 1, vector<long long int>(k + 1, 0));
	unordered_set<int> us;
	long long int res = 0;
	const int mod = 1e9 + 7;
	for (int i = 1; i <= nn; i++) {
		// v[already checked][how many used]
		if (i > 1) {
			v[i][1] += 15;
		}
		for (int j = 0; j <= k; j++) {
			// v[i - 1][j] -> v[i][j or j + 1];
			v[i][j] += v[i - 1][j] * j;
			if (j > 0) v[i][j] += v[i - 1][j - 1] * (16 - j + 1);
			v[i][j] %= mod;
		}

		char c = n[i - 1];
		int nc = (c <= '9' and c >= '0' ? c - '0' : c - 'A' + 10);
		for (int j = (i == 1 ? 1 : 0); j < nc; j++) {
			int e = 0;
			if (us.count(j) == 0) e = 1;
			if (us.size() + e <= k) {
				v[i][us.size() + e]++;
			}
		}
		us.insert(nc);
	}
	if (us.size() == k) res++;
	for (int i = k; i <= k; i++) {
		res += v[nn][i];
	}
	res %= mod;
	cout << res << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = int64_t; using Vll =vector<ll>; using VVll =vector<vector<ll>>;
template <class T> using Vec = vector<T>; template <class T> using VVec = vector<vector<T>>;
#define INF 9223372036854775807LL/2
void Z(ll i=-1){ if(i==-1)cout<<"Test"<<endl; else cout<<"Test"<<i<<endl; }
template <class T> void VVcout(VVec<T> A){ for(auto Vi:A) { for(auto i:Vi)cout<<i<<' '; cout<<endl;}}
template <class T> void Vcout(Vec<T> A){ for(auto i:A) cout<<i<<' '; cout<<endl;}
template <class T> void chmax(T &x,T y){if(x<y) x=y;} template <class T> void chmin(T &x,T y){if(x==-1 || x>y) x=y;}
#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(si, i,n) for(ll i=si;i<n;i++)

int main(){
    ll n,a;
    cin>>n;
    Vll B(n,0);
    rep(i,n){
        cin>>a;
        B.at(a-1)++;

    }

    bool ans=true;

    rep(i,n) if(B.at(i)!=1) ans=false;

    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}

#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using ll = int64_t;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>
#define vv(T) vector<vector<T>>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T> ostream& operator<<(ostream& o, const set<T>& v) {
  for (auto e : v) {
    o << e << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  vi cs(3);
  cin >> cs;

  vector<vector<vector<ld>>> ca(100, vv(ld)(100, v(ld)(100,-1)));
  auto dfs = [&](auto dfs, vi& cs, int sum)->ld {
    if (cs[0] >= 100||cs[1]>=100||cs[2]>=100) {
      return 0;
    }
    if (ca[cs[0]][cs[1]][cs[2]] >= 0) {
      return ca[cs[0]][cs[1]][cs[2]];
    }
    ld re = 0;
    F0R(i, 3) {
      if (cs[i]) {
        cs[i]++;
        re += (dfs(dfs, cs, sum + 1) + 1) * (cs[i]-1) / sum;
        cs[i]--;
      }
    }

    return ca[cs[0]][cs[1]][cs[2]] = re;
  };
  cout << std::fixed << std::setprecision(15);
  cout << dfs(dfs, cs, cs[0]+cs[1]+cs[2]);
}
#endif


 // Lights will guide you home

#include <bits/stdc++.h>

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

void test()
{
    for(ll i = 1; i <= 100; i++)
    {
        ll cnt1 = 0, cnt2 = 0;

        for(ll j = 1; j * j <= i; j++)
        {
            if(j * j == i)
            {
                if(j & 1) cnt1++;
                else cnt2++;
            }
            else if(i % j == 0)
            {
                if(j & 1) cnt1++;
                else cnt2++;

                if((i / j) & 1) cnt1++;
                else cnt2++;
            }
        }

        cout << i << " = ";

        if(cnt1 > cnt2) cout << "ODD\n";
        else if(cnt1 == cnt2) cout << "SAME\n";
        else cout << "EVEN\n";
    }
}
int main()
{
    ll i, j, k, l, m, n, r, q;
    ll testcase;
    ll in, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

//    test();

    slld(testcase);

    for(ll cs = 1; cs <= testcase; cs++)
    {
        cin >> n;

        n--;

        if(n % 4 == 0 || n % 4 == 2) cout << "Odd\n";
        else if(n % 4 == 1) cout << "Same\n";
        else cout << "Even\n";
    }

}

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

int main() {

  int T;
  cin >> T;
  vector<long long> c(T);
  rep(i,T) cin >> c[i];

  rep(i,T) {
    if(c[i] % 2 == 1) {
      cout << "Odd" << endl;
    }
    else if((c[i] / 2) % 2 == 0) {
      cout << "Even" << endl;
    }
    else {
      cout << "Same" << endl;
    }
  }
}


#include <bits/stdc++.h>
int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int h = ri();
	int w = ri();
	int x = ri() - 1;
	int y = ri() - 1;
	std::string s[h];
	for (auto &i : s) std::cin >> i;

	int cnt = -3;
	for (int i = x; i < h && s[i][y] != '#'; i++) cnt++;
	for (int i = x; i >= 0 && s[i][y] != '#'; i--) cnt++;
	for (int j = y; j < w && s[x][j] != '#'; j++) cnt++;
	for (int j = y; j >= 0 && s[x][j] != '#'; j--) cnt++;
	printf("%d\n", cnt);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int a[200005];
int cnt;
int vis[2005];
vector<int>adj[20005];
void dfs(int v)
{
    vis[v] =1;
    cnt++;

    for(auto u: adj[v]){
        if(vis[u]==0)
            dfs(u);
    }
}
int main()
{
    int n, m;
    cin >> n >>m ;
    for(int i=0;i<m;i++){
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
    }

    int ans=0;
    for(int i=1;i<=n;i++){
        memset(vis, 0 , sizeof vis);
        cnt=0;
        dfs(i);
        ans+=cnt;
    }

    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define Rep(i,j,n) for(int i=j; i<n; i++)
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100//000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int>

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

  int ans=0;
  rep(i,h){
    rep(j,w-1){
      if(s[i][j]=='.' && s[i][j+1]=='.') ans++;
    }
  }

  rep(i,w){
    rep(j,h-1){
      if(s[j+1][i]=='.' && s[j][i]=='.') ans++;
    }
  }

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

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

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

    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];

    const int INF = 1001001001;
    vector<vector<int>> dp(1100, vector<int>(1100, INF));

    rep(i, n) dp[i][0] = i;
    rep(j, m) dp[0][j] = j;

    rep1(i, n+1) rep1(j, m+1){
        int cost = 1;
        if(a[i-1] == b[j-1]) cost = 0;
        dp[i][j] = min({dp[i-1][j]+1, dp[i][j-1]+1, dp[i-1][j-1]+cost});
    }

    cout << dp[n][m] << endl;

    return 0;
}


#include "bits/stdc++.h"
#include<sstream>
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const long long inf = 1e18;
const ll INFL = 1e18;
const ll MOD = 1e9 + 7;

int digit(ll x) {
    int digits = 0;

    while(x > 0){
        x /= 10;
        digits++;
    }

    return digits;
}

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

    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}

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

double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}

long long modpow(long long a, long long b, long long m){
    long long ans = 1;
    while(b > 0){
        if (b % 2 == 1){
            ans *= a;
            ans %= m;
        }
        a *= a;
        a %= m;
        b /= 2;
    }
    return ans;
}

long long comb(long long x, long long y){
    int z;
    if (y == 0) return 1;
    else {
        z = modpow(x, y/2, MOD)*modpow(x, y/2, MOD)%MOD;
        if (y % 2 == 1) z = z*x%MOD;
        return z;
    }
}

vector<pair<long long, long long>> prime_fact(long long x){
    vector<pair<long long, long long>> res;
    for(int i = 2;i*i <= x;i++){
        if (x % i == 0){
            long long cnt = 0;
            while(x % i == 0){
                cnt++;
                x /= i;
            }
            res.push_back({i, cnt});
        }
    }
    if (x != 1){
        res.push_back({x, 1});
    }
    return res;
}

int64_t mod_inv(int64_t a, int64_t m){
    int64_t b = m, u = 1, v = 0;

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

    return u;
}

// {g, x, y}: ax + by = g
tuple<long long, long long, long long> extgcd(long long a, long long b){
    if (b == 0) return {a, 1, 0};
    long long g, x, y;
    tie(g, x, y) = extgcd(b, a % b);
    return {g, y, x - a/b*y};
}

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

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

int main(){
    int n,k;
    cin >> n >> k;
    for(int i = 0;i < k;i++){
        string tmp = to_string(n);
        sort(tmp.begin(), tmp.end());
        int mini = stoi(tmp);
        sort(tmp.begin(), tmp.end(), greater<>());
        int mx = stoi(tmp);
        n = mx - mini;
    }
    cout << n << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i, N) for(int i = 0; i < (int)N; i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007

long int powi(long int a, long int n){
    int re = 1;
    rep(i, n) re *= a;
    return re;
}
long int func(long int a){
    long int re = 0;
    vector<long int> v;
    while(a > 0){
        v.push_back(a % 10);
        a /= 10;
    }
    sort(all(v));
    rep(i, v.size()) re += powi(10,i) * (v.at(i)-v.at(v.size()-1-i));
    return re;
}
int main(){
    long int N, K, ans;
    cin >> N >> K;
    ans = N;
    rep(i, K) ans = func(ans);
    cout << ans << endl;
}


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

int main() {
	int a, b, c,d;
	cin >> a >> b >> c >> d;
	cout << a * d - b * c;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d,k,sum;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	k=c*d-b;
	if(k<=0){
		printf("-1\n");
	}else{
		sum=a/k;
		if(sum*k<a)
			sum++;
		printf("%d\n",sum);
	}
	return 0;
}


/*
  Author     : MatsuTaku
  Date         : 05/22/21
  Certificate:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDF9T447OEo8XSQ6O1AznN5tKC8mzvYc4Zs3+oOKfMqgLXfOwQnpfcoxKs4MAP1eICBD13PkcIezJ9IlV6nKQZKs1BQmvjSXJ+zKK8YCKvAueNPuNO0Bim43IBaNHNFWcMvcmUvHgRb6hUSO0V8I7OsjiFo20KDBj3gAznu9tir0Q== CompetitiveProgrammingCertification:tkm.matsumoto@gmail.com
*/

#include <bits/stdc++.h>
using namespace std;
#include <x86intrin.h>
#define REP(i, l, r)      for (int i = (l), i##_less = (r); i < i##_less; i++)
#define rep(i, n)         REP(i, 0, n)
#define RREP(i, l, r)     for (int i = (r)-1, i##_least = (l); i >= i##_least; i--)
#define rrep(i, n)        RREP(i, 0, n)
#define chmax(dst, x)     dst = max(dst, (x))
#define chmin(dst, x)     dst = min(dst, (x))
using lint = long long int;
using ulint = unsigned long long int;
template<typename T>
using vvec = vector<vector<T>>;
template<typename T>
vvec<T> make_vvec(int n, int m, T v) { return vvec<T>(n, vector<T>(m, v)); }

class Solver {
 public:
  Solver();
  void solve();
};

Solver::Solver() {}

void Solver::solve() {
  int a,b,c; cin>>a>>b>>c;
  int ans = 7*3 - (a+b+c);
  cout << ans << endl;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  Solver solver;
  int t = 1;
//  cin>>t;
  while (t--) {
    solver.solve();
  }
  return 0;
}

#include <bits/stdc++.h>

#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i, n) for(ll i=n-1;i>=0;--i)
#define rep1(i, n) for(ll i=1; i<=n; ++i)
#define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();++itr)
#define ALL(a) (a).begin(),(a).end()

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

using namespace std;
using ll  = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;

const ll MOD  = 998244353;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;
const double PI = 3.1415926535897932384626;

ll mod(ll a, ll m){return (a + m) % m;}

int main(){
    ll r, x, y;
    cin >> r >> x >> y;

    ll dist = x*x + y*y;
    if(dist % (r*r)){
        if((ll)sqrt(dist / (r*r)) == 0)cout << 2 << endl;
        else cout << (ll)sqrt(dist / (r*r)) + 1 << endl;
        return 0;
    }

    ll a = dist / (r*r);
    ll sqa = sqrt(a);
    if(a == sqa * sqa)cout << sqa;
    else cout << sqa + 1;
}


#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

// using namespace boost::multiprecision;
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int N=1000005;
ll fact[N],invfact[N];
ll power(ll x,ll y){
  if(y<=0) return 1LL;
  ll z=power(x,y/2);
  if(y%2) return (((z*z)%mod)*x)%mod;
  return (z*z)%mod;
}

void pre(){
  fact[0]=invfact[0]=invfact[1]=fact[1]=1;
  rep(i,2,N) fact[i]=(i*fact[i-1])%mod;
  rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod;
}
ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; }

const int N1=1e6+1;
vector<int> isprime(N1,1),prime;
void seive(){
  rep(i,2,sqrt(N1)+1){
      if(isprime[i]){
        for(int j=i*i;j<N1;j+=i) isprime[j]=0;
        prime.pb(i);
      }
  }
  rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i);
}

struct dsu {
    vector<int> par, rank;
    dsu(int n): par(n+1), rank(n+1) {
        for (int i = 0; i <= n; i++) {
            par[i] = i;
            rank[i]= 1;
        }
    }
    int root(int a) {
        if (a == par[a]) return a;
        return par[a] = root(par[a]);
    }
    void merge(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return;
        if (rank[a] > rank[b]) swap(a, b);
        par[b] = a;
    }
    set<int> parent(int n){
        set<int> s;
        for(int i=1;i<=n;i++){
            s.insert(root(i));
        }
        return s;
    }
};

void solve(){
  int a,b,w;
  cin>>a>>b>>w;
  int l=ceil((1.0*w*1000)/b),r=floor((1.0*w*1000)/a);
  if(l>r) cout<<"UNSATISFIABLE";
  else cout<<l<<" "<<r<<endl;
}

int main(){
    optimizeIO();
    int r=1;
    {solve();}
}

#include <bits/stdc++.h>
#define Rep(i,n) for(int i=0;i<n;i++)
#define Repr(i,n) for(int i=n;i>=0;i--)
#define For(i,m,n) for(int i=m;i<n;i++)
#define All(v) v.begin(),v.end()
#define Mod (ll)(1e9+7)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
const int Inf = INT_MAX / 2; 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(b<a){a=b;return 1;}return 0;}

int H, W;
string A[2020];
bool vis[2020][2020];
int memo[2020][2020];
int dp(int x, int y) {
    if(vis[y][x]) return memo[y][x];
    vis[y][x] = true;

    int turn = (x + y) % 2;

    if(x==W-1 && y==H-1)return memo[y][x]=0;

    if(turn==0) {
        // Takahashi
        memo[y][x]=-Inf;
        if(y<H-1)chmax(memo[y][x],dp(x,y+1)+(A[y+1][x]=='+'?1:-1));
        if(x<W-1)chmax(memo[y][x],dp(x+1,y)+(A[y][x+1]=='+'?1:-1));
        return memo[y][x];
    }
    else {
        // Aoki
        memo[y][x] = Inf;
        if(y<H-1)chmin(memo[y][x],dp(x,y+1)-(A[y+1][x]=='+'?1:-1));
        if(x<W-1)chmin(memo[y][x],dp(x+1,y)-(A[y][x+1]=='+'?1:-1));
        return memo[y][x];
    }
}

int main()
{
    cin>>H>>W;
    For(y,0,H)cin>>A[y];

    int opt=dp(0,0);

    if(0<opt)cout<<"Takahashi"<<endl;
    else if(opt==0)cout<<"Draw"<<endl;
    else cout<<"Aoki"<<endl;
    return 0;
}


//@formatter:off
#include<bits/stdc++.h>
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(i,n) for (ll i = 0; i < ll(n); ++i)
#define rep2(i,s,n) for (ll i = ll(s); i < ll(n); ++i)
#define rep3(i,s,n,d) for(ll i = ll(s); i < ll(n); i+=d)
#define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(i,n) for (ll i = ll(n)-1; i >= 0; i--)
#define rrep2(i,n,t) for (ll i = ll(n)-1; i >= (ll)t; i--)
#define rrep3(i,n,t,d) for (ll i = ll(n)-1; i >= (ll)t; i-=d)
#define rrep(...) overload4(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define popcount(x) __builtin_popcount(x)
#define pb push_back
#define eb emplace_back
#ifdef __LOCAL
#define debug(...) { cout << #__VA_ARGS__; cout << ": "; print(__VA_ARGS__); cout << flush; }
#else
#define debug(...) void(0)
#endif
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,int>;
using LP = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vs = vector<string>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vp = vector<P>;
using vvp = vector<vector<P>>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
template<class T> void vecout(const vector<T> &v,char div='\n') { rep(i,v.size()) cout<<v[i]<<(i==int(v.size()-1)?'\n':div);}
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
void scan(){}
template <class Head, class... Tail> void scan(Head& head, Tail&... tail){ cin >> head; scan(tail...); }
template<class T> void print(const T& t){ cout << t << '\n'; }
template <class Head, class... Tail> void print(const Head& head, const Tail&... tail){ cout<<head<<' '; print(tail...); }
template<class... T> void fin(const T&... a) { print(a...); exit(0); }
const string yes[] = {"no","yes"};
const string Yes[] = {"No","Yes"};
const string YES[] = {"NO","YES"};
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << boolalpha << fixed << setprecision(15);
    INT(n);
    vi ans(n);
    rep(i, 1, n + 1) {
        set<int> st;
        for (int j = 1; j * j <= i; j++) {
            if (i % j == 0) {
                if (j < i) st.insert(ans[j - 1]);
                if (i / j < i) st.insert(ans[i / j - 1]);
            }
        }
        rep(k, 1, n + 1) {
            if (st.count(k)) continue;
            ans[i - 1] = k;
            break;
        }
    }
    vecout(ans, ' ');
}

/* [Template].cpp
Example code to use when starting new code. This particular problem was problem
977A_Wrong_Subtraction from CodeForces

Compile: g++  -o B.exe B.cpp
Execute: ./B
*/

#include <cstdio>
#include <iostream>
#include <cmath>
#include <limits>
#include <iomanip>
#include <cstring>
#include <bits/stdc++.h>
#include <string>
using namespace std;

#define ull unsigned long long
#define ll long long

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

	int h, w, x, y;
	cin >> h >> w >> x >> y;
	x--; y--;

	vector<vector<char>> floor_plan (h, vector<char>(w));
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			cin >> floor_plan[i][j];
		}
	}

	int result = 1;
	// Up
	for(int i = x-1; i >= 0 && floor_plan[i][y] != '#'; i--) {
		result++;
	}
	//cout << "Up" << endl;

	// Down
	for(int i = x+1; i < h && floor_plan[i][y] != '#'; i++) {
		result++;
	}
	//cout << "Down" << endl;

	// Left
	for(int j = y-1; j >= 0 && floor_plan[x][j] != '#'; j--) {
		result++;
	}
	//cout << "Left" << endl;

	// Right
	for(int j = y+1; j < w && floor_plan[x][j] != '#'; j++) {
		result++;
	}
	//cout << "Right" << endl;

	cout << result << endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   N     =  3e5+5;
const ll   mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll n, a[N], l[N], r[N];

ll tree[N] = {};

void update(int idx, int val){
    idx++;
    while(idx <= N-2){
        tree[idx] += val;
        idx += idx & (-idx);
    }
}

ll query(int idx){
    idx++;
    ll sum = 0;
    while(idx > 0){
        sum += tree[idx];
        idx -= idx & (-idx);
    }
    return sum;
}

void solve(){
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	ll ans = 0;
	for(int i = 1; i <= n; i++){
		l[i] = query(a[i]), r[i] = a[i] - l[i];
		ans += r[i];
		update(a[i], 1);
	}
	cout << ans << "\n";
	for(int i = 1; i < n; i++){
		ans += n - i - 2 * r[i];
		ans += i - 1 - 2 * l[i];
		cout << ans << "\n";
	}
}

int main(){
	GODSPEED;
	int test = 1;
	//cin >> test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v){
    if(v.empty()){
        os<<"{ }";
        return os;
    }
    os<<"{"<<v.front();
    for(auto itr=++v.begin();itr!=v.end();itr++){
        os<<", "<<*itr;
    }
    os<<"}";
    return os;
}

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

template<typename T>
class BIT{
public:
    int n;
    vector<T> bit; // 1-indexed

    BIT():n{0}{}
    BIT(int n_in):n{n_in}{
        bit.assign(n+1,0);
    }

    void init_u(){
        for(int i=1;i<n;i++)if(i+(i&-i)<=n) bit[i+(i&-i)]+=bit[i];
    }

    void add(int k,T w){
        if(k<=0) return;
        for(int i=k;i<=n;i+=i&-i) bit[i]+=w;
    }

    //(0,k]
    T sum(int k) const{
        T res=0;
        for(int i=k;i>0;i-=i&-i) res+=bit[i];
        return res;
    }

    //(l,r] 累積和区間と同じ
    T secsum(int l,int r) const{
        return sum(r)-sum(l);
    }

    //各要素は非負整数とする
    //w->w+1でupper_bound
    int lower_bound(T w) const{
        if(sum(n)<w) return n+1; //範囲外
        int idx=0,r=1;
        while(r<n) r<<=1;
        for(int len=r;len>0;len>>=1){
            if(idx+len<n && bit[idx+len]<w){
                w-=bit[idx+len];
                idx+=len;
            }
        }
        return idx+1;
    }
};

int main(){
    ll n; cin>>n;
    vector<ll> a(n,0);
    rep(i,n) cin>>a[i];
    BIT<ll> bit(n+1);
    ll ans=0;
    rep(i,n){
        ans+=bit.secsum(a[i]+1,n+1);
        bit.add(a[i]+1,1);
    }
    cout<<ans<<endl;
    rep(i,n-1){
        ans=ans-a[i]+(n-1-a[i]);
        cout<<ans<<endl;
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
using namespace std;
#define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
typedef int ll;
ll n,m;
ll cnt=0;
long long ans=0;
long long mod=998244353;
ll a[32]={0};
ll b[32]={0};
void dfs(ll su,ll num)
{
	if(su*5>n)
    {
      if(su*4<=n)
	      b[num]++,b[num+1]+=3,b[num+2]++;
      else if(su*3<=n) b[num]++,b[num+1]+=2;
      else if(su*2<=n) b[num]++,b[num+1]++;
      else b[num]++;
      return;
    }
	b[num]++;
	for(ll i=2*su;i<=n;i+=su)
	{
		dfs(i,num+1);
	}
}
long long qpow(long long a,long long b)
{
	if(b==0) return 1;
	long long c=qpow(a,b/2);
	if(b%2==0) return c*c%mod;
	else return c*c%mod*a%mod;
}
long long jie[200005]={0};
int main(void)
{
	scanf("%d%d",&m,&n);
	for(ll i=1;i<=n;i++)
	{
		ll cnt=1;
		memset(b,0,sizeof(b));
		dfs(i,1);
		while(n/i==(n/(i+1))) cnt++,i++;
		for(ll j=0;j<32;j++) a[j]+=b[j]*cnt;
	}
	ll ans=0;
	jie[0]=1;
	for(ll i=1;i<=m;i++) jie[i]=jie[i-1]*(long long)i%(long long)mod;
	for(long long i=1;i<=min(m,30);i++)
	{
		ans=(ans+a[i]*jie[m-1]%mod*qpow(jie[i-1]*jie[m-i]%mod,mod-2)%mod)%mod;
	}
	cout<<ans;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const int inf = 1e9;
const ll infll = 1e18;
const int M = 998244353;
const int N = 2e5;

int fact[N+1], inv[N+1];

int ad(ll a, ll b){
	return (a + b)%M;
}
int mul(ll a, ll b){
	return(a*b)%M;
}
int fp(int a , int b){
	int ret = 1;
	while(b){
		if(b&1) ret = mul(ret , a);
		b >>= 1;
		a = mul(a , a);
	}
	return ret;
}

int ch(int n , int k){
	if(k > n)return 0;
	return mul(fact[n], mul(inv[n-k], inv[k]));
}
void testCase(){
	int n , m, ans = 0;
	scanf("%d%d", &n, &m);
	vector<int> dp(m+1,1);
	for (int k = 1; k <= 20; ++k){
		vector<int> newDp(m+1, 0);
		int tmp = 0;
		for (int i = 1; i <= m; ++i){
			for (int j = i*2; j <= m; j += i){
				newDp[j]= ad(newDp[j], dp[i]);
			}
			tmp = ad(tmp, dp[i]);
		}
		ans = ad(ans, mul(ch(n-1, k-1), tmp));
		dp = newDp;
	}
	printf("%d\n", ans);
}

int main(){
	fact[0] = inv[0] = 1;
	for (int i = 1; i <= N; ++i){
		fact[i] = mul(i , fact[i-1]);
		inv[i] = fp(fact[i], M - 2);
	}
	//cout << ch(5, 0) << endl;
	int T = 1;
	//scanf("%d", &T);
	for (int tt = 1; tt <= T; ++tt){
		testCase();
	}
}


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

#define int long long

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, x; cin >> n >> x;
	vector <int> a(n);
	for(int &y: a) cin >> y;
	vector <vector <int> > dp(n, vector <int> (2, 0));
	dp[n - 1][0] = dp[n - 1][1] = 1;
	for(int i = n - 2; i >= 0; i--) {
		for(int j = 0; j <= 1; j++) {
			int s = (x % a[i + 1]) / a[i] + j, k = a[i + 1] / a[i];
			if(s % k == 0) {
				dp[i][j] = dp[i + 1][j];
			} else {
				dp[i][j] = dp[i + 1][0] + dp[i + 1][1];
			}
		}
	}
	cout << dp[0][0] << endl;
}

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pai
#include <vector>        // vector

typedef long long ll;

using namespace std;

// イテレーション
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define repk(i, k, n) for (ll i = k; i < ll(n); i++)

// x:コンテナ
#define ALL(vec) vec.begin(), vec.end()
#define SIZE(x) ll(x.size())

#define debug(x) cout << "debug: " << x << endl

// 定数
#define MOD 1000000007
#define INF32 2147483647
#define INF64 9223372036854775807

void DoSomething() {
  //
  int a, b;
  cin >> a >> b;
  int ans = (2 * a) + 100;
  cout << ans - b << endl;
}

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

  DoSomething();

  return 0;
}


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
struct edge{
    ll to,cost;
    edge(ll to,ll cost):to(to),cost(cost) {}
};
vector<vector<edge>> g;
vector<ll> d;
int n,m;
ll ds(ll s){
    d.resize(n);
    for(int i=0;i<n;i++)d[i]=inf;
    d[s]=0;
    priority_queue<P,vector<P>,greater<P>> q;
    q.push(P(0,s));//始点を０で置く
    ll res=inf;
    while(!q.empty()){
        ll cur=q.top().se,val=q.top().fi;
        q.pop();
        if(val>d[cur])continue;
        for(edge &e:g[cur]){
            if(e.to==s){
                 chmin(res,val+e.cost);
                 continue;
            }
            if(d[e.to]>d[cur]+e.cost){
                d[e.to]=d[cur]+e.cost;
                q.push(P(d[e.to],e.to));
            }
        }
    }
    return res;
}
int main(){
    cin>>n>>m;
    g.resize(n);
    for(int i=0;i<m;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        --a;--b;
        g[a].emplace_back(b,c);
    }
    for(int i=0;i<n;i++){
          ll ans=ds(i);
          cout<<(ans>=inf?-1:ans)<<"\n";
    }

}

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>

#define int long long
#define lowbit(x) (x&(-x))
#define mid ((l+r)>>1)
#define lc (x<<1)
#define rc (x<<1|1)
#define fan(x) (((x-1)^1)+1)
#define max Max
#define min Min
#define abs Abs

using namespace std;

inline int read()
{
	int ans=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=(ans<<1)+(ans<<3)+c-'0';c=getchar();}
	return ans*f;
}

inline void write(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x/10) write(x/10);
	putchar((char)(x%10)+'0');
}

template<typename T>inline T Abs(T a){return a>0?a:-a;};
template<typename T,typename TT>inline T Min(T a,TT b){return a>b?b:a;}
template<typename T,typename TT> inline T Max(T a,TT b){return a>b?a:b;}

const int N=2005;
int n,m,vis[N],dis[N][N],mp[N][N],ans;

struct Edge
{
	int v,w,ne;
}e[N*2];
int head[N],tot;

struct Node
{
	int u,w;
	bool operator < (const Node &x)const
	{
		return w>x.w;
	}
};

inline void add(int u,int v,int w);
inline void dij(int st);

signed main()
{
	n=read();m=read();
	for(int i=1;i<=m;++i)
	{
		int u=read(),v=read(),w=read();
		if(mp[u][v]==0) mp[u][v]=w;
		else mp[u][v]=min(mp[u][v],w);
	}
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			if(i!=j&&mp[i][j]!=0) add(i,j,mp[i][j]);
	for(int i=1;i<=n;++i) dij(i);
	for(int i=1;i<=n;++i)
	{
		int ans=1e18;
		for(int j=1;j<=n;++j)
			if(i==j)
			{
				if(dis[i][j]!=-1)
					ans=min(ans,dis[i][j]);
			}
			else if(dis[i][j]!=-1&&dis[j][i]!=-1)
				ans=min(ans,dis[i][j]+dis[j][i]);
		if(ans==1e18) printf("-1\n");
		else printf("%lld\n",ans);
	}
	return 0;
}

inline void add(int u,int v,int w)
{
	e[++tot]=(Edge){v,w,head[u]};
	head[u]=tot;
}

inline void dij(int st)
{
	memset(vis,0,sizeof(vis));
	memset(dis[st],-1,sizeof(dis[st]));
	priority_queue<Node> qu;
	qu.push((Node){st,0});
	dis[st][st]=0;
	while(!qu.empty())
	{
		int u=qu.top().u;
		qu.pop();
		if(vis[u]) continue;
		vis[u]=1;
		for(int i=head[u];i;i=e[i].ne)
		{
			int v=e[i].v;
			if(dis[st][v]==-1||dis[st][v]>dis[st][u]+e[i].w)
			{
				dis[st][v]=dis[st][u]+e[i].w;
				if(!vis[v]) qu.push((Node){v,dis[st][v]});
			}
		}
	}
	if(mp[st][st]!=0) dis[st][st]=mp[st][st];
	else dis[st][st]=-1;
}


#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

void one_case() {

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

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

    int t = 1;
//    cin >> t;
    for (int i = 0; i < t; ++i) {
//        cout << "Case #" << i + 1 << ": ";
        one_case();
    }

    return 0;
}

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <iterator>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ll long long int
using namespace std;

int main()
{
	string str;
	cin>>str;
	for(int i = 0; i < str.length(); i++){
		char ch = str[i];
		if(ch == '.') break;
		cout<<ch;
	}
	cout<<endl;
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

/* INCLUDE STATEMENTS */
#include <bits/stdc++.h>

/* NAMESPACES */
using namespace std; //  (┛ಠ_ಠ)┛  "Bad" Practice

/* ALIASES */
typedef long long lli;
typedef long double ld;
typedef unsigned uns;

typedef pair<int, int> pi;
typedef pair<lli, lli> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<lli> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

/* DEFINITIONS */
#define mp make_pair
#define pb push_back
#define F  first
#define S  second
#define lb lower_bound
#define ub upper_bound

#define fo(i, a, b) for(auto i=a; i<(b); i++)
#define forev(i, b, a) for(auto i = (b)-1; i >= a; i--)
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define sz(x) (int)x.size()
#define enl "\n"
#define deb(x) cout << #x << ": " << x << enl;

/* CONSTANTS */
// const ld PI = 4 * atan((ld)1);
// const int MOD = 1000000007;
// const lli INF = 1e18;
// const int MX = INT_MAX - 1;

/* UTILITIES */
template<typename T> bool _odd(T a) {return a & 1;}
template<typename T> bool _even(T a) {return !(a & 1);}

/*===========================================================================*/

void solve() {
    lli n, k; cin >> n >> k;
    vpl frn;
    fo(i, 0, n) {
        lli a, b; cin >> a >> b;
        frn.pb(mp(a, b));
    }
    sortall(frn);
    lli a = 0, c, d;
    fo(i, 0, n) {
        c = frn[i].F;
        d = frn[i].S;
        if ((c - a) > k) break;
        k -= (c - a);
        k += d;
        a = c;
    }
    cout << k + a;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    // cin >> t;
    fo(i, 0, t) {
        solve();
    }
    return 0;
}

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll N;
    cin >> N;
    vector<ll> P(N+1);
    rep(i,0,N) cin >> P[i];
    ll pos[200010] = {};
    rep(i,0,N){
        pos[P[i]] = i;
    }
    bool ok = true;
    vector<ll> ans;
    ll cur = 1;
    bool check[200010] = {};

    rep(t,0,N-1){
        while(cur <= N){
            if(pos[cur] != cur-1){
                break;
            }else{
                cur++;
            }
        }
        if(cur == N+1 || pos[cur] == 0 || check[pos[cur]-1] == true){
            ok = false;
            break;
        }
        // print(cur, pos[cur]);
        check[pos[cur]-1] = true;
        ans.push_back(pos[cur]-1 + 1);
        ll left_num = P[pos[cur]-1];
        swap(P[pos[cur]-1], P[pos[cur]]);
        pos[left_num] = pos[cur];
        pos[cur] = pos[cur]-1;
    }
    rep(i,1,N+1){
        if(P[i-1] != i) ok = false;
    }
    if(ok){
        for(auto &e: ans) print(e);
    }else{
        print(-1);
    }

}

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


#include <algorithm>
#include <cmath>
// #include <cstdio>
// #include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#ifdef BUGS
#define PEEK(x) cout << #x << ": " << x << endl;
#else
#define PEEK(x) ;
#endif
using namespace std;
using ll = long long;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
const int INF_32 = 0x3f3f3f3f;
const ll INF_64 = 0x3f3f3f3f3f3f3f3f;
// priority_queue<ll, vector<ll>, greater<ll>> minor_que;
ll n, m, k;
long long qpowMod(long long a, long long b, long long M) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % M;
    a = a * a % M;
    b >>= 1;
  }
  return res;
}
void scan_d(int &ret) {
  char c;
  ret = 0;
  while ((c = getchar()) < '0' || c > '9')
    ;
  while (c >= '0' && c <= '9') ret = ret * 10 + (c - '0'), c = getchar();
}
void scan_d(ll &ret) {
  char c;
  ret = 0;
  while ((c = getchar()) < '0' || c > '9')
    ;
  while (c >= '0' && c <= '9') ret = ret * 10 + (c - '0'), c = getchar();
}
void init() {
  ;
  ;
}
// C(2, 3) = C_5^3 = C_5^2 = 10
ll C(ll x, ll y) {
  if (x < 0 || y < 0) return 0;
  ll ret = 1;
  for (int i = 1; i <= x + y; ++i) {
    ret *= i;
    ret %= MOD;
  }
  for (int i = 1; i <= x; ++i) {
    ret *= qpowMod(i, MOD - 2, MOD);
    ret %= MOD;
  }
  for (int i = 1; i <= y; ++i) {
    ret *= qpowMod(i, MOD - 2, MOD);
    ret %= MOD;
  }
  return ret;
}
void solve(int casei) {
  // ...
  if (n > m + k) {
    printf("0\n");
  } else {
    // (M + N -> N) - (M + N -> K + 1 + M)
    // printf("%lld %lld\n", C(m, n), C(k + 1 + m, n - k - 1));
    printf("%lld\n", (C(m, n) + MOD - C(k + 1 + m, n - k - 1) + MOD) % MOD);
  }
}
int main() {
  int Case = 1;
  // scanf("%d", &Case);
  // ios::sync_with_stdio(false);
  // cin.tie(0);
  // cout.tie(0);
  // cin >> Case;
  for (int casei = 1; casei <= Case; ++casei) {
    scanf("%lld %lld %lld", &n, &m, &k);
    init();
    solve(casei);
  }
  return 0;
}

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

using vi=vector<int>;
using vvi=vector<vi>;
using LL=long long;
using vL=vector<LL>;
using vvL=vector<vL>;

const int MAX = 2000001;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // 前処理
  COMinit();

  int n,m,k;
  cin>>n>>m>>k;

  if (n>m+k) {
    cout<<0<<endl;
  }
  else {
    cout<<( ( COM(n+m,n)-COM(n+m,m+k+1) )%MOD+MOD)%MOD<<endl;
  }

}


#include <bits/stdc++.h>
using namespace std;
stack<char> zhan;
int main(){
    int n;
    string k;
    cin >> n >> k;
    for(int i = 0;i < k.length();i++){
        if(zhan.size() < 2){
            zhan.push(k[i]);
            continue;
        }
        char c = zhan.top();
        zhan.pop();
        if(zhan.top() == 'f' && c == 'o' && k[i] == 'x'){
            zhan.pop();
            continue;
        }
        zhan.push(c);
		zhan.push(k[i]);
    }
    cout <<zhan.size();
    return 0;
}

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

typedef long long int ll;

int main() {
    ll n,i;cin>>n;
    vector<ll> a(n),b(n+1);
    for(i=0;i<n;i++){
        cin>>a[i];
        b[a[i]]=1;
    }
    int r=0;
    for(i=1;i<=n;i++){
        if(b[i]!=1){
            r=1;
            break;
        }
    }
    if(r==0) cout<<"Yes";
    else cout<<"No";
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int m,h;
	scanf("%d %d",&m,&h);
	if(h%m==0) printf("Yes\n");
	else printf("No\n");
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define F first
#define S second
#define YES(n)cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

int main(){
    int M,H;
    cin>>M>>H;
    Yes(H%M==0);
    return 0;
}


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

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

    int limit = A * 2 + 100;

    cout << limit - B;

    return 0;

}

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

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

  int sum;
  sum = (7 - a) + (7 - b) + (7 - c);
  cout << sum;
}


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

// @author: sharad_sharma

#define ll                long long
#define ld                long double
#define mod               1000000007
#define inf               1e18
#define pb                push_back
#define all(n)            n.begin(),n.end()
#define loop(i,a,b)       for(int i=(a);i<=(b);i++)
#define logarr(arr)       for(int z=(0);z<(arr.size());z++) cout<<(arr[z])<<" ";cout<<endl;
#define deb(x)            cout << #x << " = " << x << endl
#define debu(x, y)        cout << "( " << #x << ", " << #y << " ) = ( " << x << ", " << y << " )" << endl

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int long long
void file_i_o()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
	#endif
}

int N = 25;
vector<vector<int>> adj(N);
vector<int> visited(N, 0);
vector<int> col(N, 0);
vector<int> level(N, 0);

// i want to search exhaustively
int dfs(int i, int p) {
	//if(visited[i]) return 1;
	level[i] = level[p] + 1;
	visited[i] = 1;
	int ret = 1;

	for(auto u: adj[i]) {
		//if(u == p) continue;	// this is not enough if their level is same then it must return 0
		if(level[u] != 0 && level[u] != level[i] + 1) {
			if(col[u] == col[i]) {
				// this should not be allowed
				return 0;
			}
			continue;
		}

		int tem = 0;
		for(int c=1; c<4; c++) {
			if(col[i] == c) continue;
			col[u] = c;
			tem += dfs(u, i);
			col[u] = 0;
		}
		ret *= tem;
	}
	return ret;
}

int32_t main(int32_t argc, char const *argv[]) {
	clock_t begin = clock();
	file_i_o();

	// Write your code here....
	int n, m;
	cin >> n >> m;
	for(int i=0; i<m; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	int ans = 1LL;

	for(int i=0; i<n; i++) {
		if(visited[i]) continue;
		// let's say we colour Red on i so, it's edges is either blue or green
		col[i] = 1;	// let's say Red is 1
		level[i] = 0;
		int dd = dfs(i, i);
		ans = ans*3LL*dd;
	}
	cout << ans << "\n";

	#ifndef ONLINE_JUDGE
	  clock_t end = clock();
	  cout<<"\n\nExecuted In: "<<double(end - begin) / CLOCKS_PER_SEC*1000<<" ms";
	#endif
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MAX =1000000000000000000;
ll mod= 1000000000;
long double pi=3.141592653589793238;
void pls()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
}
ll n,m,k;
vector<pair<ll,ll>> p,temp;
ll recursion(int i,vector<int> &visi){
   if(i==k)
   {
        ll tot=0;
        for(i=0;i<p.size();i++){
            if(visi[p[i].first] && visi[p[i].second])
              tot++;

        }
        return tot;
    }

        visi[temp[i].first]+=1;
        ll val=recursion(i+1,visi);
        visi[temp[i].first]-=1;
        visi[temp[i].second]+=1;
        ll val1=recursion(i+1,visi);
        visi[temp[i].second]-=1;
        return max(val,val1);

}
void solve()
{
          cin>>n>>m;
          for(int i=0;i<m;i++){
            ll x,y; cin>>x>>y;
            p.push_back({x,y});
          }
          cin>>k;
          for(int i=0;i<k;i++){
            ll x,y; cin>>x>>y;
            temp.push_back({x,y});
          }
          vector<int> visi(n+1,0);
          cout<<recursion(0,visi)<<endl;

}
int main(){pls(); solve(); return 0;}
/*
  Mostly wrong answer form base case or overflow or runtime
  Debug--> check overflow---> check varible name---> check logic implementation----> check logic

*/


#include<bits/stdc++.h>
#define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define endl "\n"
#define vll vector<ll>
#define vlll vector<vll>
#define all(x) x.begin(),x.end()
ll power(ll x, ll y, ll p) {
    ll res = 1;    x = x % p;
    while(y > 0) {
        if(y & 1) res = (res*x) % p;
        y = y>>1;    x = (x*x) % p;
    } return res;
}

inline void solve()
{
    ll n,x;
    cin>>n>>x;
    string s;
    cin>>s;
    f(s.length())
    {
        if(s[i]=='o')
        x++;
        else if(x>0)
        x--;
    }
    cout<<x<<endl;

}
int main()
{
    Imposter

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

    }
    return 0;
}

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }

    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}

long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n,k,m;
  cin>>n>>k>>m;
  int a[n-1];
  int s = 0;
  REP(i,n-1){
    cin>>a[i];
    s += a[i];
  }
  int r = n*m - s;
  if(r > k){
    cout<<-1<<endl;
    return 0;
  }
  r = max(0, r);
  cout<<r<<endl;
  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <fstream>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define x first
#define y second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cerr << #x << ": " << x << '\n';
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define FORN(i, n) for (int i = 1; i <= n; ++i)
#define pb push_back
#define trav(a, x) for (auto& a : x)
using vi = vector<int>;
template <typename T>
std::istream& operator >>(std::istream& input, std::vector<T>& data)
{
    for (T& x : data)
        input >> x;
    return input;
}
template <typename T>
std::ostream& operator <<(std::ostream& output, const pair <T, T> & data)
{
    output << "(" << data.x << "," << data.y << ")";
    return output;
}
template <typename T>
std::ostream& operator <<(std::ostream& output, const std::vector<T>& data)
{
    for (const T& x : data)
        output << x << " ";
    return output;
}
ll div_up(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll div_down(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down
ll math_mod(ll a, ll b) { return a - b * div_down(a, b); }
#define tcT template<class T
#define tcTU tcT, class U
tcT> using V = vector<T>;
tcT> void re(V<T>& x) {
    trav(a, x)
        cin >> a;
}
tcT> bool ckmin(T& a, const T& b) {
    return b < a ? a = b, 1 : 0;
} // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0;
}
ll gcd(ll a, ll b) {
    while (b) {
        tie(a, b) = mp(b, a % b);
    }
    return a;
}
signed main() {
    #ifdef LOCAL
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n;
    cin >> n;
    vi a(2 * n);
    cin >> a;
    vi sign(2 * n);
    V <ii> ord;
    FOR (i, 2 * n) {
        ord.app(mp(a[i], i));
    }
    sort(all(ord));
    FOR (i, n) {
        sign[ord[i].y] = -1;
    }
    FOR (i, n) {
        sign[ord[i + n].y] = 1;
    }
    string ans;
    vi S;
    trav (e, sign) {
        if (S.empty() || S.back() == e) {
            ans += '(';
            S.app(e);
        }
        else {
            ans += ')';
            S.pop_back();
        }
    }
    assert(S.empty());
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#pragma optimize("-O3")
#define int long long int
#define f first
#define s second
#define pb push_back
#define endl '\n'

const int N=4e5+5;
bool bl[N];
int arr[N];

vector<char>ans;

main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	vector<pair<int, int>>vec;
	for(int i=0; i<2*n; i++){
		int x;
		cin>>x;
		vec.pb({x, i});
	}
	sort(vec.begin(), vec.end());
	for(int i=0; i<n; i++){
		bl[vec[i].s]=1;
	}
	stack<int>st;
	ans.resize(2*n);

	for(int i=0; i<2*n; i++){
		if(!st.empty() && (bl[i]^bl[st.top()])==1){
			ans[i]=')';
			ans[st.top()]='(';
			st.pop();
		}
		else{
			st.push(i);
		}
	}
	for(auto u:ans){
		cout<<u;
	}

	return 0;
}


/*  -*- coding: utf-8 -*-
 *
 * f.cc: F - Construct a Palindrome
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 1000;
const int INF = 1 << 30;

/* typedef */

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

/* global variables */

vi nbrs[MAX_N][26];
int ds[MAX_N][MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < m; i++) {
    int u, v;
    char s[4];
    scanf("%d%d%s", &u, &v, s);
    u--, v--;
    int ci = s[0] - 'a';
    nbrs[u][ci].push_back(v);
    if (u != v) nbrs[v][ci].push_back(u);
  }

  memset(ds, -1, sizeof(ds));
  ds[0][n - 1] = 0;

  queue<pii> q;
  q.push(pii(0, n - 1));

  int mind = INF;
  while (! q.empty()) {
    pii u = q.front(); q.pop();
    int u0 = u.first, u1 = u.second;
    int vd = ds[u0][u1] + 1;

    for (int c = 0; c < 26; c++) {
      vi &nbr0 = nbrs[u0][c], &nbr1 = nbrs[u1][c];
      if (! nbr0.empty() && ! nbr1.empty())
	for (vi::iterator vit0 = nbr0.begin(); vit0 != nbr0.end(); vit0++)
	  for (vi::iterator vit1 = nbr1.begin(); vit1 != nbr1.end(); vit1++) {
	    int v0 = *vit0, v1 = *vit1;
	    if (v0 == v1)
	      mind = min(mind, vd * 2);
	    else if (v0 == u1 && v1 == u0)
	      mind = min(mind, vd * 2 - 1);
	    else {
	      if (v0 > v1) swap(v0, v1);
	      if (ds[v0][v1] < 0) {
		ds[v0][v1] = vd;
		q.push(pii(v0, v1));
	      }
	    }
	  }
    }
  }

  printf("%d\n", (mind >= INF) ? -1 : mind);
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

// using mint = long double;
// using mint = modint998244353;
// using mint = modint1000000007;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<ll, vector<ll>> Pd;

const ll INF = 2e18;
const ll fact_table = 1200008;

priority_queue<ll> pql;
priority_queue<P> pqp;
// big priority queue
// priority_queue <ll, vector<ll>, greater<ll> > pqls;
priority_queue<P, vector<P>, greater<P>> pqps;
// small priority queue
// top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
//↓,→,↑,←

/*
#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif
*/

#define p(x) cout << x << endl;
#define el cout << endl;
#define pe(x) cout << x << " ";
#define ps(x) cout << fixed << setprecision(25) << x << endl;
#define pu(x) cout << (x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = a; i <= (b); i++)
#define rep3(i, a, b) for (ll i = a; i >= (b); i--)
#define all(c) begin(c), end(c)

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

// vec v(n) -> 長さnのベクトルを宣言
// mat dp(h, vec(w)) -> h * w の行列を宣言

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

ll mypow(ll a, ll b, ll m = mod) {
    ll x = 1;
    while (b) {
        while (!(b & 1)) {
            (a *= a) %= m;
            b >>= 1;
        }
        (x *= a) %= m;
        b--;
    }
    return x;
}
vec rv(ll read) {
    vec res(read);
    for (int i = 0; i < read; i++) {
        cin >> res[i];
    }
    return res;
}

/*
ll fact[fact_table + 5], rfact[fact_table + 5];

void c3_init() {
    fact[0] = rfact[0] = 1;
    for (ll i = 1; i <= fact_table; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
    for (ll i = fact_table; i >= 1; i--) {
        rfact[i - 1] = rfact[i] * i;
        rfact[i - 1] %= mod;
    }
    return;
}
ll c3(ll n, ll r) {
    return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod;
}
*/
bool icpc = false;
bool multicase = false;

ll n, m;
vector<P> G[500005];
ll cost[1005][1005];

bool solve() {
    cin >> n >> m;
    rep(i, m) {
        ll a, b;
        char c;
        cin >> a >> b >> c;
        G[a].pb(P(b, c - 'a'));
        G[b].pb(P(a, c - 'a'));
    }

    queue<P> q;
    rep2(i, 1, n) {
        rep2(j, 1, n) {
            cost[i][j] = INF;
        }
    }
    q.push(P(1, n));
    cost[1][n] = 0;

    while (q.size()) {
        auto [vx, vy] = q.front();
        q.pop();

        for (auto [nvx, cx] : G[vx]) {
            for (auto [nvy, cy] : G[vy]) {
                if (cx != cy) continue;
                if (cost[nvx][nvy] != INF) continue;

                q.push(P(nvx, nvy));
                cost[nvx][nvy] = cost[vx][vy] + 1;
            }
        }
    }

    ll ans = INF;

    for (int i = 1; i <= n; i++) {
        ans = min(ans, 2 * cost[i][i]);
    }

    for (int i = 1; i <= n; i++) {
        for (auto [nv, c] : G[i]) {
            int a = i, b = nv;
            ans = min(ans, cost[a][b] + cost[b][a]);
        }
    }

    if (ans == INF) ans = -1;
    p(ans);
    return true;
}

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

    if (icpc) {
        while (solve())
            ;
        return 0;
    }
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        solve();
        testcase++;
    }

    // solve();
    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast","unroll-loops")
#define ll long long
#define ft first
#define sec second
#define pb push_back
#define pi pair<ll,ll>
using namespace std;
int n;
vector<pi> G[200005];
ll dp[200005][60][2],ans;
const int mod=1e9+7;
void dfs(int now,int fa)
{
	for(int i=0; i<60; i++) dp[now][i][0]=1;
	for(pi v:G[now]) if(v.ft!=fa)
	{
		dfs(v.ft,now);
		for(int i=0; i<60; i++)
		{
			int k=((v.sec&(1LL<<i))!=0);
			dp[now][i][0]+=dp[v.ft][i][k];
			dp[now][i][1]+=dp[v.ft][i][1^k];
		}
	}
}
void sol(int now,int fa)
{
	ll cnt[60][2]={0};
	for(pi v:G[now]) if(v.ft!=fa)
	{
		sol(v.ft,now);
		for(int i=0; i<60; i++)
		{
			int k=((v.sec&(1LL<<i))!=0);
			ll add=(1LL<<i)%mod;
			ans=(ans+dp[v.ft][i][1^k]*add%mod)%mod;
			ans=(ans+add*cnt[i][0]%mod*dp[v.ft][i][1^k]%mod)%mod;
			ans=(ans+add*cnt[i][1]%mod*dp[v.ft][i][k]%mod)%mod;
			cnt[i][0]+=dp[v.ft][i][k];
			cnt[i][1]+=dp[v.ft][i][1^k];
		}
	}
	//if(now==3) cout << ans <<'\n';

}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for(ll i=1,a,b,c; i<n; i++)
	{
		cin >> a >> b >> c;
		G[a].pb({b,c});
		G[b].pb({a,c});
	}
	dfs(1,1);
	sol(1,1);
	cout << ans;
	return 0;
}

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

#define nl '\n'

//----------------------------------- DEBUG -----------------------------------
#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__) << "] "
// debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }

//----------------------------------- END DEBUG --------------------------------

/*

(2, 3)
(4, 6)

2 < x < 3

x = 2.5 = 5

[3, 2]

*/

void run_cases() {
    int N;
    cin >> N;
    vector<vector<int64_t>> ranges(N);
    for(int i = 0; i < N; i++) {
        int64_t t, l, r;
        cin >> t >> l >> r;
        l *= 100;
        r *= 100;
        switch(t) {
            case 2:
                r--;
                break;
            case 3:
                l++;
                break;
            case 4:
                l++, r--;
                break;
        }
        ranges[i] = {l, r};
    }

    int ans = 0;

    auto intersect = [&](vector<int64_t> &a, vector<int64_t> &b) -> bool {
        vector<int64_t> common = {max(a[0], b[0]), min(a[1], b[1])};
        return common[0] <= common[1];
    };

    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N; j++) {
            ans += intersect(ranges[i], ranges[j]);
        }
    }

    cout << ans;
}

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

    int tests = 1;
    // cin >> tests;

    for(int test = 1;test <= tests;test++) {
        run_cases();
    }
}


#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

using vi = vector<int>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int H, W;
  cin >> H >> W;
  v(string) ss(H);
  cin >> ss;
  int re = 0;
  F0R(r, H) {
    F0R(c, W) {
      if (ss[r][c] == '#') continue;
      if (r < H - 1 && ss[r + 1][c] == '.') re++;
      if (c < W - 1 && ss[r][c + 1] == '.') re++;
    }
  }
  cout << re;
}
#endif

#include <bits/stdc++.h>

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < (n); i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 55, mod = 998244353;
int n, k, p[MX];
ll fac[MX], cn[MX], a[MX][MX], res = 1;

int parent (int a) {
	return a == p[a] ? a : p[a] = parent(p[a]);
}

void join (int a, int b) {
	p[parent(a)] = parent(b);
}

void solve () {
	iota(p, p + MX, 0);
	forn (y, n) forn (x, y) {
		int cn = 0;
		forn (i, n)
			if (a[i][x] + a[i][y] <= k)
				cn++;
		if (cn == n) join(x, y);
	}
	memset(cn, 0, sizeof(cn));
	forn (i, n) cn[parent(i)]++;
	forn (i, n) (res *= fac[cn[i]]) %= mod;
}

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

	fac[0] = 1;
	for (int i = 1; i < MX; i++) {
		fac[i] = i * fac[i - 1] % mod;
	}

	cin >> n >> k;
	forn (i, n) forn (j, n) cin >> a[i][j];

	solve();
	forn (i, n) forn (j, i) swap(a[i][j], a[j][i]);
	solve();

	cout << res << endl;

	return 0;
}


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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()

typedef long long ll;

#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)

#define fi first
#define se second

const int N = 25;
vector<int> g[N];

int ne, nv;
int ja_comp[N];
int cor[N];

vector<int> vno;
int ant[N];

void dfscnt(int no,int from){
	if(ja_comp[no]) return;
	ant[no] = from;
	ja_comp[no] = 1;
	vno.push_back(no);
	nv++;
	ne+=sz(g[no]);
	for(auto &it : g[no]) dfscnt(it,no);
}

/*
void dfs(int no){
	if(vis[no]) return;
	vis[no] = 1;
	na++;
	fr(c,3){
		int bad = 0;
		for(auto &it : g[no]){
			if(vis[it] and cor[it]==c){
				bad = 1;
				break;
			}
		}
		if(bad) continue;
		if(na==nv){
			ways++;
		} else{

		}
	}
	na--;
	vis[no] = 0;
}
*/

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n, m; cin >> n >> m;
	fr(mm,m){
		int a, b; cin >> a >> b;
		a--,b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	ll ans = 1;

	int ctc[3][2] = {{1,2},{0,2},{0,1}};
	fr(noo,n){
		if(!ja_comp[noo]){
			nv = 0, ne = 0;
			vno.clear();
			dfscnt(noo,-1);
			//prin(noo);
			//prin(nv);
			//prinv(vno);
			/*
			if(2*nv-2==ne){
				ll cur = 3;
				fr(i,nv-1) cur*=2;
				ans*=cur;
			} else{
				na = 0;
				dfs(i);
				ans*=ways;
			}
			*/
			ll cur = 0;
			fr(c1,3){
				cor[vno[0]] = c1;
				fr(mask,1<<(nv-1)){
					//prin(mask);
					fr(i,nv-1){
						int cc = cor[ant[vno[i+1]]];
						if(mask&(1<<i)){
							cor[vno[i+1]] = ctc[cc][0];
						} else{
							cor[vno[i+1]] = ctc[cc][1];
						}
					}
					int ok = 1;
					for(auto &no : vno){
						for(auto &it : g[no]){
							if(cor[it]==cor[no]){
								ok = 0;
								goto sai;
							}
						}
					}
					sai:
					if(ok) cur++;
				}
			}
			ans*=cur;
		}
	}

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

#include <bits/stdc++.h>

using namespace std;

/*
    VERIFICAR:
    - Corner cases
    - Estouro de variavel
    - Acesso indevido de memoria

    MODULO NEGATIVO
    int modulo(int x,int N){
        return (x % N + N) %N;
    }

*/

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second
#define pb push_back

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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

struct info {
    bool c1;
    bool c2;
    bool c3;
};

int n;
vector<vector<int> > g;
vector<int> cores;
ll cont = 0;
vector<int> analisado;
vector<info> opt;

void solve(int at1) {
    if(at1 == analisado.size()) {
        cont++;
        return;
    }
    int at = analisado[at1];
    bool cor1 = opt[at].c1;
    bool cor2 = opt[at].c2;
    bool cor3 = opt[at].c3;
    if(!cor1) {
        cores[at] = 0;
        vector<info> old = opt;
        for(int viz : g[at]) {
            opt[viz].c1 = true;
        }
        solve(at1+1);
        opt = old;
        cores[at] = -1;
    }
    if(!cor2) {
        cores[at] = 1;
        vector<info> old = opt;
        for(int viz : g[at]) {
            opt[viz].c2 = true;
        }
        solve(at1+1);
        opt = old;
        cores[at] = -1;
    }
    if(!cor3) {
        cores[at] = 2;
        vector<info> old = opt;
        for(int viz : g[at]) {
            opt[viz].c3 = true;
        }
        solve(at1+1);
        opt = old;
        cores[at] = -1;
    }
}

vector<bool> vis;

void dfs(int at, int pai) {
    if(vis[at]) {
        return;
    }
    vis[at] = true;
    for(int viz: g[at]) {
        if(viz != pai) {
            dfs(viz, at);
        }
    }
}

int main() {_
    int m;
    cin >> n >> m;
    g.resize(n);
    int a, b;
    for(int I=0; I<m; I++) {
        cin >> a >> b;
        a--; b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    vector<bool> visAq(n, false);
    vector<vector<int> > componentes;
    for(int I=0; I<n; I++) {
        if(!visAq[I]) {
            vis.clear();
            vis.resize(n);
            dfs(I, -1);
            vector<int> componente;
            for(int J=0; J<n; J++) {
                if(vis[J]) {
                    visAq[J] = true;
                    componente.pb(J);
                }
            }
            componentes.pb(componente);
        }
    }
    ll resp = 1;
    cores.resize(n, -1);
    opt.resize(n);
    for(vector<int> v : componentes) {
        if(v.size() == 1) {
            resp*=3;
        } else {
            cont = 0;
            analisado = v;
            solve(0);
            resp*=cont;
        }
        if(resp == 0) {
            break;
        }
    }
    cout << resp << endl;
	return 0;
}


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

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

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

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

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

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

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

string solve(string s){
    string t = "";
    rep0(i, s.size()){
        if(s[i] == s[i + 1]){
            t.push_back(s[i]);
        }else if(s[i] + s[i + 1] == 163){
            t.push_back('S');
        }else if(s[i] + s[i + 1] == 165){
            t.push_back('R');
        }else t.push_back('P');
        ++i;
    }
    s = t;
    return s;
}

//modの値の確認をすること
int main(){
    ll n,k;
    string s;
    cin >> n >> k >> s;
    rep0(i, k)s = solve(s + s);
    pf(s[0]);
    return 0;
}

#include <map>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define int long long
#define mp make_pair
const int mod = 998244353;
int read () {
	int x = 0, f = 1;
	char ch = getchar ();
	while (ch < '0' || ch > '9') {
		if (ch == '-') f = -1;
		ch = getchar ();
	}
	while (ch >= '0' && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar ();
	}
	return x * f;
}
void write (int x) {
	if (x < 0) x = -x, putchar ('-');
	if (x >= 10) write (x / 10);
	putchar (x % 10 + '0');
}
int quickmod (int x, int y) {
	int Ans = 1;
	while (y) {
		if (y & 1) Ans = (Ans * x) % mod;
		x = (x * x) % mod;
		y >>= 1;
	}
	return Ans;
}
int a[200005], b[200005], sum[200005];
int fac[200005], inv[200005];
signed main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	fac[0] = 1;
	for (int i = 1; i <= 200000; i++) fac[i] = (fac[i-1] * i) % mod;
	for (int i = 0; i <= 200000; i++) inv[i] = quickmod (fac[i], mod - 2);
	int n = read (), m = read (), k = read ();
	if (n == 1 && m == 1) return printf ("%lld", k) & 0;
	if (n == 1) return printf ("%lld", quickmod (k, m)) & 0;
	if (m == 1) return printf ("%lld", quickmod (k, n)) & 0;
	for (int i = 1; i <= k; i++) {
		a[i] = quickmod (i, n);
	}//所有行最大值不超过 i 时方案总数
	for (int i = 1; i <= k; i++) {
		b[i] = quickmod (k - i + 1, m);
	}//所有列最小值不小于 i 时方案总数
	for (int i = k; i >= 1; i--) {
		a[i] = (a[i] - a[i-1] + mod) % mod;
	}
	for (int i = 1; i <= k; i++) {
		b[i] = (b[i] - b[i+1] + mod) % mod;
	}
//	for (int i = 1; i <= k; i++) printf ("[%lld %lld]\n", a[i], b[i]);
	for (int i = 1; i <= k; i++) sum[i] = (sum[i-1] + a[i]) % mod;
//	printf ("\n");
	int Ans = 0;
	for (int i = 1; i <= k; i++) {
		Ans = (Ans + (b[i] * sum[i])) % mod;
//		for (int j = 1; j <= i; j++) {
//			Ans = (Ans + (b[i] * a[j])) % mod;
//		}
	}
	printf ("%lld", Ans);
	return 0;
}
/*
*/


#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

int main(){
  ll n;
  cin>>n;
  map<string,ll> ma;
  rep(i,0,n){
    string s;
    cin>>s;
    string s1;
    if(s[0]=='!'){
      rep(j,1,s.sz){
        s1 += ctos(s[j]);
      }
      ma[s1] |= 2;
    }
    else{
      ma[s] |= 1;
    }
  }
  map<string,ll>::iterator itr = ma.begin();
  while(itr!=ma.end()){
    string a = (*itr).fi;
    ll b = (*itr).se;
    if(b==3){
      cout << a << endl;
      return 0;
    }
    itr++;
  }
  cout << "satisfiable" << endl;
  return 0;
}

#include <bits/stdc++.h>

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

    int64_t n;
    std::cin >> n;
    for (int64_t a = 1, p = 3; p <= n; ++a, p *= 3) {
        for (int64_t b = 1, q = 5; q <= n; ++b, q *= 5) {
            if (p + q == n) {
                std::cout << a << " " << b << "\n";
                return 0;
            }
        }
    }
    std::cout << -1 << "\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const long long N = 1e5 + 5, INF = 1e17 + 5;

long long n, m, a, b, c, d, dist[N];

bool vis[N];

struct Edge{
    long long b, c, d;
};

vector<Edge> graph[N];

long double findtime(long long t, long long wait, Edge e){
    return wait + e.c + ((e.d / (long double)(t + 1 + wait)));
}

long long findwait(long long t, Edge e){
    long long l = 0, r = INF, m1, m2;
    long double m1ans, m2ans;

    while(r - l > 2){
        m1 = l + (r - l) / 3;
        m2 = r - (r - l) / 3;

        m1ans = findtime(t, m1, e);
        m2ans = findtime(t, m2, e);

        if(m1ans <= m2ans) r = m2;
        else l = m1;
    }

    vector<pair<long double, long long>> v;

    for(long long i = l; i <= r; i++){
        v.push_back({findtime(t, i, e), i});
    }

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

    return v.front().second;
}

void dijkstra(){
    for(int i = 1; i <= n; i++) dist[i] = INF;

    priority_queue<pair<long long, long long>> pq;

    dist[1] = 0;

    pq.push({0, 1});

    long long v;

    while(!pq.empty()){
        v = pq.top().second, pq.pop();

        if(!vis[v]){
            vis[v] = true;

            for(auto e : graph[v]){
                if(!vis[e.b]){
                    long long waitt = findwait(dist[v], e);
                    long long edget = findtime(dist[v], waitt, e);

                    if(dist[v] + edget < dist[e.b]){
                        dist[e.b] = dist[v] + edget;
                        pq.push({-dist[e.b], e.b});
                    }
                }
            }
        }
    }
}

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

    cin >> n >> m;

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

        graph[a].push_back({b, c, d});
        graph[b].push_back({a, c, d});
    }

    dijkstra();

    cout << (dist[n] == INF ? -1 : dist[n]);
}

//================code===================//

//#define TLE

#ifdef TLE
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#endif

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <ctime>
#include <random>
#include <chrono>
//#include <stdint.h>

#define ci(t) cin>>t
#define co(t) cout<<t
#define LL long long
#define ld long double
#define fa(i,a,b) for(LL i=(a);i<(LL)(b);++i)
#define fd(i,a,b) for(LL i=(a);i>(LL)(b);--i)
#define setp pair<int,ld>
#define setl pair<LL,LL>

#define micro 0.000000000001

using namespace std;

LL gcd(LL a, LL b)
{
	if (!(a && b)) return max(a, b);
	return a % b ? gcd(b, a % b) : b;
}

#ifdef OHSOLUTION
#define ce(t) cerr<<t
#define AT cerr << "\n=================ANS=================\n"
#define AE cerr << "\n=====================================\n"
#define DB(a) cerr << __LINE__ << ": " << #a << " = " << (a) << endl;
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#define LLL LL
#else
#define AT
#define AE
#define ce(t)
#define LLL __int128
#endif

pair <int, int> vu[9] = { {0,1},{1,0},{0,-1} ,{-1,0},{-1,0},{-1,-1}, {0,-1} , {1,-1},{-1,-1} }; //RDLU EWSN

template<typename T, typename U> void ckmax(T& a, U b) { a = a < b ? b : a; }
template<typename T, typename U> void ckmin(T& a, U b) { a = a > b ? b : a; }
struct gcmp { bool operator()(LL a, LL b) { return a < b; } bool operator()(setl& a, setl& b) { return a.second < b.second; } };
struct lcmp { bool operator()(LL a, LL b) { return a > b; } bool operator()(setl& a, setl& b) { return a.second > b.second; } };

const int max_v = 1e5+ 7;
const int max_k = 5e2 + 7;
const int bsz = (1ll << 10) + 7;
const int INF = 1e9 + 7;
const LL LNF = (LL)5e18 + 7ll;
LL mod =  998244353;//1e9 + 7;
template<typename T, typename U> void MOD(T& a, U b) { a += b; if (a >= mod) a -= mod; };

struct node
{
	int nxt;
	int c, d;
};

vector<node> adj[max_v];

int main()
{
#ifdef OHSOLUTION
	freopen("input.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int v, e; ci(v >> e);

	fa(i, 0, e)
	{
		int a, b, c, d; ci(a >> b >> c >> d); --a, --b;
		adj[a].push_back({ b,c,d });
		adj[b].push_back({ a,c,d });
	}

	vector<LL> dist(v, LNF);
	vector<bool> vist(v, 0);
	dist[0] = 0;
	priority_queue<setl, vector<setl>, lcmp> pq;
	pq.push({0,0});

	while (pq.size())
	{
		setl u;
		do
		{
			u = pq.top(); pq.pop();
		} while (pq.size() && vist[u.first]);

		if (vist[u.first]) break;

		vist[u.first] = 1;

		for (auto& v : adj[u.first])
		{
			LL base = dist[u.first]+1;
			LL l = 0;
			LL r = 1e9 + 7;

			if (base > v.d)
			{
				if (dist[v.nxt] > dist[u.first] + l + v.c + v.d / (dist[u.first] + l + 1))
				{
					dist[v.nxt] = dist[u.first] + l + v.c + v.d / (dist[u.first] + l + 1);
					pq.push({ v.nxt,dist[v.nxt] });
				}

			}
			else
			{
				while (l < r)
				{
					LL mid = l + r >> 1;

					if ((mid + base) * (mid + base) >= v.d) r = mid;
					else l = mid + 1;
				}

				if (dist[v.nxt] > dist[u.first] + l + v.c + v.d / (dist[u.first] + l + 1))
				{
					dist[v.nxt] = dist[u.first] + l + v.c + v.d / (dist[u.first] + l + 1);
					pq.push({ v.nxt,dist[v.nxt] });
				}

				++l;

				if (dist[v.nxt] > dist[u.first] + l + v.c + v.d / (dist[u.first] + l + 1))
				{
					dist[v.nxt] = dist[u.first] + l + v.c + v.d / (dist[u.first] + l + 1);
					pq.push({ v.nxt,dist[v.nxt] });
				}

				if (l > 1)
				{
					l -= 2;
					if (dist[v.nxt] > dist[u.first] + l + v.c + v.d / (dist[u.first] + l + 1))
					{
						dist[v.nxt] = dist[u.first] + l + v.c + v.d / (dist[u.first] + l + 1);
						pq.push({ v.nxt,dist[v.nxt] });
					}
				}

			}
		}
	}

	dist[v - 1] == LNF ? co(-1) : co(dist[v - 1]);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vl vector<ll>

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

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}

int n, q;
Graph G;
vi depth;
vl val;

void DepthDFS(int now, int d)
{
    depth[now] = d;
    for(int next: G[now]) {
        if(depth[next] == -1) {
            DepthDFS(next, d + 1);
        }
    }
}
void SumDFS(int now, ll weight)
{
    weight += val[now];
    val[now] = weight;
    for(int next: G[now]) {
        if(depth[next] > depth[now]) {
            SumDFS(next, weight);
        }
    }
}

int main()
{
    cin >> n;
    vi A(n - 1);
    vi B(n - 1);
    G.resize(n);
    depth.resize(n, -1);
    val.resize(n, 0);
    rep(i, n - 1) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);
    }

    DepthDFS(0, 0);

    cin >> q;

    rep(i, q) {
        int t, e, x;
        cin >> t >> e >> x;
        e--;
        int a = A[e];
        int b = B[e];
        if(t == 2) swap(a, b);
        if(depth[a] > depth[b]) {
            val[a] += x;
        } else {
            val[0] += x;
            val[b] -= x;
        }
    }

    SumDFS(0, 0);
    rep(i, n) cout << val[i] << endl;

}

#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
#define endl "\n"
int N;
long long Ans[200005];
vector<int>to[200005];
class Tree {
public:
	Tree(int V, int root) : V(V), root(root) {
		T.resize(V);
		for (int i = 0; i < MAXLOGV; i++) parent[i].resize(V);
		depth.resize(V);
	}
	// uとvをつなぐ
	// lcaを求めることが主目的なので無向グラフとしている
	void unite(int u, int v) {
		T[u].push_back(v);
		T[v].push_back(u);
	}
	// initする
	// コンストラクタだけじゃなくてこれも呼ばないとlcaが求められないぞ
	void init() {
		dfs(root, -1, 0);
		for (int k = 0; k + 1 < MAXLOGV; k++) {
			for (int v = 0; v < V; v++) {
				if (parent[k][v] < 0) parent[k + 1][v] = -1;
				else parent[k + 1][v] = parent[k][parent[k][v]];
			}
		}
	}
	// uとvのlcaを求める
	int lca(int u, int v) const {
		if (depth[u] > depth[v]) swap(u, v);
		for (int k = 0; k < MAXLOGV; k++) {
			if ((depth[v] - depth[u]) >> k & 1) {
				v = parent[k][v];
			}
		}
		if (u == v) return u;
		for (int k = MAXLOGV - 1; k >= 0; k--) {
			if (parent[k][u] != parent[k][v]) {
				u = parent[k][u];
				v = parent[k][v];
			}
		}
		return parent[0][u];
	}
	// uとvの距離を求める
	// edgeを定義しないといけない時はこれじゃダメ
	int dist(int u, int v) const {
		int p = lca(u, v);
		return (depth[u] - depth[p]) + (depth[v] - depth[p]);
	}
	void dfs(int v, int p, int d) {
		parent[0][v] = p;
		depth[v] = d;
		for (int next : T[v]) {
			if (next != p) dfs(next, v, d + 1);
		}
	}
	static const int MAXLOGV = 25;
	// グラフの隣接リスト表現
	vector<vector<int> > T;
	// 頂点の数
	int V;
	// 根ノードの番号
	int root;

	// 親ノード
	vector<int> parent[MAXLOGV];
	// 根からの深さ
	vector<int> depth;
};

void dfs(int v, int p = -1) {
	if (-1 != p) {
		Ans[v] +=Ans[p];
	}
	for (int i = 0; i < to[v].size(); ++i) {
		if (p == to[v][i]) {
			continue;
		}
		dfs(to[v][i], v);
	}
	return;
}

int main() {
	cin >> N;
	vector<int>A(N);
	vector<int>B(N);
	Tree tree(N, 0);
	for (int i = 0; i < N - 1; ++i) {
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
		to[A[i]].push_back(B[i]);
		to[B[i]].push_back(A[i]);
		tree.unite(A[i], B[i]);
	}
 	tree.init();
	int Q;
	cin >> Q;
	for (int i = 0; i < Q; ++i) {
		int t, e, x;
		cin >> t >> e >> x;
		e--;
		if (1 == t) {
			if (tree.depth[B[e]] < tree.depth[A[e]]) {
				Ans[A[e]] += x;
			}
			else {
				Ans[B[e]] -= x;
				Ans[0] += x;
			}
		}
		else {
			if (tree.depth[A[e]] < tree.depth[B[e]]) {
				Ans[B[e]] += x;
			}
			else {
				Ans[A[e]] -= x;
				Ans[0] += x;
			}
		}
	}
	dfs(0);
	for (int i = 0; i < N; ++i) {
		cout << Ans[i] << endl;
	}
	return 0;
}


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

int main(){
  int  M ,H;
  cin >> M >> H;
  if(H%M==0){
    cout << "Yes";
  }else{
    cout << "No";
  }
}

#include <iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<functional>
#include <iomanip>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define  DESC std::greater<int>() //sort 3rd arg

int main() {
    int x, y;
    cin >> x >> y;

    if (x > y) {
        swap(x, y);
    }

    if (x + 3 > y) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iostream>
#include<iomanip>
#include<map>
#include<numeric>
#include<optional>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<tuple>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#pragma GCC optimize("Ofast")
namespace gengar
{
	using namespace std;
	#define int long long
	#define itn int
	#define uint unsigned long long
	#define ld long double
	#define vt(tp) vector<tp>
	#define vvt(tp) vector<vector<tp>>
	#define vvt2(nm,tp,h,w,n) vector<vector<tp>>nm((h),vector<tp>(w,n))
	#define P pair<int,int>
	#define hmap unordered_map
	#define hset unordered_set
	#define all(x) x.begin(),x.end()
	#define nsort(x) sort(all(x))
	#define rsort(x) nsort(x);reverse(all(x))
	#define unq(v) v.erase(unique(all(v)),v.end())
	#define l_b(c,x) distance(c.begin(),lower_bound(all(c),(x)))
	#define u_b(c,x) distance(c.begin(),upper_bound(all(c),(x)))
	#define fi first
	#define se second
	#define mp make_pair
	#define pb push_back
	#define eb emplace_back
	#define spc ' '
	#define pass
	#define _overload3(_1,_2,_3,name,...) name
	#define _rep(i,n) repi(i,0,n)
	#define repi(i,a,b) for(int i=(a),__SIZE##_=(b);i<__SIZE##_;i++)
	#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
	#define _daolrevo3(_1,_2,_3,name,...) name
	#define _per(i,n) peri(i,n,0)
	#define peri(i,a,b) for(int i=(a),__SIZE##_=(b);i>=__SIZE##_;i--)
	#define per(...) _daolrevo3(__VA_ARGS__,peri,_per,)(__VA_ARGS__)
	#define Bit(n) (1LL<<(n))
	#define myceil(a,b) ((a)+((b)-1))/(b)
	#define scale(n) cout<<fixed<<setprecision(n)
	using i64=int64_t;
	using u64=uint64_t;
	template<class T>using PQ=priority_queue<T,vt(T),greater<T>>;
	void in(){}
	template<class Car,class...Cdr>
	void in(Car&&car,Cdr&&...cdr){cin>>car;in(forward<Cdr>(cdr)...);}
	template<class T>void drop(T x){cout<<(x)<<endl;exit(0);}
	void dYes(){puts("Yes");exit(0);}
	void dNo(){puts("No");exit(0);}
	int gcd(int a,int b){return b?gcd(b,a%b):a;}
	int lcm(int a,int b){return a/gcd(a,b)*b;}
	int fact(int n,int m){int f=n;for(int i=n-1;i>=1;i--){f*=i;f%=m;}return f;}
	template<class T>int chmin(T&a,const T&b){if(b<a){a=b;return 1;}return 0;}
	template<class T>int chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
	const int inf=Bit(60);
	const double pi=acos(-1);
	const int mod=1000000007;//998244353
};
using namespace gengar;

int rui[100010],rui2[100010];
int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;in(n,m);
	vector<int>h(n),w(m);
	rep(i,n)cin>>h[i];
	rep(i,m)cin>>w[i];
	sort(all(h));
	for(int i=0;i<n-1;i+=2)rui[i/2+1]=rui[i/2]+h[i+1]-h[i];
	for(int i=n-2;i>0;i-=2)rui2[i/2]=rui2[i/2+1]+h[i+1]-h[i];
	int ans=inf;
	for(auto p:w)
	{
		int x=l_b(h,p);
		if(x%2)x--;
		chmin(ans,rui[x/2]+rui2[x/2]+abs(h[x]-p));
	}
	cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define pf push_front
#define pipii pair<int,pair<int,int>>
#define pii pair<int,int>
#define mod 1000000007
#define ss second
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int>>
#define ff first
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend();
#define ld long double
#define inf (int)1e9+7
#define sp fixed<<setprecision(12)
using namespace std;

// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

int dx[]={0,0,-1,1};
int dy[]={-1,1,0,0};
char charr[]={'L','R','U','D'};

void solve(int tc){
    //cout<<"Case #"<<tc<<": ";

    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=INT_MAX;
    for(int i=0;i<(1ll<<n);i++){
        vector<int> v;
        int orr=0;
        for(int j=0;j<n;j++){
            if((1ll<<j)&i){
                orr|=a[j];
                v.pb(orr);
                orr=0;
            }else{
                orr|=a[j];
            }
        }
        if(orr>0){
            v.pb(orr);
        }
        int xorr=0;
        for(int x:v){
            xorr^=x;
        }
        ans=min(ans,xorr);
    }
    cout<<ans;

}

int32_t main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    //double    pi=3.14159265358979323846;
    //precompute();
    int t=1;
    //cin>>t;
    int tc=1;
    while(t--){
        solve(tc);
        tc++;

    }

    return 0;

}//Ardhendu Reja , JGEC

/*
int powmod(int x,int n,int p)
{
    int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%p;
        x=(x*x)%p;
        n=n/2;
    }
    return result;
}

int modmul(int a,int b) {
    return ((a % mod) * (b % mod)) % mod;
}
*/


//Never stop trying
#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef long long ll;
#define int ll
typedef string str;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)

const int MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const int MX = 2e5 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up

template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
//constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
ll random(ll a, ll b){
    return a + rng() % (b - a + 1);
}
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define dbg(x) cerr << #x << " : " << x << endl;
#define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;

void IO() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
/////////////////////////ONLY CLEAN CODES ALLOWED/////////////////////////

int32_t main() {
    boost; IO();

    int N; cin>>N;
    vi a(N);
    FOR(i,0,N) cin>>a[i];

    int ans=INF;
    FOR(m,0,(1<<N)){
    	if( !((m>>(N-1))&1) ) continue;
    	int cur=0;
    	vi vec;
    	FOR(i,0,N){
    		cur|=a[i];
    		if((m>>i)&1){
    			vec.pb(cur);
    			cur=0;
    		}
		}

		int v=0;
		for(auto x: vec) v^=x;
		ckmin(ans,v);
    }
    cout << ans << endl;

    return 0;
}
//Change your approach

#include<bits/stdc++.h>
using namespace std;
#define dd double
#define ll long long int
#define light ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mkp make_pair
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define fi first
#define sc second
ll INF=2*1e9+5;
ll mod=998244353;
ll ans=INF,n;

void calc(vector<ll>&a , ll i,ll ro){
    if(i==n-1){
        ans = min(ans,ro);
        return;
    }
    ll rox=a[i+1];
    for (ll j = i+1; j <n ; ++j){
        calc(a,j,ro^rox);
        if(j<n-1)
            rox |= a[j+1];
    }
}

void solve(){
    cin>>n;
    vector<ll>a(n);
    for(auto &ele:a){
        cin>>ele;
    }
    ans=INF;
    ll i,rox=a[0];
    for(i=0;i<n;i++){
        calc(a,i,rox);
        if(i<n-1)
            rox |= a[i+1];
    }
    cout<<ans<<"\n";
}

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

    light;
    ll t;
    //cin>>t;
    t=1;
    while(t--){
        solve();
    }
}


/* BABA JAGAAAAAA  */

#include<bits/stdc++.h>
#define pb push_back
#define un unordered_map
#define us unordered_set
#define ll long long
#define PI 3.1415926535897932384626
#define fast ios:: sync_with_stdio(false);cin.tie(NULL)
#define l long
using namespace std;
const int  mod= 1e9+7;
const int inf=1e9+3;
 int main()
 {
     fast;
    int x;
     cin>>x;
      if(x>=0)
      cout<<x<<"\n";
      else
      cout<<0<<"\n";
       return 0;

 }

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
#define all(x) (x).begin(),(x).end()
#define fr first
#define sc second
#define nl '\n'

void solve(){

    int x;cin>>x;
    cout<<max(x,0);
}

int main(){

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

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

return 0;
}