#include<bits/stdc++.h>
#define ffr(i,a,b) for(i=a;i<b;i++)
#define ffrr(i,a,b) for(i=a;i<=b;i++)
#define ll long long int
#define pf printf
#define mp make_pair
#define mm(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define MMAX 200005

using namespace std;

int minn(int a, int b)
{
    if(a<b) return a; return b;
}

int main(){
    ll n, i, j, sum=0, ans=0, a, b, c, MOD=200003, sz, num, cur;
    string s;
    map< pair<ll,ll>, ll > mpp; mpp.clear();
    cin >> n;
    ffr(j,0,n){
        cin >> s;
        i=0; sz=s.size(); num=0;

        while(i<sz && s[i]!='.'){
            cur = s[i]-'0';
            num*=10; num+=cur;
            i++;
        }
        i++;
        a=b=c=0;
        while(i<sz){
            cur = s[i]-'0';
            num*=10; num+=cur;
            i++;
            c++;
        }
        while(1){
            if(num&1) break;
            else{
                num>>=1;
                a++;
            }
        }
        while(1){
            if(num%5>0) break;
            else{
                num/=5;
                b++;
            }
        }
        mpp[mp(a-c,b-c)]++;
    }
    for(auto i:mpp){
        //if(i.first.first<0) continue;
        for(auto j:mpp){
            //if(j.first.first>0) continue;
            if(i==j) continue;
            if(i.first.first+j.first.first>=0 && i.first.second+j.first.second>=0) ans+=(i.second*j.second);
        }
        if(i.first.first>=0 && i.first.second>=0)
        {
            cur = i.second;
            ans+= (cur*cur-cur);
        }
    }

    cout << ans/2 << endl;
}

#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
struct UnionFind {
    vector<int> par, siz;
    UnionFind(int n) {
        par.resize(n);
        siz.resize(n, 1);
        for(int i = 0; i < n; i++)
            par[i] = i;
    }
    int find(int x) {
        if(par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    bool unite(int u, int v) {
        u = find(u), v = find(v);
        if(u == v)
            return false;
        if(siz[u] < siz[v])
            swap(u, v);
        par[v] = u;
        siz[u] += siz[v];
        return true;
    }
    bool same(int u, int v) { return find(u) == find(v); }
};
struct edge {
    ll u, v, cost;
    bool operator<(const edge& e) { return cost < e.cost; }
};
ll d;
vector<ll> a;
vector<edge> es;
void calc(int l, int r) {
    if(r - l <= 1) {
        return;
    }
    int m = (l + r) / 2;
    ll mi = LINF, s, t;
    for(ll i = l; i < m; i++) {
        ll k = -i * d + a[i];
        if(mi > k) {
            mi = k;
            s = i;
        }
    }
    mi = LINF;
    for(ll i = m; i < r; i++) {
        ll k = i * d + a[i];
        if(mi > k) {
            mi = k;
            t = i;
        }
    }
    for(ll i = l; i < m; i++) {
        es.push_back({i, t, (t - i) * d + a[t] + a[i]});
    }
    for(ll i = m; i < r; i++) {
        es.push_back({s, i, (i - s) * d + a[i] + a[s]});
    }
    calc(l, m);
    calc(m, r);
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n >> d;
    a.resize(n + 1);
    for(ll i = 1; i <= n; i++) {
        cin >> a[i];
    }
    calc(1, n + 1);
    UnionFind uf(n + 1);
    sort(all(es));
    ll ans = 0;
    for(auto e : es) {
        if(uf.unite(e.u, e.v)) {
            ans += e.cost;
        }
    }
    cout << ans << endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

#define LEN 1000000

char str[LEN];
int cnt[LEN];

int main() {
	char ch;
	int s = -1, ans = 0;

	while (cin >> ch) {
		if (str[s] != ch) {
			s++;
		}
		str[s] = ch;
		cnt[s]++;
	}

	for (int i = 0; i + 2 <= s; ++i) {
		if (str[i] == 'J' && str[i + 1] == 'O' && str[i + 2] == 'I') {
			if (cnt[i + 1] <= cnt[i] && cnt[i + 1] <= cnt[i + 2]) {
				ans = max(ans, cnt[i + 1]);
			}
		}
	}

	cout << ans << endl;

	return 0;
}

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
using namespace std;
#define MAX 1000000010

int solve(string str){
	int a[3] = {0, 0, 0}, ans = 0;
	for(int i = 0;i < str.size();i++){
		if(str[i] == 'J'){
			if(a[1] || a[2])a[0] = a[1] = a[2] = 0;
			if(!a[1] && !a[2])a[0]++;
		}else if(a[0] && str[i] == 'O'){
			if(!a[2])a[1]++;
			else a[0] = a[1] = a[2] = 0;
		}else if(a[0] && a[1] && a[0] >= a[1] && str[i] == 'I'){
			a[2]++;
			if(a[1] == a[2])ans = max(a[1], ans);
		}else{
			a[0] = a[1] = a[2] = 0;
		}
	}
	return ans;
}

int main(){
	string str;
	cin >> str;
	cout << solve(str) << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
int main(){
  ll n; cin>>n;
  ll a[n]={};
  ll b[65]={};
  rep(i,n){
    cin>>a[i];}
  ll ans = 0;
  rep(i,n){
    bitset<61> s(a[i]);
    rep(j,61){
      if(s.test(j))b[j]++;}
  }
  ll k = 1;
  rep(i,61){
    ll m = b[i]*(n-b[i]);
    m%=MOD;
    ans += m*k;
    k*=2;
    k%=MOD;
  ans%=MOD;}
  cout << ans << endl;}

#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
using P = pair<int, int>;

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

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

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

int main()
{
    ll mod = TEN(9) + 7;
    int n;
    cin >> n;
    vector<ll> a(n, 0);
    ll a_max = 0;

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

    ll y = 1; int log_a_max = 0;
    while (y < a_max) {
        y *= 2;
        log_a_max++;
    }

    vector<vector<bool>> p(n, vector<bool>(log_a_max, 0));
    vector<int> s(log_a_max, 0);
    for (int i = 0; i < n; i++) {
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < log_a_max; j++) {
            s[j] += (a[i] >> j) & 1;
        }
    }

    ll sum = 0;
    ll x = 1;
    for (int j = 0; j < log_a_max; j++) {
        for (int i = 0; i < n; i++) {
            if (a[i] >> j & 1) {
                sum += x * (n - s[j]);
            } else {
                sum += x * s[j];
            }
            sum %= mod;
        }
        x *= 2;
        x %= mod;
    }
    cout << sum * ((mod + 1) / 2) % mod << endl;
    return 0;
}


#include <iostream>
using namespace std;

const int BASE = 6200;
int N, mod;
int dp[6009][12409][3];
long long ret[12409];

void solve(int p1, int p2) {
	// 最大値を更新する場合
	for (int i = 0; i <= 2; i++) {
		int r = 0;
		if (i == 0) r = -1;
		if (i == 1) r = 1;
		dp[p1][p2][0] += 1LL * dp[p1 - 1][p2 - r][i] % mod;
		if (dp[p1][p2][0] >= mod) dp[p1][p2][0] -= mod;
	}

	// 最大値を更新しない場合
	for (int i = 1; i <= 2; i++) {
		dp[p1][p2][i] += 1LL * (p1 - 1LL) * dp[p1 - 1][p2][i - 1] % mod;
		if (dp[p1][p2][i] >= mod) dp[p1][p2][i] -= mod;
	}
}

int main() {
	cin >> N >> mod;
	dp[1][BASE][0] = 1;

	for (int i = 2; i <= 3 * N; i++) {
		for (int j = 1; j <= BASE * 2 - 1; j++) {
			solve(i, j);
		}
	}

	for (int i = 1; i <= BASE * 2 - 1; i++) {
		for (int j = 0; j <= 2; j++) {
			int r = 0;
			if (j == 0) r = -1;
			if (j == 1) r = 1;
			ret[i + r] += dp[3 * N][i][j];
		}
	}

	long long Answer = 0;
	for (int i = 0; i <= BASE; i++) Answer += ret[i];
	cout << Answer % mod << endl;
	return 0;
}

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

const int MAX = 7000;

// fac[]・・・a! finv[]・・・(a!)^(-1) inv[]・・・a^(-1)

long long N, M, ans, fac[MAX], finv[MAX], inv[MAX], two[MAX], six[MAX];

void pre_comb(void){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	two[0] = 1; two[1] = 2;
	six[0] = 1; six[1] = 6;
	for(int i=2; i<MAX; i++){
		fac[i] = fac[i-1] * i % M;
		inv[i] = M - inv[M % i] * (M/i) % M;
		finv[i] = finv[i-1] * inv[i] % M;
		two[i] = two[i-1] * 2 % M;
		six[i] = six[i-1] * 6 % M;
	}
}

long long comb(int n, int k){
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n-k] % M) % M;
}

long long mpow(long long n, long long r){
	if(r == 1) return n;
	if(r % 2 == 1) return n * mpow(n, r-1) % M;
	else{
		long long a = mpow(n, r/2);
		return a * a % M;
	}
}

long long inve(long long n){
	return mpow(n, M-2);
}

int main(){
	cin >> N >> M;
	pre_comb();
	rep(i, N+1){
		rep(j, (3*N/2)+1){
			if(3*N - 2*j - 3*i >= j){
				long long t1 = (fac[3*N] * finv[3*N-3*i-2*j] % M) * two[i] % M;
				long long t2 = t1 * inve(six[i] * two[j] % M) % M;
				ans = (ans + (t2 * finv[i] % M) * finv[j] % M) % M;
			}
		}
	}
	cout << ans << "\n";
	return 0;
}


#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>
// #include <atcoder/all>

#define int long long

struct edge {
    int to;
    int cost;
};

using namespace std;
// using namespace atcoder;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vb = vector<bool>;
using qi = queue<int>;
using P = pair<int, int>;
using graph = vector<vector<edge>>;
// using graph = vector<vector<int>>;
// using mint = modint1000000007;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define delim(i, n) cout << (i == n-1 ? "\n" : " ")
#define print1(v) cout << fixed << setprecision(10) << v << "\n"
#define print2(v1, v2) cout << fixed << setprecision(10) << v1 << " " << v2 << "\n"
#define print3(v1, v2, v3) cout << fixed << setprecision(10) << v1 << " " << v2 << " " << v3 << "\n"
#define printvi(v, n) REP(iiii, n) { cout << v[iiii]; delim(iiii, n); }
#define printvii(v, h, w) REP(iiiii, h) { printvi(v[iiiii], w); }

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

const int inf = 1LL << 60;
// const int inf = 100000000;
const int mod = 1000000007;

const int maxn = 1e5+5;
int n, m;
vi color(3);

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

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

    cin >> m;

    int cntc = -1;
    int cnt9 = -1;
    REP(i, m) {
        int d, c; cin >> d >> c;
        cntc += c;
        cnt9 += d*c;
    }
    int ret = cntc + (cnt9/9);
    print1(ret);
}

#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;

int main(){
	int people[21], Total, Total2;
	for (int i = 0; i < 20; i++){
		cin >> people[i];
	}
	sort(people, people + 10,greater<int>());
	sort(people + 10, people + 20,greater<int>());
	Total = people[0] + people[1] + people[2];
	Total2 = people[10] + people[11] + people[12];
	cout << Total <<" "<< Total2 << endl;
	return 0;
}


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

int gcd(int a,int b){
    return b ? gcd(b, a % b) : a;
}
int lcm(int a,int b){
    return b / gcd(a,b) * a;
}

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

    int x,y; cin >> x >> y;
    if(y >= x && y >0 && x < 0 && abs(y)> abs(x)) cout << 1 + y + x << endl;
    else if(y >= x && y >0 && x < 0) cout << -y - x + 1 << endl;
    else if(y >= x) cout << y - x << endl;
    else if(y > 0) cout << 1 - y + x + 1 << endl;
    else if(y == 0) cout << 1 + x << endl;
    else if(x >= 0 && abs(x) >= abs(y)) cout << 1 + abs(x) - abs(y) << endl;
    else if(x >= 0) cout << abs(y) - abs(x) + 1 << endl;
    else if(x > y)cout << 1 + abs(y) - abs(x) + 1 << endl;
}

#include<bits/stdc++.h>
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 f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int x, y;
    cin >> x >> y;

    vector <int> c;
    c.app(x);
    c.app(-x);
    c.app(y);
    c.app(-y);

    const int INF = 5e18;
    vector <int> d(4, INF);
    d[0] = 0;

    for (int t = 0; t < 10; ++t) {
        for (int i = 0; i < 4; ++i) {
            for (int j = 0; j < 4; ++j) {
                if (c[i] <= c[j])
                    d[j] = min(d[j], d[i] + c[j] - c[i]);
                if (c[j] == -c[i])
                    d[j] = min(d[j], d[i] + 1);
            }
        }
    }

    cout << d[2] << endl;
}


#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

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

int sx, sy, tx, ty;

int main() {
  cin >> sx >> sy >> tx >> ty;
  int dx = tx - sx;
  int dy = ty - sy;
  rep(i, 0, dy) { cout << "U"; }
  rep(i, 0, dx) { cout << "R"; }
  rep(i, 0, dy) { cout << "D"; }
  rep(i, 0, dx) { cout << "L"; }
  cout << "L";
  rep(i, 0, dy + 1) { cout << "U"; }
  rep(i, 0, dx + 1) { cout << "R"; }
  cout << "D";
  cout << "R";
  rep(i, 0, dy + 1) { cout << "D"; }
  rep(i, 0, dx + 1) { cout << "L"; }
  cout << "U";
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int sx, sy;
  cin >> sx >> sy;
  int tx, ty;
  cin >> tx >> ty;
  int dx = tx - sx, dy = ty - sy;
  cout << string(dy, 'U');
  cout << string(dx, 'R');
  cout << string(dy, 'D');
  cout << string(dx, 'L');
  cout << 'L';
  cout << string(dy+1, 'U');
  cout << string(dx+1, 'R');
  cout << "DR";
  cout << string(dy+1, 'D');
  cout << string(dx+1, 'L');
  cout << "U" << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 60);

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  vector<ll> dp(2, -INF);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    vector<ll> ndp(2, -INF);
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        int d = (j ^ k ? -a[i] : a[i]);
        ndp[k] = max(ndp[k], dp[j] + d);
      }
    }
    dp = move(ndp);
  }
  cout << dp[0] << endl;
  return 0;
}

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

int main(void) {
    int a,b,c,k;
    int64_t target;
    int64_t remains;
    cin >> a >> b >> c >> k;
    target = max(a,max(b,c));
    remains = a + b + c - target;
    target = target * pow(2,k);
    cout << target + remains << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  ll a;
  cin>>a;
  if(a==1){
    cout<<"Hello World"<<endl;
    return 0;
  }
  ll b,c;
  cin>>b>>c;
  cout<<b+c<<endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define wi(t) int t;cin>>t;while(t--)
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve()
    {
     string s;
     cin>>s;
     string ans;
      int diff=INT_MAX;
      for(int i=0;i<3;i++)
      ans+=s[i];
    diff=min(diff,abs(stoi(ans)-753));
     for(int i=3;i<s.length();i++)
     {
        ans.erase(ans.begin());
        ans.pb(s[i]);

           diff=min(diff,abs(stoi(ans)-753));

     }
     cout<<diff<<endl;

    }

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

   // wi(t)
    {
      solve();
    }

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
    u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;

    }else{
        return a.second < b.second;
    }
}

bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

int main() {
    ll H,W;
    cin >>H>>W;
    vector<vector<bool>>S(H+2,vector<bool>(W+2));

    rep2(i,H){
        rep2(j,W){
            char c;
            cin>>c;
            if(c=='#'){
                S[i][j]=1;
            }
        }
    }
    rep2(i,H){
        rep2(j,W){
            if(S[i][j]==1){
                rep(dir,4){
                    if(S[i+dx[dir]][j+dy[dir]]){
                        break;
                    }
                    if(dir==3){
                        cout<<"No"<<endl;
                        return 0;
                    }
                }
            }
        }
    }

    cout << "Yes" << endl;

    return 0;

}

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll x,y;
    cin >> x >> y;
    if(x*y > 0){
        if(x > y){
            cout << min(llabs(x)+llabs(y)+1,llabs(llabs(x)-llabs(y))+2)<< endl;
        }else{
            cout << y - x << endl;
        }
    }else if(x*y < 0){
        cout << llabs(llabs(x)-llabs(y))+1 << endl;
    }else{
        if(x == y){
            cout << 0 << endl;
        }else if(x == 0){
            if(y > 0){
                cout << y << endl;
            }else{
                cout << llabs(y)+1 << endl;
            }
        }else{
            if(x > 0){
                cout << x+1 << endl;
            }else{
                cout << -x << endl;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,x,n) for(ll i=x;i<n;i++)
#define sort(v) sort(v.begin(),v.end());
const ll mod = 1E9+7;

int main()
{
  ll a,b,c;
  cin>>a>>b>>c;
  swap(a,b);
  swap(a,c);
  cout<<a<<" "<<b<<" "<<c;
}

#include <stdio.h>
#include <string.h>
int main (){
	char d[14], e[14], f[14];
	scanf ("%s %s %s", &d, &e, &f);
		if ( d[strlen(d) - 1] == e[0] && e[strlen(e) - 1] == f[0]){
			puts ("YES\n");
		}else {
			puts ("NO\n");
		}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  vector<string> a;
  string hoge="hi";
  a.push_back(hoge);
  for(int i=0;i<4;i++){
    hoge=hoge+"hi";
    a.push_back(hoge);
  }
  for(int i=0;i<5;i++){
    if(a[i]==s){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}

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

char S[15];

int main(){
    scanf(" %s", S);

    int len = strlen(S);
    if(len%2 != 0){
        printf("No");
        return 0;
    }
    for(int i = 0; i < len; i ++){
        if(i%2 == 0 && S[i] != 'h'){
            printf("No");
            return 0;
        }
        if(i%2 == 1 && S[i] != 'i'){
            printf("No");
            return 0;
        }
    }

    printf("Yes");
    return 0;
}


#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main () {

	int n;
	vector<int> values;

	cin >> n;
	cin.ignore();

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

		if(i == n)
			getline(cin, tmp_value);
		else
			getline(cin, tmp_value, ' ');

		values.push_back(stoi(tmp_value));
	}

	for (int i = n; i != 0; i--){

		if (i == 1)
			cout << values[i - 1] << endl;
		else
			cout << values[i - 1] << ' ';
	}

	return 0;
}

#include<iostream>
using namespace std;

int main(){
	int n, A[100];
	cin >> n;
	for ( int i = 0; i < n; i++ ) cin >> A[i];

	for ( int i = n-1; i >= 0; i-- ) {
		if ( i != n-1 ) cout << " ";
		cout << A[i];
	}
	cout << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;
const int MOD = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];

    int res = 1001001001;
    int cnt;
    rep(i, n)
    {
        cnt = 0;
        while (v[i] % 2 == 0)
        {
            cnt++;
            v[i] /= 2;
        }
        res = min(res, cnt);
    }

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

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

#define int long long

signed main() {
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    vector<int> odd;
    vector<int> even;
    rep(i, n) {
        if (i % 2)
            odd.push_back(v[i]);
        else
            even.push_back(v[i]);
    }
    map<int, int> o;
    map<int, int> e;
    rep(i, n / 2) o[odd[i]]++;
    rep(i, n / 2) e[even[i]]++;
    int ofreq = 0, osfreq = 0;
    int efreq = 0, esfreq = 0;
    int o1, e1, o2, e2;
    for (auto c : o) {
        if (c.second > ofreq) {
            o2 = o1;
            o1 = c.first;
            osfreq = ofreq;
            ofreq = c.second;
        }
        else if (c.second > osfreq) {
            osfreq = c.second;
            o2 = c.first;
        }
    }
    for (auto c : e) {
        if (c.second > efreq) {
            e2 = e1;
            e1 = c.first;
            esfreq = efreq;
            efreq = c.second;
        }
        else if (c.second > esfreq) {
            esfreq = c.second;
            e2 = c.first;
        }
    }
    if (o1 != e1)
        cout << n - ofreq - efreq;
    else
        cout << n - max(ofreq + esfreq, osfreq + efreq);

    cout << endl;
}


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

int main (void){
    int r;
    cin >> r;
    if(2800 <= r){
        cout << "AGC" << endl;
    }else if(1200 <= r){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }

    return 0;
}

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

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    int r;
    cin >> r;

    if (r < 1200)
        cout << "ABC" << endl;
    else if (r < 2800)
        cout << "ARC" << endl;
    else
        cout << "AGC" << endl;

    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}


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

typedef long long ll;

int main()
{
    ll A, B, K;
    cin >> A >> B >> K;
    for (int i = 0; i < K; ++i)
    {
        if (A % 2 == 1)
        {
            --A;
        }
        B += A / 2;
        A = A / 2;
        ++i;
        if (i >= K)
        {
            break;
        }
        if (B % 2 == 1)
        {
            --B;
        }
        A += B / 2;
        B = B / 2;
    }
    cout << A << " " << B << endl;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> AB(2);
    for (int i=0;i<2;++i) cin >> AB[i];
    int K; cin >> K;
    for (int i=0;i<K;++i){
        if (AB[i&1]&1) --AB[i&1];
        AB[(i&1)^1]+=AB[i&1]/2;
        AB[i&1]/=2;
    }
    cout << AB[0] << ' ' << AB[1] << '\n';
}


#include <iostream>
//#include<stack>
#include<set>
#include<bits/stdc++.h>
using namespace std;
//int f[10005];
//int chazhao(int x)
//{
//	if(x==f[x])
//	return x;
//	else
//	return f[x]=chazhao(f[x]);
//}

int main()
{
	set<int >ss;
	int n,x;
	cin>>n>>x;
	ss.insert(x);
	for(int i=1;i<n;i++)
	{
		cin>>x;
	  if(ss.count(x)==0)
	  ss.insert(x);
	  else
	  continue;
	}
   int k=ss.size();
   if(k==n)
   cout<<"YES"<<endl;
   else
   cout<<"NO"<<endl;
 return 0;
}

#include <bits/stdc++.h>
#define Tayeb ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
int main()
{
    Tayeb;
    int N,count=0;
    cin >> N;
    int arr[N];
    for(int i=0; i<N; i++)
    {
        cin >> arr[i];
    }
    sort(arr,arr+N);
    for(int i=1; i<N; i++)
    {
        if(arr[i]==arr[i-1])
        count++;
    }
    if(count==0)
    cout << "YES" << "\n";
    else
    cout << "NO" << "\n";

    return 0;

}


#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

 int main(){
ll n ; cin>> n ;
vector<string> A(n) ;
rep(i,n) cin>>A[i] ;
vector<ll> sum(n) ,sa(n) ;
rep(i,n){
  ll k= A[i].size() ;
  ll now=0 ;
  ll ans=0 ;
  rep(j,k){
   if(A[i][j]==')') now-- ;
   else now++ ;
   chmin(ans,now)  ;
  }
  sum[i]= now ;
  sa[i]= ans ;
}
 vector<P> B, D ;
 ll zero =0 ;

  rep(i,n){
   if(sum[i]>0){
   P xx= mpa(sa[i],sum[i]) ;
   B.pb(xx) ;
   }
   if(sum[i]==0) chmin(zero,sa[i]) ;
   if(sum[i]<0){
     P yy= mpa(sum[i]-sa[i],sum[i]) ;
     D.pb(yy) ;
   }

  }

  sort(B.rbegin(),B.rend()) ;
  sort(D.begin(),D.end()) ;
  ll ok= B.size() ;
  ll ko= D.size() ;
  ll start= 0 ;
  bool flag= 0;

  rep(i,ok){
  if(start+ B[i].fi<0) flag=1;
  start+= B[i].se ;
  }

  if(start+zero<0) flag=1 ;
  ll goal =0 ;
  rep(i,ko){
    if(goal-D[i].fi<0) flag=1 ;
     goal -= D[i].se ;
  }
  if(start!=goal) flag=1 ;

  if(flag) cout<<"No"<<endl ;
  else cout<<"Yes"<<endl ;
   return 0 ;
}

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n, i, a[210];
	cin >> n;
	n *= 2;
	for (i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a, a + n);
	int b = 0, c = 0;
	for (i = 0; i < n; i += 2) {
		b += a[i];
	}
	for (i = 1; i < n - 1; i += 2) {
		c += a[i];
	}
	//c += a[0];
	cout << max(b, c) << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
char s[101];
int main() {
    int n;
    while(scanf("%d",&n),n) {
        vector<int> key;
        for(int i=0;i<n;i++) {
            int k;
            scanf("%d",&k);
            key.push_back(k);
        }
       scanf("%s",s);
       for(int i=0;s[i]!='\0';i++) {
            int code=0;
            if('a'<=s[i]&&s[i]<='z') code=s[i]-'a';
            if('A'<=s[i]&&s[i]<='Z') code=26+s[i]-'A';
            code-=key[i%key.size()];
            while(code<0) code+=52;
            code%=52;
            if(0<=code&&code<=25) putchar('a'+code);
            if(26<=code&&code<=51) putchar('A'+code-26);
       }
       putchar('\n');
    }
}

#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n+m){
    vector<int>ve(n);
    ll ans=0;
    for(int i=0;i<n;i++){
      cin>>ve[i];ans+=ve[i];
    }
    sort(ve.begin(),ve.end(),greater<int>());
    for(int i=m-1;i<n;i+=m)
      ans-=ve[i];
    cout<<ans<<endl;
  }
  return 0;
}


#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;a++)
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	rep(i, n) {
		int base[3];
		int cnt = 0;
		int out = 0;
		rep(i123, 3) { base[i123] = 0; }
		while (true) {
			string thistime;
			cin >> thistime;
			if (thistime == "HIT") {
				cnt += base[2];
				base[2] = base[1];
				base[1] = base[0];
				base[0]=1;
			}
			else if (thistime == "OUT") {
				out++;
				if (out == 3) { break; }
			}
			else {
				cnt += base[2] + base[1] + base[0] + 1;
				base[2] = base[1] = base[0] = 0;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

#include <iostream>
#include <sstream>

using namespace std;

int main(){
	string result[3]={"HIT", "HOMERUN" , "OUT"};
	string eventlist;
	int inning,run;
	int count = 0;
	int score;
	while(cin >> inning){
		for(int i=0;i<inning;i++){
			run = 0; score = 0;
			for(count=0;count < 3;){
				cin >> eventlist;
//				cout << eventlist << endl;
				if(eventlist == result[0]){
					score += (run/4);
					run = (2 * run + 1) % 8;
//					cout << run << "H" << score << endl;
				}
				else if(eventlist == result[1]){
					for(int j = 0;j < 3;j++){
						score += run % 2;
						run = run /2;
					}
					run = 0;
					score++;
//					cout << " " << score << endl;
				}
				else{
					count++;
//					cout << "o" << count << endl;
				}
			}
			cout << score << endl;
		}
	}
}


#include<iostream>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main(){
int n,sum=0;
cin>>n;
sum=n+(n*n)+(n*n*n);
cout<<sum;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

int digit(long long int a)
{
	int  ans = 0;
	while(a > 0){
		a/=10;
		ans++;
	}

	return ans;
}

int main() {
	int i;
	int count = 1;
	long long int N, A = 1, B;
	int ans = 15;

	cin >> N;

	while ((double)A <= sqrt((double)N))
	{
		if (N % A == 0)
		{
			B = N/A;
			count = max(digit(A),digit(B));
			if (ans > count)
			{
				ans = count;
			}

		}
		A++;
	}

	cout << ans <<endl;

}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

class RUQ{
public:
  int t[555555],v[555555],c;
  void init(){
    c=0;
    memset(t,0,sizeof(t));
    memset(v,0,sizeof(v));
  }
  void update(int a,int b,int x) {
    c++;
    v[c]=x;
    update2(a,b,c);
  }
  void update2(int a,int b,int x,int k=0,int l=0,int r=1<<18){
    if(b<=l||r<=a)return;
    if(a<=l&&r<=b){t[k]=max(t[k],x);return;}
    int m=(l+r)/2;
    update2(a,b,x,k*2+1,l,m);
    update2(a,b,x,k*2+2,m,r);
  }
  int query(int i){
    i+=(1<<18)-1;
    int res=t[i];
    while(i){
      i=(i-1)/2;
      res=max(res,t[i]);
    }
    return v[res];
  }
};

void Main() {
  int n,m;
  cin >> n >> m;
  RUQ r;
  r.init();
  r.v[0]=INT_MAX;
  while(m--) {
    int z,x;
    cin >> z >> x;
    if(!z) {
      int y,w;
      cin >> y >> w;
      r.update(x,y+1,w);
    } else pr(r.query(x));
  }
}

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

#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 1 << 18;
#define int long long
typedef pair<int,int> P;
int n;
P dat[2*MAX_N-1];
void init(int n_){
  n=1;
  while(n<n_) n*=2;
  for(int i=0;i<2*n-1;i++) dat[i].first=-1,dat[i].second=INT_MAX;
}
int query(int k){
  k+=n-1;
  P p=dat[k];
  //cout<<k<<"/"<<dat[k].second<<endl;
  while(k>0){
    k=(k-1)/2;
    //cout<<k<<"/"<<dat[k].second<<endl;
    p=max(p,dat[k]);
  }
  return p.second;
}

void update(int a,int b,int k,P p,int l,int r){
  if(r<=a||b<=l) return;
  if(a<=l&&r<=b) {
    //cout<<a<<":"<<b<<":"<<k<<":"<<l<<":"<<r<<endl;
     dat[k]=p;
  }else{
    update(a,b,k*2+1,p,l,(l+r)/2);
    update(a,b,k*2+2,p,(l+r)/2,r);
  }
}
signed main(){
  int _n,q;
  cin>>_n>>q;
  init(_n+1);
  for(int i=0;i<q;i++){
    int f;
    cin>>f;
    if(!f){
      int s,t,x;
      cin>>s>>t>>x;
      //cout<<i<<":"<<x<<endl;
      update(s,t+1,0,P(i,x),0,n);
    }else{
      int u;
      cin>>u;
      cout<<query(u)<<endl;
    }
  }
  return 0;
}


#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

int h, w;
vector<string> v(400);
class UnionFind
{
public:
    vector<ll> par; // 各元の親を表す配列
    vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)
    vector<ll> siz_B;
    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1), siz_B(sz_,0)
    {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_)
    {
        par.resize(sz_);
        siz.assign(sz_, 1);
        siz_B.assign(sz_, 0);
        for (ll i = 0; i < sz_; ++i){
            par[i] = i;
            if (v[i / w][i % w] == '#')
            {
                siz_B[i]=1;
            }
        }
    }

    // Member Function
    // Find
    ll root(ll x)
    { // 根の検索
        while (par[x] != x)
        {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y])
            swap(x, y);
        siz[x] += siz[y];
        siz_B[x]+=siz_B[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y)
    { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x)
    { // 素集合のサイズ
        return siz[root(x)];
    }
    ll size_B(ll x){
        return siz_B[root(x)];
    }
};

int main()
{
    cin >> h >> w;
    REP(i,h){
        cin >> v[i];
    }
    UnionFind uf(h * w);
    uf.init(h*w);
    REP(i,h){
        REP(j,w){
            if(j!=w-1&&v[i][j]!=v[i][j+1]){
                uf.merge(i*w+j,i*w+j+1);
            }
            if(i!=h-1&&v[i][j]!=v[i+1][j]){
                uf.merge(i*w+j,(i+1)*w+j);
            }
        }
    }
    set<ll> ne;
    REP(i,h){
        REP(j,w){
            ne.insert(uf.root(i*w+j));
        }
    }
    ll ans=0;
    for(auto& k:ne){
        ans+=(uf.size(k)-uf.size_B(k))*(uf.size_B(k));
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 1000000
#define MOD 1000000007
#define INF 100000000000000

vector<vector<pair<int,int>>> parent;

pair<int,int> find(pair<int,int> x){
  pair<int,int> y=parent.at(x.first).at(x.second);
  if(y!=x){
    y=find(y);
  }
  return parent.at(x.first).at(x.second)=y;
}

void unite(pair<int,int> x, pair<int,int> y){
  pair<int,int> a=find(x);
  pair<int,int> b=find(y);
  if(a!=b){
    parent.at(a.first).at(a.second)=b;
  }
}

int main(){
  int H,W;
  cin>>H>>W;
  vector<vector<char>> c(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>c.at(i).at(j);
    }
  }
  parent.resize(H,vector<pair<int,int>>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      parent.at(i).at(j)=make_pair(i,j);
    }
  }
  int dx[4]={1,0,-1,0};
  int dy[4]={0,1,0,-1};
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      for(int k=0;k<4;k++){
        int ni=i+dx[k];
        int nj=j+dy[k];
        if(ni<0||nj<0||ni>=H||nj>=W){
          continue;
        }
        if(c.at(i).at(j)!=c.at(ni).at(nj)){
          unite(make_pair(i,j),make_pair(ni,nj));
        }
      }
    }
  }
  vector<vector<ll>> number1(H,vector<ll>(W,0)),number2(H,vector<ll>(W,0));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      pair<int,int> p=find(make_pair(i,j));
      if(c.at(i).at(j)=='.'){
        number1.at(p.first).at(p.second)++;
      }else{
        number2.at(p.first).at(p.second)++;
      }
    }
  }
  ll ans=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      ans+=number1.at(i).at(j)*number2.at(i).at(j);
    }
  }
  cout<<ans<<endl;
}


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

int main(){
  int n; cin >> n;
  if(n == 0){
      cout << 0 << '\n';
      return 0;
  }
  int base = -2;
  string ans;
  while(n){
    int r = n%base;
    n = n/base;
    if(r < 0) n++;
    if(r < 0) r = r*(-1);
    char x = r + '0';
    ans = x + ans;

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

#include<iostream>
#include<cstring>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;
#define MAX 500000
#define INF 2e9
int L[MAX/2+2],R[MAX/2+2];
long long  cnt=0;
long long merge(int A[],int n,int left,int mid,int right)
{
	long long cnt=0;
    int n1=mid-left;
    int n2=right-mid;
    for(int i=0;i<n1;i++)
    {
        L[i]=A[left+i];
    }
    for(int i=0;i<n2;i++)
    {
        R[i]=A[mid+i];
    }
    L[n1]=INF;
    R[n2]=INF;
    int i=0,j=0;
    for(int k=left;k<right;k++)//合并
    {
     if(L[i]<=R[j])
     A[k]=L[i++];
     else
     {
	 A[k]=R[j++];
	 cnt=cnt+(n1-i);
}
}
return cnt;
}
long long  mergeSort(int A[],int n,int left,int right)
{
	long long v1,v2,v3;
    if(left+1<right)
    {
        int mid=(left+right)/2;
        v1=mergeSort(A,n,left,mid);
        v2=mergeSort(A,n,mid,right);
        v3=merge(A,n,left,mid,right);
        return (v1+v2+v3);
    }
    else
    return 0;
}
int main()
{
int A[MAX],n;
cnt=0;
cin>>n;
for(int i=0;i<n;i++)
cin>>A[i];
cnt=mergeSort(A,n,0,n);
cout<<cnt<<endl;
return 0;
 }


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;

const ll MOD = 998244353LL;
const ll MAX = 2000010LL;

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

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

ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main(int argc, char *argv[]) {
  COMinit();

  ll n, m, k;

  cin >> n >> m >> k;

  ll ans = 0LL;

  for(ll i=0;i<=k;i++){
    ans += ((m*modpow(m-1LL,n-i-1LL)%MOD)*COM(n-1LL,i)) % MOD;
    ans %= MOD;
  }

  if(ans<0LL){
    ans += MOD;
  }

  cout << ans << endl;

  return 0;
}

#include <bits/stdc++.h>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int turn,tmp;

int main(){
	string s[3];
	cin >> s[0] >> s[1] >> s[2];
	while(true){
		if(!s[turn].empty()){
			tmp = s[turn][0]-'a';
			s[turn].erase(s[turn].begin());
		}else{
			cout << static_cast<char>(turn+'A') << endl;
			return 0;
		}
		turn = tmp;
	}
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e6;
int n,s[N+1],t[N+1];
int hea=1,tai,que[N+1];
int res;
void input(int x[])
{
	static char str[N+2];
	scanf("%s",str+1);
	for(int i=1;i<=n;++i) {
		x[i]=str[i]-'a';
	}
	return;
}
bool check0()
{
	for(int i=1;i<=n;++i) {
		if(s[i]!=t[i]) {
			return false;
		}
	}
	return true;
}
int main()
{
	scanf("%d",&n);
	input(s);
	input(t);
	if(check0()) {
		puts("0");
		return 0;
	}
	for(int spos=n,tpos=n;tpos;--tpos) {
		while((tpos>1)&&(t[tpos-1]==t[tpos])) {
			--tpos;
		}
		while(spos&&((spos>tpos)||(s[spos]!=t[tpos]))) {
			--spos;
		}
		if(!spos) {
			puts("-1");
			return 0;
		}
		while((hea<=tai)&&(que[hea]-(tai-hea+1)+1>tpos)) {
			++hea;
		}
		que[++tai]=spos;
		if(tpos!=1) {
			res=max(res,tai-hea+1);
		}
	}
	++res;
	printf("%d\n",res);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
char s[N],t[N];
int n,ans,l=1,r,last,q[N];
int main(){
	scanf("%d%s%s",&n,s+1,t+1),last=n;
	for(int i=n;i;){
		while(last&&(i<last||s[last]!=t[i])) --last;
		if(!last)	{puts("-1");return 0;}
		while(l<=r&&q[l]-r+l-1>=i)	++l;
		q[++r]=last;
		if(i!=last) ans=max(ans,r-l+1);
		while(t[i]==s[last]&&i>=last)	--i;
	}
	printf("%d\n",ans);
	return 0;
}


#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#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(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll N, ll Q, std::string S, std::vector<ll> l, std::vector<ll> r) {
  vector<ll> a(N, 0);
  FOR(i, 1, N) {
    a.at(i) = a.at(i - 1);
    if (S.at(i) == 'C' && S.at(i - 1) == 'A') a.at(i) += 1;
  }

  rep(i, Q) cout << a.at(r.at(i) - 1) - a.at(l.at(i) - 1) << endl;
}

int main() {
  ll N;
  scanf("%lld", &N);
  ll Q;
  scanf("%lld", &Q);
  std::string S;
  std::cin >> S;
  std::vector<ll> l(Q);
  std::vector<ll> r(Q);
  for (int i = 0; i < Q; i++) {
    scanf("%lld", &l[i]);
    scanf("%lld", &r[i]);
  }
  solve(N, Q, S, std::move(l), std::move(r));
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 2;
const int INF = 2e18;

signed main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N + 1);
    vector<int> count(N + 1, 0);
    int start = 0;
    {
        set<int> remain;
        for (int i = 1; i <= N; i++) remain.insert(i);
        for (int i = 0; i < N + M - 1; i++) {
            int A, B;
            cin >> A >> B;
            G[A].push_back(B);
            count[B]++;
            remain.erase(B);
        }
        start = *remain.begin();
    }
    vector<int> ans(N + 1, -1), dis(N + 1, -1);
    ans[start] = 0;
    dis[start] = 0;
    queue<int> explore;
    explore.push(start);
    while (!explore.empty()) {
        int now = explore.front();
        explore.pop();
        for (int next : G[now]) {
            count[next]--;
            if (dis[next] < dis[now] + 1) {
                dis[next] = dis[now] + 1;
                ans[next] = now;
            }
            if (count[next] == 0) explore.push(next);
        }
    }
    for (int i = 1; i <= N; i++) cout << ans[i] << endl;
}


#include <cstdio>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
int arr[3][100005], nxt[100005], rev[100005];
bool vis[100005];
int main()
try
{
	// freopen("AGC006-E.in", "r", stdin);
	int n;
	scanf("%d", &n);
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < n; j++)
			scanf("%d", arr[i] + j);
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			if (my_abs(arr[j][i] - arr[j + 1][i]) != 1)
				throw false;
		}
		nxt[i] = (arr[1][i] + 1) / 3 - 1;
		if ((nxt[i] ^ i) & 1)
			throw false;
		rev[i & 1] ^= arr[0][i] > arr[2][i];
	}
	for (int i = 0; i < n; i++)
	{
		if (vis[i])
			continue;
		rev[i & 1 ^ 1] ^= 1;
		int x = i;
		while (!vis[x])
		{
			vis[x] = true;
			rev[i & 1 ^ 1] ^= 1;
			x = nxt[x];
		}
	}
	if (rev[0] || rev[1])
		throw false;
	puts("Yes");
	return 0;
}
catch (bool)
{
	puts("No");
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) (x&-x)

int num[4][100010],c0[300010],c1[300010],n;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline void add0(int x) { for (;x;x-=lowbit(x)) c0[x]++; }

inline void add1(int x) { for (;x;x-=lowbit(x)) c1[x]++; }

inline int sum0(int x)
{
	int res=0;
	for (;x<=n*3;x+=lowbit(x)) res+=c0[x];
	return res;
}

inline int sum1(int x)
{
	int res=0;
	for (;x<=n*3;x+=lowbit(x)) res+=c1[x];
	return res;
}

int main()
{
	n=rd();
	for (int i=1;i<=3;i++) for (int j=1;j<=n;j++) num[i][j]=rd();
	int t0=0,t1=0,tt0=0,tt1=0;
	for (int i=1;i<=n;i++)
	{
		int h1=num[1][i],h2=num[2][i],h3=num[3][i];
		if (h1<h3)
		{
			if (h2-h1!=1||h3-h2!=1) { puts("No");return 0; }
			if (h1%3!=1) { puts("No");return 0; }
			int hh=h1/3+1;
			if (abs(i-hh)&1) { puts("No");return 0; }
		}
		else
		{
			if (h2-h3!=1||h1-h2!=1) { puts("No");return 0; }
			if (h3%3!=1) { puts("No");return 0; }
			int hh=h3/3+1;
			if (abs(i-hh)&1) { puts("No");return 0; }
			if (i&1) t1^=1;
			else t0^=1;
		}
	}
	for (int i=1;i<=n;i++)
	{
		int h1=num[1][i],h3=num[3][i];
		if (h1<h3)
		{
			if (i&1) tt0+=sum1(h1),add1(h1);
			else tt1+=sum0(h1),add0(h1);
		}
		else
		{
			if (i&1) tt0+=sum1(h3),add1(h3);
			else tt1+=sum0(h3),add0(h3);
		}
		tt0&=1;tt1&=1;
	}
	if (t0==tt0&&t1==tt1) puts("Yes");
	else puts("No");
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  for (int i = N; i > 0; i--)
  {
    if (sqrt(i) == floor(sqrt(i))){
      cout << i << endl;
      return 0;
    }

  }

}

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

int main(){
	string str;
	while(1){
		getline( cin, str );
		if( str.length()==0 )	break;
		for( int i=0; i<=26; i++ ){
			for( int j=0; j<str.length(); j++ ){
				if( 'a'<=str[j] && str[j]<='z' ){
					str[j]++;
					if( str[j] == 'z'+1 )
						str[j] = 'a';
				}
			}
			if( str.find("the")+str.find("this")+str.find("that") != -3 ){
				cout << str << endl;
				break;
			}
		}
	}
	return 0;
}


#include<cstdio>
#include<stdio.h>
#include<string>
#include<iostream>
#include<map>
using namespace std;
#include<algorithm>

bool two(int *a,int left,int right,int num){
	while(left<right){
		int mid=(left+right)/2;
		if(a[mid]==num){
			return true;
		}
		else if(a[mid]>num){
			right=mid;
		}
		else if(a[mid]<num){
			left=mid+1;
		}
	}
	return false;
}

int main(){
	int n,q,a[100005],b[100005],count=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>b[i];
	}
	sort(a,a+n);
	for(int i=0;i<q;i++){
		if(two(a,0,n,b[i])){
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
}

#include <algorithm>
#include <bits/stdc++.h>
#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define INF 1LL << 40;
#define ll long long
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define prique priority_queue
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
template <class T> inline void chmax(T &a, T b) { a < b ? a = b : a; };
template <class T> inline void chmin(T &a, T b) { a > b ? a = b : a; };
int main() {
    int n, q, res = 0;
    cin >> n;
    vi s(n);
    rep(i, n) cin >> s[i];
    cin >> q;
    vi t(q);
    rep(i, q) cin >> t[i];
    rep(i, q) rep(j, n) {
        if(t[i] == s[j]) {
            res++;
            break;
        }
    }
    cout << res << endl;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#define INF 111111111
using namespace std;

long int cost[1000][1000],ans[1000];
int memo[1000];
int n,k,m,a,b,c;

void solve(int s){
  ans[a] = 0;

  while(true){
    int k = -1;

    for(int i=1;i<=n;i++){
      if(!memo[i] && (k == -1 || ans[i] < ans[k])) k = i;
    }

    if(k == -1) break;

    memo[k] = 1;

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

int main(){

  while(true){
    cin >> n >> k;
    if(!n && !k) break;

    for(int i=0;i<1000;i++){
      for(int j=0;j<1000;j++) cost[i][j] = INF;
    }

    for(int i=0;i<k;i++){
      cin >> m;

      if(m){
	cin >> a >> b >> c;
	if(cost[a][b] > c) cost[a][b] = cost[b][a] = c;
      }

      if(!m){
	cin >> a >> b;

	for(int i=0;i<1000;i++) ans[i] = INF;
	memset(memo,0,sizeof(memo));
	solve(a);

	if(ans[b] < INF) cout << ans[b] << endl;
	if(ans[b] == INF) cout << -1 << endl;
      }
    }
  }
}

#include<atcoder/all>
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;
using namespace atcoder;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}

// segtree
// 型 S, 二項演算 S op(S a, S b), 単位元 S e() を設定
// segtree<int, op, e> seg(10); // 要素数n、segという名前で作成
// seg.set(int p, S x) // a[p]にxを代入
// S seg.get(int p) // a[p]を返す
// S seg.prod(int l, int r) // op(a[l], ..., a[r - 1])を返す
// S seg.all_prod() // op(a[0], ..., a[n - 1])を返す
// int seg.max_right<f>(int l) // f(op(a[l], a[l + 1], ..., a[r - 1])) = trueとなる最大のr

int op(int a, int b){
    return a+b;
}

int e(){
    return 0;
}

signed main(){
    int n,q;
    cin >> n >> q;
    segtree<int, op, e> seg(n);
    REP(i,n){
        int a1;
        cin >> a1;
        seg.set(i,a1);
    }

    REP(i,q){
        int q1;
        int q2,q3;
        cin >> q1 >> q2 >> q3;
        if(q1==0){
            seg.set(q2,seg.get(q2)+q3);
        }
        else{
            cout << seg.prod(q2,q3) << endl;
        }

    }

    return 0;
}


#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	string s;
	int ans=0;
	cin >>s;
	set<char>dis;
	for(char i:s){
		dis.insert(i);
	}
	dis.insert('z' + 6);
	for (char i = 'a'; i <= 'z'; i++) {
		if(*dis.lower_bound(i)!=i){
			cout << i << endl;
			return 0;
		}
	}
	cout << "None" << endl;
}

//list index out of rangeエラー表示用
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep1(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main(){
  int n;
  cin >> n;
  vector<int> l(n);
  rep1(i, n){
    cin >> l[i];
  }
  int ans = 0;
  rep2(i, 0, n-2){
    rep2(j, i+1, n-1){
      rep2(k, j+1, n){
        int a = l[i];
        int b = l[j];
        int c = l[k];
        if(a != b && b != c && c != a && a+b > c && b+c > a && c+a > b){
          ans += 1;

        }

      }
    }
  }
  cout << ans;

}


#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; }
ll modc(ll a, char op, ll b, ll _mod=mod)
{
        a %= _mod; b %= _mod; ll res = 1;
        switch (op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break;
        }
        if (res < 0) { res += _mod; } return res;
}

int main()
{
        ll N, x;
        cin >> N >> x;

        vll a(N);
        rep(i, 0, N) cin >> a[i];

        ll ans = 0;
        sort(all(a));
        rep(i, 0, N) {
                if (i != N-1) {
                        if (x >= a[i]) {
                                x -= a[i];
                                ++ans;
                        }
                } else {
                        if (a.back() == x) ++ans;
                }
        }

        cout << ans << endl;
}

#include <iostream>
#include <iomanip>
#include <map>
#include <list>
#include <set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

constexpr ll inf = INT64_MAX / 4;
constexpr double pi = asin(1) * 2;
constexpr ll mod = 1000000007;

template<class T>
class set2 : public set<T> {
private:
    typename set<T>::iterator back_itr() {
        auto e = this->end();
        e--;
        return e;
    }

public:
    T front() {
        if (this->empty()) throw;
        return *this->begin();
    }

    T back() {
        if (this->empty()) throw;
        return *this->back_itr();
    }

    void erase_front() {
        if (!this->empty()) this->erase(this->begin());
    }

    void erase_back() {
        if (!this->empty()) this->erase(this->back_itr());
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    for (auto &e:a) cin >> e;
    for (auto &e:b) cin >> e;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    bool f = true;
    for (int i = 1; i < n; i++) if (a[i] == a[i - 1]) f = false;
    for (int i = 1; i < m; i++) if (b[i] == b[i - 1]) f = false;
    if (!f) {
        cout << 0 << endl;
        return 0;
    }
    auto in_r = [](vector<int> r, int e) { return binary_search(r.begin(), r.end(), e); };
    auto in_a = [&in_r, &a](int e) { return in_r(a, e); };
    auto in_b = [&in_r, &b](int e) { return in_r(b, e); };
    ll r = 1;
    for (int i = n * m; i > 0; i--) {
        if (in_a(i) && in_b(i)) {
            r *= 1;
        } else if (in_a(i)) {
            r *= b.end() - lower_bound(b.begin(), b.end(), i);
        } else if (in_b(i)) {
            r *= a.end() - lower_bound(a.begin(), a.end(), i);
        } else {
            r *= (a.end() - lower_bound(a.begin(), a.end(), i)) * (b.end() - lower_bound(b.begin(), b.end(), i)) -
                 (n * m - i);
        }
        r %= mod;
    }
    cout << r << endl;
}


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

int main(){
  int A,B;
  int ans=0;
  cin >> A >> B;
  for(int i=0;i<2;i++){
    ans+=max(A,B);
    if(max(A,B)==A){
      A--;
    }
    else{
      B--;
    }
  }
  cout << ans << endl;
}


#include <stdio.h>

int main(){
	int year=0;
	char str[5];
	scanf("%d/%s",&year, &str);
	printf("2018/%s", str);

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string s;
    cin >> s;
    string ans;
    rep(i, s.length()){
        if(i == 3) ans += '8';
        else ans += s[i];
    }
    cout << ans << endl;
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
typedef pair<int,int> P;
#define MAX 10000

int is_prime[MAX+5];// 1:prime 0:not prime
int ans[MAX+5];
void eratos()
{
	int i,j;
	for(i=2;i<=MAX;i++)is_prime[i]=1;
	for(i=2;i*i<=MAX;i++)if(is_prime[i]==1)
	{
		for(j=i*2;j<=MAX;j+=i)is_prime[j]=0;
	}
	return;
}

int main(void)
{
	eratos();
	for(int i=0;i<=MAX;i++)if(is_prime[i]&&is_prime[i+2])ans[i+2]=i+2;
	for(int i=5;i<=MAX;i++)if(ans[i]==0)ans[i]=ans[i-1];
	while(1)
	{
		int n;
		cin >> n;
		if(n==0)break;
		cout << ans[n]-2 << ' ' << ans[n] << endl;
	}
	return 0;
}

#include <cstdio>
#include <cmath>
#define buf 10000
using namespace std;
int k=0;
int B[buf];
void Answer(int n);
int PrimeNumber(int n);

int main(void){
  int i,n;
  char str[buf];

  for(i=2;i<buf;i++)
    PrimeNumber(i);
  for( ;fgets(str,sizeof(str),stdin)!=NULL; ){
    sscanf(str,"%d",&n);
    if(n==0) break;
    Answer(n);
  }
  return 0;
}

void Answer(int n){
  int i,j;
  for(i=0;i<k;i++){
    if(B[i]>n)
        break;
  }
  for(j=i-1;j>=0;j--){
    if(B[j]-B[j-1]==2){
      printf("%d %d\n",B[j-1],B[j]);
      break;
    }
  }
}

int PrimeNumber(int n){
  int i,c;
  if(n==2){
    B[k]=n;
    k++; return 0;
  }
  if(n<2 || n%2==0)
    return 0;
  c=sqrt(n);
  for(i=3;i<=c;i+=2){
    if(n%i==0)
      return 0;
  }
  B[k]=n;
  k++; return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
static const ll mod=1000000007;
ll modpow(ll x,ll y){
if(y==0)
  return 1;
  else if(y%2==0){
    ll z=modpow(x,y/2);
    return (z*z)%mod;
  }else{
  ll z=modpow(x,y/2);
    return (x*((z*z)%mod))%mod;
  }
}
ll H,W,A,B;
ll fac[200005];
ll rev[200005];
int main(){
cin>>H>>W>>A>>B;
  fac[0]=1;rev[0]=1;
  for(ll i=1;i<=200004;i++){
  fac[i]=(i*fac[i-1])%mod;
    rev[i]=modpow(fac[i],mod-2);
  }ll ans=0;
  for(ll i=B;i<W;i++){
  ll a=(rev[i]*((fac[H-A-1+i]*rev[H-A-1])%mod))%mod;
    ll b=(rev[W-1-i]*((fac[W+A-2-i]*rev[A-1])%mod))%mod;
    ans=(ans+(a*b)%mod)%mod;
  }cout<<ans<<endl;
  return 0;
}

#include <cstdio>
#include <algorithm>
#include <vector>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int N(2e5 + 10), Mod(1e9 + 7);
int fac[N], inv[N], f[N], n, m, A, B;
int C(int n, int m) { return 1ll * fac[n + m] * inv[m] % Mod * inv[n] % Mod; }
int fastpow(int x, int y)
{
	int ans = 1;
	for (; y; y >>= 1, x = 1ll * x * x % Mod)
		if (y & 1) ans = 1ll * ans * x % Mod;
	return ans;
}

int main()
{
	n = read() - 1, m = read() - 1, A = read() - 1, B = read() - 1, fac[0] = inv[0] = 1;
	if (A == n || B == m) return puts("0"), 0;
	for (int i = 1; i <= n + m; i++) fac[i] = 1ll * fac[i - 1] * i % Mod;
	inv[n + m] = fastpow(fac[n + m], Mod - 2);
	for (int i = n + m - 1; i; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % Mod;
	int ans = C(n, m);
	for (int i = 0; i <= A; i++)
		ans = (ans - 1ll * C(i, m - B - 1) * C(n - i, B) % Mod + Mod) % Mod;
	printf("%d\n", ans);
	return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;
double PI = 4*atan(1);

int N, M;
int adj[15][15], stor[1<<15][15], dp[1<<15][15];
vector<pii> nex[1<<15];

void gen(int i, int cur, int todo, int cost) {
    if (todo == N) {
        nex[i].pb({cur,cost});
        return;
    }
    if ((i & (1<<todo)) == 0) gen(i,cur+(1<<todo),todo+1,cost+stor[i][todo]);
    gen(i,cur,todo+1,cost);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> M;
    F0R(i,M) {
        int a,b,c; cin >> a >> b >> c;
        a--, b--;
        adj[a][b] = adj[b][a] = c;
    }

    F0R(i,1<<N) {
        F0R(j,N) {
            int tot = 0;
            F0R(k,N) if (i & (1<<k)) tot += adj[j][k];
            stor[i][j] = tot;
        }
        gen(i,0,0,0);
    }

    F0R(i,1<<N) F0R(j,N) dp[i][j] = MOD;
    dp[1][0] = 0;

    F0R(i,1<<N) if (i&1) F0R(j,N) if (i&(1<<j)) {
        F0R(k,N) if ((i&(1<<k)) == 0) if (adj[j][k]) dp[i^(1<<k)][k] = min(dp[i^(1<<k)][k],dp[i][j]+stor[i^(1<<j)][k]);
        for(pii a: nex[i]) dp[i^a.f][j] = min(dp[i^a.f][j],dp[i][j]+a.s-stor[a.f][j]);
    }

    cout << dp[(1<<N)-1][N-1];
}

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

const int maxn = 100010;
int n, m, dep[maxn];
bool vis[maxn];
vector<int> G[maxn];

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1, u, v; i <= m; i++) {
        scanf("%d %d", &u, &v);
        G[u].push_back(v), G[v].push_back(u);
    }
    long long s1 = 0, s2 = 0, s3 = 0;
    vector<int> V1, V2;
    for (int i = 1; i <= n; i++) if (!vis[i]) {
        dep[i] = 1;
        int sz = 0, flag = 0;
        function<void(int)> dfs = [&](int v) {
            vis[v] = 1, sz++;
            for (int u : G[v]) {
                if (!vis[u]) dep[u] = dep[v] + 1, dfs(u);
                else if (!(dep[v] - dep[u] & 1)) flag = 1;
            }
        };
        dfs(i);
        if (sz == 1) { s3++; continue; }
        if (!flag) s1++;
        else s2++;
    }
    long long ans = 0;
    ans += 2 * s3 * n - s3 * s3;
    ans += 2 * s1 * s1 + s1 * s2;
    ans += s2 * (s1 + s2);
    printf("%lld\n", ans);
    return 0;
}


#include <cstdio>
#include <vector>
#include <map>
using namespace std;
#define N 8

int board[N][N];
vector< pair<int,int> > queen;
vector< pair<int,int> > sol_queen;

bool check(int k, int x, int y)
{
  for(int i=0;i<k;i++)
  {
    int tx = queen[i].first;
    int ty = queen[i].second;
    if(x == tx) return false;
    if(y == ty) return false;
    if((x-tx)*(x-tx) == (y-ty)*(y-ty)) return false;
  }
  return true;
}

/*
void printQueen() {
  for(int i=0;i<N;i++) {
    printf("%d : (%d,%d)\n",i,queen[i].first,queen[i].second);
  }
}
*/

void setQueen(int k,bool is_solution) {
  if(k == N && !is_solution) {
    is_solution = true;
    sol_queen = queen;
    return;
  }
  for(int i=0;i<N;i++) {
    for(int j=0;j<N;j++) {
      if(check(k,i,j)) {
        queen[k] = make_pair(i,j);
        setQueen(k+1,is_solution);
      }
    }
  }
}

int main() {
  // initialize
  queen.resize(N,make_pair(-1,-1));

  int k,r,c;
  scanf("%d",&k);
  for(int i=0;i<k;i++) {
    scanf("%d %d",&r,&c);
    queen[i] = make_pair(r,c);
  }

  setQueen(k,false);

  for(int k=0;k<N;k++) {
    board[sol_queen[k].first][sol_queen[k].second] = 1;
  }
  for(int i=0;i<N;i++) {
    for(int j=0;j<N;j++) {
      if(board[i][j] == 0)
        printf(".");
      else
        printf("Q");
    }
    printf("\n");
  }
}

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    int A,B,C,D;
    vector<pair<int,int> > P;
    vector<int> R;

    cin >> N;

    P.push_back({1000000000,-1});
    R.resize(N+1);

    for(int i=1; i<=N; ++i) P.push_back({0,i});

    for(int i=0; i<N*(N-1)/2; ++i) {
        cin >> A >> B >> C >> D;
        if(C==D) {
            ++P[A].first;
            ++P[B].first;
        } else if(C>D) {
            P[A].first+=3;
        } else {
            P[B].first+=3;
        }
    }

    sort(P.rbegin(),P.rend());

    int rnk=1;

    R[P[1].second]=1;

    for(int i=2; i<=N; ++i) {
        if(P[i-1].first!=P[i].first) rnk=i;
        R[P[i].second]=rnk;
    }

    for(int i=1; i<=N; ++i) {
        cout << R[i] << endl;
    }

    return 0;
}


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

using ll = int64_t;
constexpr ll mod = ll(1e9 + 7);

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

  int TT = 1;
  // cin >> TT;
  while (TT--) {
    ll n,h,w;
    cin >> n >> h >> w;
    --h;
    --w;
    cout << max(ll(0), ((n-h)*(n-w))) << endl;
  }
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,H,W;
    cin >> N >> H >> W;
    cout << (N-H+1)*(N-W+1) << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;

    }else{
        return a.second < b.second;
    }
}

bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

int main() {
    ll N,M;
    cin >>N>>M;
    vector<ll>m(N+5);

    rep(i,M){
        ll l,r;
        cin>>l>>r;
        m[l]++;
        m[r+1]--;
    }
    ll ans =0;
    rep(i,N+4){
        m[i+1]+=m[i];
        if(m[i+1]==M){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;

}

#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
#define int long long
int dp[6006], n, m, x, y, res;
pair<int, int> p[3003];
int32_t main() {
    DAU
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> p[i].first >> p[i].second;
    sort(p + 1, p + n + 1);
    dp[0] = 1;
    for (int i = 1; i <= n; ++i) {
        tie(x, y) = p[i];
        for (int j = m - 1; j >= 0; --j)
            if (dp[j])
                dp[j + x] = max(dp[j + x], dp[j] + y);
    }
    for (int i = 1; i <= m + 3000; ++i)
        res = max(res, dp[i]);
    cout << res - 1;
    PLEC
}


//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

const long long M=1000000007;
//typedef long T;
//#include "math/mod.h"

//#include "math/modulo.h"

template<class T, long long M>
struct modulo {
	T n;
	T gcd_ext(T a, T b, T *x, T *y) {
		if (a == 0) {
			*x = 0;
			*y = 1;
			return b;
		}
		T x1, y1;
		T gcd = gcd_ext(b%a, a, &x1, &y1);
		*x = y1 - (b/a) * x1;
		*y = x1;
		return gcd;
	}
	modulo(T n): n(n<0? n%M+M: n%M) {}
	operator T() const { return n; }
	modulo operator-() {
		return modulo(-n);
	}
	modulo operator+(const modulo &o) {
		return modulo(n+o.n);
	}
	modulo operator-(const modulo &o) {
		return modulo(n-o.n);
	}
	modulo operator*(const modulo &o) {
		return modulo(n*o.n);
	}
	modulo operator/(const modulo &o) {
		T x, y;
		T g = gcd_ext(o.n, M, &x, &y);
		if (g != 1) return 0;
		else return modulo(n * (x % M));
	}
	bool operator<(const modulo &o) const {
		return n<o.n;
	}
	bool operator<=(const modulo &o) const {
		return n<=o.n;
	}
	bool operator>(const modulo &o) const {
		return n>o.n;
	}
	bool operator>=(const modulo &o) const {
		return n>=o.n;
	}
	bool operator==(const modulo &o) const {
		return n==o.n;
	}
	bool operator!=(const modulo &o) const {
		return n!=o.n;
	}
};

typedef modulo<long long, M> T;
//#include "math/comb.h"

void comb_inc_k(T &r, int n, int &k) {
        //C(n,k+1) = C(n,k) * (n-k) / (k+1)
	r = r * T(n-k) / T(k+1);
	k++;
}

void comb_dec_k(T &r, int n, int &k) {
        //C(n,k-1) = C(n,k) * k / (n-k+1)
	r = r * T(k) / T(n-k+1);
	k--;
}

void comb_inc_n(T &r, int &n, int k) {
        //C(n+1,k) = C(n,k) * (n+1) / (n+1-k)
	r = r * T(n+1) / T(n+1-k);
	n++;
}

void comb_dec_n(T &r, int &n, int k) {
        //C(n-1,k) = C(n,k) * (n-k) / n
	r = r * T(n-k) / T(n);
	n--;
}

T comb(int n, int k) {
    if (k*2 > n) k = n-k;
    if (n==0) return 0;
    T r = 1; //C(n,0)
    for (int i=0; i<k; ) comb_inc_k(r, n, i);
    return r;
}

int h,w,a,b;

int input() {
	if (scanf("%d %d %d %d", &h, &w, &a, &b) < 0) return 0;
	return 1;
}

void init() {
}

int solve() {
	T r = comb(h+w-2, h-1);

	int xn = h-a+b-1, xk = b-1;
	T x = comb(xn, xk);

	int yn = a-1+w-b-1, yk = w-b-1;
	T y = comb(yn, yk);

	for (int i=0; i<a; i++) {
		//T x = mod_combinations(h-a+i+b-1, b-1, M);
		//T y = mod_combinations(a-1-i+w-b-1, w-b-1, M);
		if (i) {
			comb_inc_n(x, xn, xk);
			comb_dec_n(y, yn, yk);
		}
		r = r-x*y;
	}
	/*
	T r = mod_combinations(h+w-2, h-1, M);
	T x = mod_combinations(h-a+b-1, b-1, M);
	T y = mod_combinations(a-1+w-b-1, w-b-1, M);
	for (int i=0; i<a; i++) {
		//T x = mod_combinations(h-a+i+b-1, b-1, M);
		//T y = mod_combinations(a-1-i+w-b-1, w-b-1, M);
		if (i) {
			T n = h-a+i+b-1, m = b-1;
			x = mod_div(x*n, n-m, M);

			n = a-1-i+w-b-1, m = w-b-1;
			y = mod_div(y*(n+1-m), n+1, M);
		}
		T z = mod_mul(x, y, M);
		//printf("%d: r=%ld %ld %ld %ld\n", i, r, x, y, z);
		r = mod_sub(r, z, M);

	}
	*/
	return r;
}

void output(int ans) {
	printf("%d\n", ans);
}

void cleanup() {
}

int main() {
	//precalc();
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}

#include "bits/stdc++.h"

using namespace std;
using ll = long long;

const ll MOD = 1e9 + 7;

inline void normal(ll &a) { if (a >= MOD) a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) {normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) {normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) {normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; } //if MOD is prime, modPow(b, p % (MOD-1))
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

const int mx = 1e6 + 9;

ll f[mx];

ll ncr(ll n, ll r) {
    return modDiv(f[n], modMul(f[r], f[n - r]));
}

ll total_path(ll r, ll c) {
    return ncr(r + c - 2, r - 1);
}

int main() {
    f[0] = 1;
    for (int i = 1; i < mx; i++) f[i] = modMul(i, f[i - 1]);
    ll h, w, a, b; cin >> h >> w >> a >> b;
    ll ttl = 0;

    for (ll i = 1; i <= h - a; i++) {
        ll temp = modMul(total_path(i, b), total_path(h - i + 1, w - b));
        ttl = modAdd(ttl, temp);
    }

    cout << ttl << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n;
  cin>>n;
  cout<<n/3<<endl;
}

#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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

int main(){
    string S; cin >> S;
    if(S.length() == 3)
        swap(S[0], S[2]);
    cout << S << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1000000007;
const int INF=1001001001;

int main() {
  int N;
  cin>>N;
  cout<<0<<endl;
  string start;
  cin>>start;
  string vac="Vacant";
  if(start==vac){cout<<0<<endl;return 0;}
  int l=0,r=N;
  while(r-l>1){
    int mid=(l+r)/2;
    cout<<mid<<endl;
    string next;
    cin>>next;
    if(next==vac){cout<<mid<<endl;return 0;}
    else if(mid%2==l%2){
      if(next!=start){r=mid;}
      else{l=mid;start=next;}
    }
    else {
      if(next==start){r=mid;}
      else{l=mid;start=next;}
    }
  }

  return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};

int main() {
  int N; cin >>N;
  vector<int> seat(N+1, -1);
  // 0: Male, 1: Female
  cout <<0 <<endl;
  fflush(stdout);
  string s; cin >>s;
  if (s == "Vacant") return 0;
  seat[0] = s == "Male" ? 0 : 1;
  seat[N] = s == "Male" ? 0 : 1;
  int ai = 0, bi = N;
  for (int qq=1; qq<20; qq++){
    int ci = (ai+bi)/2;
    cout <<ci <<endl;
    fflush(stdout);
    cin >>s;
    if (s == "Vacant") return 0;
    seat[ci] = s == "Male" ? 0 : 1;
    if ((seat[ai]^seat[ci]) != abs((ai-ci)%2)){
      bi = ci;
    }else{
      ai = ci;
    }
  }
}


#include <bits/stdc++.h>
#define P pair<int, int>

using namespace std;
const int INF=1e5;

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

int main(){
  int h,w,a[1009][1009];
  string s[1009];
  cin >> h >> w;
  memset(a, -1, sizeof(a));
  for(int i=0;i<h;i++)cin >> s[i];
  queue<P> q;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#'){
        a[i][j]=0;
        q.push(P(i,j));
      }
    }
  }
  int mx=0;
  while(!q.empty()){
    P p=q.front();q.pop();
    int ci=p.first;
    int cj=p.second;
    for(int i=0;i<4;i++){
      int ni=ci+dy[i];
      int nj=cj+dx[i];
      if(!(0<=ni&&ni<h&&0<=nj&&nj<w))continue;
      if(a[ni][nj]==-1){
        a[ni][nj]=a[ci][cj]+1;
        mx = max(mx, a[ni][nj]);
        q.push(P(ni, nj));
      }
    }
  }
  cout << mx << endl;
}

                                              //BISMILLAHIR RAHMANIR RAHIM
                                               //BY THE NAME OF ALLAH
                                               //FAISAL AHAMMED SHAWON
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<set>
#include<map>
#include<iterator>
#include<numeric>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define SQ(a) (a)*(a)
#define pi acos(-1.0)
const int MAX=100001;
const int MOD=1e9+7;
int ara[MAX];
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    else
    gcd(b,a%b);
}
ll lcd(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}

bool f(ll a,ll b)
{
    return a>b;
}
ll max_sum_subarrays(ll ara[],ll n)
{
    ll ans=0,sum=0;
    for(ll k=0;k<n;k++){
        sum=max(ara[k],sum+ara[k]);
        ans=max(ans,sum);
    }
    return ans;
}
ll num_divisors(ll n)
{
    long long cnt=0;
    for(int i=1;i*i<=n;i++)
    {
        if(n%i==0 && i*i==n)
            cnt+=1;
        if(n%i==0 && i*i!=n)
                cnt+=2;
    }
    return cnt;
}
ll comb(ll m, ll n)
{
    ll x = max(m-n,n),ans = 1,i=1;
    for(ll k=m;k>=x+1;k--){
        ans*=k;
        ans/=i;
        i++;
    }
    return ans;
}
ll binsearch(ll low,ll high,ll target)
{
    while(low<=high)
    {
        ll mid=(low+high)/2;
        if(ara[mid]>target)
            high=mid-1;
        else if(ara[mid]<target)
            low=mid+1;
        else return mid;
    }
    return -1;
}

int main()
{
    fast();
    int n;
    cin>>n;
    int ara[n];
    for(int i=0;i<n;i++)
    {
        cin>>ara[i];
    }
    int maxm=ara[0];
    int ans=0;
    for(int i=1;i<n;i++)
    {
        if(maxm>ara[i])
        {
            maxm=ara[i];
            ans++;
        }
    }
    cout<<ans+1<<endl;
}


// 2020-07-15 23:41:12
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  using Work = tuple<int, int, int>; // (x, s, t)
  using P = pair<int, int>;
  int n, q;
  cin >> n >> q;
  vector<Work> works(n);
  rep(i, n) {
    int s, t, x;
    cin >> s >> t >> x;
    works[i] = { x, s-x, t-x };
  }
  sort(ALL(works));
  set<P> ds;
  rep(i, q) {
    int d;
    cin >> d;
    ds.emplace(d, i);
  }
  vector<int> ans(q, -1);
  for(const auto& w : works) {
    int x, s, t;
    tie(x, s, t) = w;
    auto it = ds.lower_bound({ s, -1 });
    while(it != ds.end() && (*it).first < t) {
      int d, qi;
      tie(d, qi) = *it;
      ans[qi] = x;
      it++;
      ds.erase(prev(it));
    }
  }
  for(const auto x : ans) cout << x << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const ll oo = 1e18;
const int MOD = 1000000007;
const int N = 300010;
#define x first
#define y second
#define pb push_back
#define mp make_pair

int n , m , dp[1 << 16][16], comp[1 << 16], cost[16][1 << 16], vis[1 << 16],val[1<<16], vsId;
struct edge {
	int s , t , c;
};
edge E[16 * 16];
int solve(int msk , int p){
	if(p == n-1)return !msk?0:-1e9;
	int &ret = dp[msk][p];
	if(ret != -1)return ret;
	ret = -1e9;
	for (int i = 0; i < n; ++i){
		if((msk&(1<<i))>0 && cost[i][1<<p]){
			ret = max(ret,cost[i][1<<p]+solve(msk^(1<<i),i));
		}
	}
	return ret;
}
ll all = 0;
vector<int> nodes;
int calc(int msk){
	if(!msk)return 0;
	if(vis[msk]==vsId)return val[msk];
	vis[msk] = vsId;
	int &ret = val[msk];
	ret = -1e9;
	for(int sub = msk ; sub > 0 ; sub=(sub-1)&msk){
		for(int u = 0 ; u < nodes.size() ; ++u){
			int j = nodes[u];
			ret = max(ret,cost[j][sub]+comp[sub]+calc(msk^sub));
		}
	}
	return ret;
}

int main() {
	memset(dp,-1,sizeof dp);
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) {
		scanf("%d%d%d", &E[i].s, &E[i].t, &E[i].c);
		E[i].s--, E[i].t--;
		all += E[i].c;
	}
	for (int i = 0; i < n; ++i) {
		for (int msk = 0; msk < (1 << n); ++msk) {
			for (int j = 0 ; j < m ; ++j) {
				if (E[j].t == i)
					swap(E[j].s, E[j].t);
				if (E[j].s == i && (msk & (1 << E[j].t)) > 0) {
					cost[i][msk] += E[j].c;
				}
			}
		}
	}
	for (int msk = 0; msk < (1 << n); ++msk) {
		for (int j = 0 ; j < m ; ++j) {
			if((msk & (1 << E[j].s)) > 0 && (msk & (1 << E[j].t)) > 0){
				comp[msk] += E[j].c;
			}
		}
	}
	ll ans = oo;
	for (int msk = 0 ; msk < (1<< n); ++msk){
		if((msk&(1<<0))==0||(msk&(1<<(n-1)))==0)continue;
		if(solve(msk^(1<<0),0) < 0)continue;
		nodes.clear();
		vsId++;
		for(int i = 0 ; i < n ; ++i)
			if((msk&(1<<i))>0)nodes.pb(i);
		ans = min(ans,all-solve(msk^(1<<0),0)-calc(~msk&((1<<n)-1)));
	}
	printf("%lld\n",ans );
	return 0;
}


#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, h, w, a, b;
  scanf("%lld%lld%lld%lld", &h, &w, &a, &b);
  for(i = 0; i < h; ++i) {
    for(j = 0; j < w; ++j) printf("%d", (i < b) ^ (j < a));
    printf("\n");
  }
  return 0;
}

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

int main() {
    int H, W; cin >> H >> W;
    int A, B; cin >> A >> B;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if ((i < B && j < A ) || (B <= i && A <= j)) cout << '0';
            else cout << '1';
        }
        cout << '\n';
    }
    cout << endl;
}


#include<cstdio>
#define MAXN 100010
int gcd(int a,int b)
{
	while(b)
	{
		int t=a;a=b;b=t%b;
	}
	return a;
}
int n,a[MAXN];
bool dfs()
{
	int cnt0=0,cnt1=0;
	for(int i=1;i<=n;i++)
		(a[i]&1)?cnt1++:cnt0++;
	if(cnt0&1) return 1;
	if(cnt1>1) return 0;
	for(int i=1;i<=n;i++)
		if(a[i]&1)
		{
			if(a[i]==1) return 0;
			a[i]--;
			break;
		}
	int d=a[1];
	for(int i=2;i<=n;i++)
		d=gcd(a[i],d);
	for(int i=1;i<=n;i++)
		a[i]/=d;
	return !dfs();
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	if(dfs()) printf("First\n");
	else printf("Second\n");
}

#include <cstdio>
typedef long long lint;
int const N=1e5+10;
int n,a[N];
int gcd(int x,int y)
{
    if(x==-1 || y==-1) return -x*y;
    if(x==0) return y;
    else return gcd(y%x,x);
}
int g1[N],g2[N];
int main()
{
    scanf("%d",&n);
    lint sum=0;
    for(int i=1;i<=n;i++) scanf("%d",&a[i]),sum+=a[i];
    if(n%2==0)
    {
        if(sum%2==1) printf("First");
        else printf("Second");
        return 0;
    }
    if(sum%2==0) {printf("First"); return 0;}
    int cur=0;
    while(true)
    {
        bool flag=false;
        sum=0;
        for(int i=1;i<=n;i++) sum+=a[i];
        g1[0]=-1; g2[n+1]=-1;
        for(int i=2;i<=n;i++) g1[i]=gcd(g1[i-1],a[i]);
        for(int i=n-1;i>=1;i--) g2[i]=gcd(g2[i+1],a[i]);
        int g;
        for(int i=1;i<=n&&!flag;i++)
        {
            if(a[i]==1) continue;
            g=gcd(gcd(g1[i-1],g2[i+1]),a[i]-1);
            if(((sum-1)/g)%2==1) flag=true;
        }
        if(flag)
            for(int i=1;i<=n;i++) a[i]/=g;
        else
        {
            if(cur==0) printf("Second");
            else printf("First");
            return 0;
        }
        cur^=1;
    }
    return 0;
}