#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

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

const int mod = 1000000007;
//const int mod = 998244353;

signed main(){

    int B, C; cin >> B >> C;
    int ans = 0;
    if(B > 0){
        //[-B,B]
        if(C >= 2 * B) ans++;
        ans += min(B, C / 2 + 1);
        ans += min(B, (C - 1) / 2 + 1);
        //(-INF,-B)
        ans += (C - 1) / 2;
        //(B,INF)
        if(C >= 4) ans += (C - 4) / 2 + 1;
    }else if(B < 0){
        //(-INF,B]
        ans += C / 2 + 1;
        //[-B,INF)
        ans += (C - 1) / 2 + 1;
        //(B,-B)
        if(C >= 2 * (-B) + 1) ans++;
        ans += min(-B - 1, (C - 1) / 2);
        if(C >= 2) ans += min(-B - 1, (C - 2) / 2);

    }else if(B == 0){
        ans += C / 2 + 1;
        ans += (C - 1) / 2;
    }
    Out(ans);

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

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

	long long int B,C;
	long long int res = 0;
	vector <pair<long long int,long long int>> seg;

	cin >> B >> C;

	//1. 빼는 경우
	long long int L = B - (C/2);
	long long int R = B;
	seg.push_back(make_pair(L,R));
	//2. 빼고 나서 -1을 곱하는 경우
	L = -B;
	R = -(B - ((C-1)/2));
	if(L<R)
	{
		seg.push_back(make_pair(L,R));
	}
	else
	{
		seg.push_back(make_pair(R,L));
	}
	//3. -1을 곱하고 빼는 경우
	L = -B;
	R = -B - ((C-1)/2);
	if(L<R)
	{
		seg.push_back(make_pair(L,R));
	}
	else
	{
		seg.push_back(make_pair(R,L));
	}
	//4. -1을 곱하고 빼고 -1을 곱하는 경우
	L = B;
	R = B + ((C-2)/2);
	if(L<R)
	{
		seg.push_back(make_pair(L,R));
	}
	else
	{
		seg.push_back(make_pair(R,L));
	}

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

	L = -2e18;
	R = -2e18;

	for(int i=0;i<seg.size();i++)
	{
	//	cout << L << ' ' << R << ' ' << seg[i].first << ' ' << seg[i].second << '\n';
		if(R < seg[i].first)
		{
			if(R!=-2e18)
			{
				res += (R-L+1);
			}
			L = seg[i].first;
			R = seg[i].second;
		}
		else
		{
			R = max(R,seg[i].second);
		}
	}
	if(R!=-2e18)
	{
		res += (R-L+1);
	}

	cout << res << '\n';

	return 0;
}


#ifdef LOGX
#define _GLIBCXX_DEBUG
#endif
#include <bits/extc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;

/*---------macro---------*/
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define mybit(i,j) (((i)>>(j))&1)

/*---------type/const---------*/
typedef long long ll;
typedef unsigned long long ull;
typedef std::string::const_iterator state; //構文解析
const int big=1000000007;
//const int big=998244353;
const double EPS=1e-8; //適宜変える
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char newl='\n';
struct{
    constexpr operator int(){return -int(1e9)-10;}
    constexpr operator ll(){return -ll(1e18)-10;}
}neginf;
struct{
    constexpr operator int(){return int(1e9)+10;}
    constexpr operator ll(){return ll(1e18)+10;}
    constexpr auto operator -(){return neginf;}
}inf;

/*---------debug---------*/
#ifdef LOGX
#include <template/debug.hpp>
#else
#define dbg(...) ;
#define dbgnewl ;
#define prt(x) ;
#define _prt(x) ;
#endif

/*---------function---------*/
template<typename T> T max(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=max(ans,elem);}return ans;}
template<typename T> T min(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=min(ans,elem);}return ans;}
template<typename T,typename U> bool chmin(T &a,const U b){if(a>b){a=b;return true;}return false;}
template<typename T,typename U> bool chmax(T &a,const U b){if(a<b){a=b;return true;}return false;}
bool valid(int i,int j,int h,int w){return (i>=0 && j>=0 && i<h && j<w);}
template<class T,class U>T expm(T x,U y,const ll mod=big){T res=1;while(y){if(y&1)(res*=x)%=mod;(x*=x)%=mod;y>>=1;}return res;}
template<class T,class U>T exp(T x,U y){T res=1;while(y){if(y&1)res*=x;x*=x;y>>=1;}return res;}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.precision(10);
/*------------------------------------*/

    char a,b,c;cin >> a >> b >> c;
    cout << b << c << a << newl;
}

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

#define ll long long
#define fo(i, k, n)  for(int i = k; i < n; i++)
#define deb(x)       cout<<#x<<" = "<<x<<endl;
#define el endl
#define ff first
#define ss second
#define pb push_back

void solve(){
    string s;
    cin>>s;
    for(int i = 1; i < s.length(); i++){
      cout<<s[i];
    }
    cout<<s[0];
}

int main()
{
    int t = 1;
    // cin>>t;
    while(t--){
        solve();
        cout<<endl;
    }
    return 0;
}


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

#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) {
    return uniform_int_distribution<int>(l, r) (rng);
}

const int N = 105;

int mod;
int dp[N][N*N*N];

int main() {
//    freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, K;
    cin >> n >> K >> mod;

    dp[0][0] = 1;
    int sum = 0;
    for(int i = 1; i <= n; i++) {
        sum += K * i;
        for(int s1 = 0; s1 < i; s1++) {
            int ways = 0;
            for(int s = s1; s <= sum; s += i) {
                ways += dp[i-1][s];
                if(ways >= mod) ways -= mod;
                if(s-(K+1)*i >= 0) {
                    ways -= dp[i-1][s-(K+1)*i];
                    if(ways < 0) ways += mod;
                }
                dp[i][s] = ways;
//                debug(), dbg(i), dbg(s), dbg(dp[i][s]);
            }
        }
    }
    for(int avg = 1; avg <= n; avg++) {
        int ways = 0;
        for(int s = 0; s <= sum; s++) {
            ways += 1ll*dp[avg-1][s]*dp[n-avg][s]%mod;
            if(ways >= mod) ways -= mod;
        }
        ways = 1ll*ways*(K+1)%mod;
        ways--;
        if(ways < 0) ways += mod;
        cout << ways << "\n";
    }
}

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

#ifdef LOCAL
#include "/debug.h"
#else
#define db(...)
#endif

#define all(v) v.begin(), v.end()
#define pb push_back
using ll = long long;
const int NAX = 2e5 + 5, MOD = 1000000007;

ll dp_mask[1 << 16][17][17];

int64_t solveCase(int64_t H, int64_t W, int64_t A, int64_t B)
{
    // TODO: edit here
    memset(dp_mask, -1, sizeof dp_mask);
    function<ll(int, int, int)> solve = [&](int mask, int a, int b) -> ll {
        if (a < 0 || b < 0)
            return 0;
        int cnt = __builtin_popcount(mask);
        if (cnt == H * W)
        {
            auto ret = a == 0 && b == 0;
            db("basecase", bitset<16>(mask), a, b, ret, cnt);
            return ret;
        }
        auto &ret = dp_mask[mask][a][b];
        if (ret >= 0)
            return ret;
        ret = 0;
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                int curr = i * W + j;
                if ((mask >> curr) & 1)
                {
                }
                else
                {
                    ret += solve(mask | (1 << curr), a - 1, b);
                    if (i + 1 < H)
                    {
                        int curr2 = (i + 1) * W + j;
                        if (mask & (1 << curr2))
                            ;
                        else
                            ret += solve(mask | (1 << curr) | (1 << curr2), a, b - 1);
                    }
                    if (j + 1 < W)
                    {
                        int curr2 = i * W + j + 1;
                        if (mask & (1 << curr2))
                            ;
                        else
                            ret += solve(mask | (1 << curr) | (1 << curr2), a, b - 1);
                    }
                    db("midloop", bitset<16>(mask), a, b, ret, cnt);
                    return ret;
                }
            }
        }
        db("endloop", bitset<16>(mask), a, b, ret, cnt);
        return ret;
    };
    return solve(0, B, A);
}

// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main()
{
#ifndef LOCAL
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    constexpr char endl = '\n';
    int64_t H, W, A, B;
    cin >> H >> W >> A >> B;
    auto ans = solveCase(H, W, A, B);
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int res=0;
	bool zf=0;
	char c;
	while(((c=getchar())<'0'||c>'9')&&c!='-');
	if(c=='-')zf=1;
	else res=c-'0';
	while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
	if(zf)return -res;
	return res;
}
const int N=2e5+5;
int dta[N];
vector<int>G[N];
int ct,vi[N];
void dfs(int x){
	vi[x]=1,++ct;
	for(register int i=0;i<G[x].size();++i){
		int v=G[x][i];
		if(!vi[v]){
			dfs(v);
		}
	}
	return;
}
signed main(){
	int n=read();
	for(register int i=1;i<=n;++i){
		dta[i]=read();
	}
	for(register int i=1;i<n-i+1;++i){
		G[dta[i]].push_back(dta[n-i+1]),
		G[dta[n-i+1]].push_back(dta[i]);
	}
	int A=0;
	for(register int i=1;i<=200000;++i){
		if(vi[i]){
			continue;
		}
		ct=0;
		dfs(i);
		A+=ct-1;
	}
	printf("%d\n",A);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using pii = pair<i64, i64>;
#define rep(i, n) for (i64 i = 0; i < i64(n); i++)
#define per(i, n) for (i64 i = n - 1; i >= 0; i--)
#define REP(i, a, b) for (i64 i = a; i < i64(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#ifdef LOCAL
#define dbg(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug(__VA_ARGS__)
#else
#define dbg(...)
#endif
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) {
    os << '(' << pa.first << ',' << pa.second << ')'; return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    for (auto& x : vec) { os << x << ' '; } return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &mat) {
    os << endl; for (auto& vec : mat) { os << vec << endl; } return os;
}
void debug() { cerr << endl; }
template <typename Head, typename... Tail> void debug(Head H, Tail... T) {
    cerr << " " << H; debug(T...);
}
template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1 << 30) - 1;
const i64 LINF = (1LL << 62) - 1;

int n, m;
vector<int> G[20];
vector<int> color(20, -1);

i64 dfs(vector<int> &component, int pos = 0) {
    if (pos == (int) component.size()) {
        return 1;
    }

    i64 ret = 0;

    int now = component[pos];

    rep(i, 3) {
        bool ok = 1;
        for (auto& to : G[now]) {
            if (color[to] == i) ok = 0;
        }
        color[now] = i;
        if (ok) {
            ret += dfs(component, pos + 1);
        }
        color[now] = -1;
    }
    return ret;
}

vector<vector<int>> components;
bool visited[20];

vector<int> bfs(int v) {
    vector<int> ret;
    visited[v] = 1;
    queue<int> que;
    ret.push_back(v);
    que.push(v);
    while (!que.empty()) {
        int now = que.front();
        que.pop();
        for (int& to : G[now]) {
            if (visited[to]) continue;
            visited[to] = 1;
            que.push(to);
            ret.push_back(to);
        }
    }
    return ret;
}

void solve() {
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    rep(i, n) {
        if (!visited[i]) {
            components.push_back(bfs(i));
        }
    }

    i64 ans = 1;
    for (auto &component : components) {
        ans *= dfs(component);
    }
    cout << ans << endl;
}

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


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e+7;
const ld PI = acos(-1);
const ld EPS = 1e-8;
const ll LINF = 1LL<<60;
const int INF = 1LL<<17;
#define rep(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define rrep(i, a, b) for(ll i=b-1; a<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
ll ceil(ll a, ll b) {if(a==0) return 0; return (a-1)/b+1;}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string YES[2] = {"NO", "YES"};
string yes[2] = {"No", "Yes"};

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<998244353>;
struct UnionFind{

    vector<ll> par;
    UnionFind(ll n) : par(n, -1){}

    int root(int x){
        if(par[x]<0) return x;
        return par[x] = root(par[x]);
    }

    bool same(int a, int b){
        return root(a)==root(b);
    }
    void unite(int a, int b){
        int x=root(a), y=root(b);
        if(same(x, y)) return;
        if(y<x) swap(x, y);
        par[x] += par[y];
        par[y] = x;
    }
    int size(int x){
        return -par[root(x)];
    }

};

int main(){
    ll n, k;    cin >> n >> k;
    vector<vector<ll>> g(n, vector<ll>(n));
    rep(i, 0, n) rep(j, 0, n) cin >> g[i][j];
    mint res=1;
    rep(t, 0, 2){
        UnionFind tree(n);
        rep(i, 0, n){
            rep(j, i+1, n){
                bool flag=true;
                rep(p, 0, n){
                    if(t){
                        if(g[i][p]+g[j][p]>k) flag = false;
                    }else{
                        if(g[p][i]+g[p][j]>k) flag = false;
                    }
                }
                if(flag) tree.unite(i, j);
            }
        }
        set<ll> st;
        rep(i, 0, n) st.insert(tree.root(i));

        for(auto x: st){
            mint sum = 1;
            rep(i, 1, tree.size(x)+1) sum *= i;
            res *= sum;
        }
    }

    cout << res << endl;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
struct edge{
	int to,next;
}e[10000];
int n,m,a[30],head[30],cnt,ans=1,res,t,b[30];
bool vis[30];
inline void add(int u,int v){
	cnt++;
	e[cnt].to=v;
	e[cnt].next=head[u];
	head[u]=cnt;
}
inline void dfs1(int u){
	for(int i=head[u];i;i=e[i].next){
		int v=e[i].to;
		if(vis[v])continue;
		vis[v]=1;
		b[++t]=v;
		dfs1(v);
	}
}
inline void dfs(int u,int s){
	bool tag[4],flag=0;
	memset(tag,0,sizeof(tag));
	int sum=0;
	for(int i=head[u];i;i=e[i].next){
		int v=e[i].to;
		if(a[v]&&!tag[a[v]])tag[a[v]]=1,sum++;
	}
	if(sum==3)return;
	if(s==t){
		a[u]=0;
		for(int i=1;i<=3;i++)if(!tag[i])res++;
		return;
	}
	for(int j=1;j<=3;j++)
	if(!tag[j]){
		flag=0;
		a[u]=j;
		for(int i=head[u];i;i=e[i].next){
			int v=e[i].to;
			if(a[v])continue;
			flag=1;
			dfs(v,s+1);
			break;
		}
		if(!flag){
		    for(int i=1;i<=t;i++)
		    if(!a[b[i]]){
			    dfs(b[i],s+1);
			    break;
		    }
	    }
	}
	a[u]=0;
}
signed main(){
	scanf("%lld%lld",&n,&m);
	for(int i=1,x,y;i<=m;i++){
		scanf("%lld%lld",&x,&y);
		add(x,y);
		add(y,x);
	}
	for(int i=1;i<=n;i++)
	if(!vis[i]){
		vis[i]=1;
		t=1;
		b[1]=i;
		dfs1(i);
		//cout<<t<<endl;
		res=0;
		dfs(i,1);
		ans*=res;
	}
	printf("%lld",ans);
	return 0;
}


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

const ll INF = 1L << 60;

struct edge { int to; ll cost; int k; };

struct graph{
    int V;
    vector<vector<edge>> G;
    vector<ll> d;

    graph(int n): V(n) {
        G.resize(V);
        d.resize(V);
        rep(i, V) d[i] = INF;
    }

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

    void dijkstra(int s) {
        d[s] = 0;
        priority_queue<P, vector<P>, greater<P>> que; // min-heap
        que.push(P(0, s));  // d[i], i
        while (!que.empty()) {
            P p = que.top(); que.pop();
            int v = p.second;
            if (d[v] < p.first) continue;
            for (auto e : G[v]) {
                if (d[v] % e.k == 0) {
                    if (d[e.to] > d[v] + e.cost) {
                        d[e.to] = d[v] + e.cost;
                        que.push(P(d[e.to], e.to));
                    }
                } else {
                    if (d[e.to] > d[v] + e.cost + e.k - (d[v] % e.k)) {
                        d[e.to] = d[v] + e.cost + e.k - (d[v] % e.k);
                        que.push(P(d[e.to], e.to));
                    }
                }
            }
        }
    }
};

int main()
{
    io;
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    graph G(n);
    rep(i, m) {
        int a, b, t, k;
        cin >> a >> b >> t >> k;
        G.add_edge(a-1, b-1, t, k);
    }
    G.dijkstra(x-1);
    if (G.d[y-1] == INF) cout << -1 << endl;
    else cout << G.d[y-1] << endl;
    return 0;
}

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

const int INF = 1e9;
const long long inf = 1LL<<60;
using ll = long long;

int main(){
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  auto solve = [&]() -> ll {
    deque<ll> a, b;
    for (int i=0; i<n; i++) {
      if (s[i] == '1') a.push_back(i);
      if (t[i] == '1') b.push_back(i);
    }
    if (a.size() < b.size() || (b.size() - a.size()) % 2 == 1) return -1;
    auto twopop = [&]() -> ll {
      ll res = a[1] - a[0];
      a.pop_front(), a.pop_front();
      return res;
    };
    ll res = 0;
    for (auto id : b) {
      while (!a.empty() && a[0] < id) {
        if (a.size() < 2) return -1;
        res += twopop();
      }
      if (a.empty()) return -1;
      res += a[0] - id;
      a.pop_front();
    }
    if (a.size() % 2 == 1) return -1;
    while (!a.empty()) res += twopop();
    return res;
  };
  cout << solve() << endl;
}


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

using namespace std;

#define ll long long
#define reps(i, a, b) for(int i = a; i < b; i++)
#define rreps(i, a, b) for(int i = a-1; i >= b; i--)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) rreps(i, n, 0)
#define P pair<int, int>
#define vec vector<int>
#define mat vector<vec>

const ll mod = 998244353;
const int INF = 1001001001;

struct mint {
    ll x;
    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 {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=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 {
        mint res(*this);
        return res/=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 h, w;
    cin >> h >> w;
    string s[h];
    rep(i, h){
        cin >> s[i];
    }
    mint ans(1);
    rep(i, h){
        set<char> t;
        int x = i;
        int y = 0;
        while(x >= 0 && y < w){
            t.insert(s[x][y]);
            x--;
            y++;
        }
        if(t.size() == 3){
            ans *= 0;
        }else if(t.size() == 2){
            if(t.find('.') == t.end()){
                ans *= 0;
            }else{
                ans *= 1;
            }
        }else{
            if(t.find('.') == t.end()){
                ans *= 1;
            }else{
                ans *= 2;
            }
        }
    }
    reps(i, 1, w){
        set<char> t;
        int x = h-1;
        int y = i;
        while(x >= 0 && y < w){
            t.insert(s[x][y]);
            x--;
            y++;
        }
        if(t.size() == 3){
            ans *= 0;
        }else if(t.size() == 2){
            if(t.find('.') == t.end()){
                ans *= 0;
            }else{
                ans *= 1;
            }
        }else{
            if(t.find('.') == t.end()){
                ans *= 1;
            }else{
                ans *= 2;
            }
        }
    }
    cout << ans << endl;
}

#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

const int N = 510, mod = 998244353;

int n, m;
char a[N][N];
int c[2 * N];

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

    for(int i = 1; i <= n; i ++) scanf("%s", a[i] + 1);

    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= m; j ++)
            if(a[i][j] == 'R') c[i + j] |= 1;
            else if(a[i][j] == 'B') c[i + j] |= 2;

    int res = 1;
    for(int i = 2; i <= n + m; i ++)
        if(c[i] == 0) res = 2 * res % mod;
        else if(c[i] == 3) res = 0;

    printf("%d\n", res);
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int arr[6];
    for(int i=0;i<6;i++){
        arr[i]=6-i;
    }
    int x=arr[a-1]+arr[b-1]+arr[c-1];
    cout<<x;

  return 0;
}

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

int main()
{
  vector<int> a(3);
  int sum(0);
  for(auto &x:a)
  {
    cin>>x;
    sum=sum+x;
  }
  cout<<(21-sum);
  return 0;
}


#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <queue>
#include <random>

using namespace std;

const long long MAXT = 1000000007;

int a, b;
vector<int> res;

int main() {
    cin >> a >> b;
    int minx = min(a, b);
    int maxx = max(a, b);
    for (int i = 0;i < minx-1;i ++) {
        res.push_back(i+1);
        res.push_back(-(i+1));
    }
    int sum = 0;
    for (int i = minx;i <= maxx;i ++) {
        if (minx == a) {
            res.push_back(-i);
            sum += (-i);
        } else {
            res.push_back(i);
            sum += i;
        }
    }
    res.push_back(-sum);
    for (int i = 0;i < res.size();i ++) {
        if (i == 0) cout << res[i];
        else cout << " " << res[i];
    }
    cout << endl;
    return 0;
}

#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
#include <cassert>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); }
void Yes() { cout << "Yes" << endl; exit(0); }
void No() { cout << "No" << endl; exit(0); }

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

	bool is_swap = false;
	if (A < B)
	{
		is_swap = true;
		swap(A, B);
	}

	int sum_a = 0;
	for (int i = 1; i <= A; i++)
	{
		sum_a += i;
	}
	int sum_b = 0;
	for (int i = 1; i <= B; i++)
	{
		sum_b += i;
	}

	int fix = is_swap ? -1 : 1;
	for (int i = 1; i <= A; i++)
	{
		cout << fix * i << " ";
	}
	for (int i = 1; i < B; i++)
	{
		cout << fix  * -i << " ";
	}
	cout << fix * (-B - (sum_a - sum_b)) << " ";
	cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;++i)
#define mp make_pair
#define pb push_back
#define size sze
#define inf 998244353
int n,k;
vector<int> g[210000];
int v[210000],dep[210000];
int q[210000];
int f[210000][20],size[210000],son[210000],minp[210000];
int father[210000],root;
struct node
{
    int adj,valid,next;
}edge[2*210000];
int gh[210000],top;
void addedge(int x, int y) {
	edge[++top].adj = y;
	edge[top].valid = 1;
	edge[top].next = gh[x];
	gh[x] = top;
}
void get_size(int x, int root=0) {
	size[x] = 1; son[x] = 0;
	int dd = 0;
	for (int p=gh[x]; p; p=edge[p].next)
		if (edge[p].adj != root && edge[p].valid) {
			get_size(edge[p].adj, x);
			size[x] += size[edge[p].adj];
			if (size[edge[p].adj] > dd) {
				dd = size[edge[p].adj];
				son[x] = edge[p].adj;
			}
		}
}
int getroot(int x) {
	get_size(x);
	int sz = size[x];
	while (size[son[x]] > sz/2)
		x = son[x];
	return x;
}
int dc(int x,int fa) {
	x = getroot(x);
    father[x]=fa;
	for (int p=gh[x]; p; p=edge[p].next)
		if (edge[p].valid) {
			edge[p].valid = 0;
			edge[p^1].valid = 0;
			dc(edge[p].adj,x);
		}
    return x;
}
bool cmp(int x,int y)
{
    return dep[x]>dep[y];
}
void dfs(int x,int pre,int depp)
{
    f[x][0]=pre;
    for(int i=1;i<=17;i++)f[x][i]=f[f[x][i-1]][i-1];
    dep[x]=depp;
    for(int p=gh[x];p;p=edge[p].next)
        if (edge[p].adj!=pre)dfs(edge[p].adj,x,depp+1);
}
int jump(int x,int d)
{
    int delta=dep[x]-d;
    for(int i=17;i>=0;i--)
        if (delta & (1<<i))x=f[x][i];
    return x;
}
int lca(int x,int y)
{
    if (dep[x]<dep[y])swap(x,y);
    x=jump(x,dep[y]);
   // cout<<x<<" "<<y<<endl;
    if (x==y)return x;
    for(int i=17;i>=0;i--)
        if (f[x][i]!=f[y][i])
        {
            x=f[x][i];
            y=f[y][i];
        }
    return f[x][0];
}
int dis(int x,int y)
{
    return dep[x]+dep[y]-2*dep[lca(x,y)];
}
void insert(int x)
{
    int now=x;
    while (now!=0)
    {
        if (minp[now]==n+1 || dis(now,x)<dis(now,minp[now]))minp[now]=x;
        now=father[now];
    }
}
int get(int x)
{
    int ret=2147483647;
    int now=x;
    while (now!=0)
    {
        if (minp[now]!=n+1)ret=min(ret,dis(x,minp[now]));
        now=father[now];
    }
    return ret;
}
bool check(int lim)
{
    for(int i=1;i<=n;i++)minp[i]=n+1;
    int tot=0;
    for(int i=1;i<=n;i++)
    {
        //cout<<q[i]<<endl;
        if (get(q[i])>lim)
        {
            int fa=jump(q[i],max(dep[q[i]]-lim,0));
            insert(fa);
            tot++;
        }
        if (tot>k)return 0;
    }
    return 1;
}

int main()
{
    cin>>n>>k; top=1;
    for(int i=1;i<n;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        addedge(x,y);
        addedge(y,x);
    }

    dfs(1,0,0);

    root=dc(1,0);
    //cout<<lca(3,2)<<" "<<lca(3,5)<<" "<<lca(4,5)<<endl;
    for(int i=1;i<=n;i++)q[i]=i;
    sort(q+1,q+n+1,cmp);
    long long l=1; long long r=n;

    //for(int i=1;i<=n;i++)cout<<father[i]<<" "; puts("");
    while (l<r)
    {
        int mid=(l+r)/2;
       // cout<<mid<<endl;
        if (check(mid))r=mid;
        else l=mid+1;
    }
    cout<<l<<endl;
    return 0;
}

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

#define pb push_back
#define ppb pop_back
#define int long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define mii map<int, int>
#define pii pair<int, int>
#define sz(a) (a).size()
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ROF(i, a, b) for(int i=b-1; i>=a; i--)
#define all(x) (x).begin(), (x).end()
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define LB lower_bound
#define UB upper_bound
#define FS first
#define SD second
#define INF 1e18
#define MAX_NUM 300001
#define ps(x,y) fixed<<setprecision(y)<<x
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
const int MOD = 1e9 + 7;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define deb(x) cout << #x << " " << x << endl;

ll max(ll a, ll b)
{
    if (a > b) return a;
    return b;
}

ll min(ll a, ll b)
{
    if (a < b) return a;
    return b;
}

int n, m;
vvi graph(22); vi visited(22, 0), comp, color(22, 0);

void DFS(int s) {
    visited[s] = 1;
    comp.pb(s);
    for (auto &c : graph[s]) if (!visited[c]) DFS(c);
}

int calc(int pos) {
    if (pos == sz(comp)) return 1;
    int ans = 0;
    FOR(i, 1, 4) {
        int skip = 0;
        for (auto &c : graph[comp[pos]]) {
            if (color[c] == i) {
                skip = 1;
                break;
            }
        }
        if (skip) continue;
        color[comp[pos]] = i;
        ans += calc(pos + 1);
    }
    color[comp[pos]] = 0;
    return ans;
}

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

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

    cin >> n >> m;

    FOR(i, 0, m) {
        int u, v;
        cin >> u >> v;
        graph[u].pb(v);
        graph[v].pb(u);
    }

    int ans = 1;

    FOR(i, 1, n + 1) {
        if (!visited[i]) {
            DFS(i);
            ans *= calc(0);
            comp.clear();
        }
    }

    cout << ans;

    return 0;
}


/*   --------------------
    |       LOSER        |
    |     ~NOOBOSS~      |
     --------------------
*/
#include <bits/stdc++.h>
using namespace std;
#define      mxx                 LLONG_MAX
#define      mnn                 LLONG_MIN
#define      Y()                 cout<< "YES" <<endl
#define      N()                 cout << "NO"<<endl
#define      endl                "\n"
#define      Ceil(x,y)           ((x+y-1)/y)
#define      sz(s)               (int)s.size()
#define      angle(x)            double(x * acos(-1) / 180.0)
#define      max_3(a,b,c)        max(a, max(b,c))
#define      min_3(a,b,c)        min(a, min(b,c))
#define      gcd(a,b)            __gcd(a,b)
#define      lcm(a,b)           (a*b)/gcd(a,b)
#define      loser               return 0
#define      ll                  long long
#define      PI                  acos(-1)
#define      mem(a,v)            memset(a,v,sizeof(a))
#define      all(v)              v.begin(),v.end()
#define      SORT(v)             sort(v.begin(),v.end())
#define      SRV(v)              sort(v.rbegin(),v.rend())
#define      REV(v)              reverse(v.begin(),v.end())
#define      B                   begin()
#define      E                   end()
#define      V                   vector
#define      F                   first
#define      S                   second
#define      PSB                 push_back
#define      MP                  make_pair
#define      flash               cout.flush()
#define      InTheNameOfGod      ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
constexpr ll MOD = 998244353;
constexpr ll mod = 1e9  + 7;
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
/*-----*/
#define bug1(a)  cerr<<a<<endl;
#define bug2(a,b)  cerr<<a<<" "<<b<<endl;
#define bug3(a,b,c)  cerr<<a<<" "<<b<<" "<<c<<endl;
/*----*/
const ll N=3e5+5;
vector<ll> adj[N];
ll power(ll n,ll p){if(p==0) return 1;if(p==1)return n;if(p%2)return power(n,p-1)*n;else{ll x=power(n,p/2);return x*x;}}
ll modpow(ll a,ll b,ll m){ll ans=1;while(b){if(b&1)ans=(ans*a)%m;b/=2;a=(a*a)%m;}return ans;}
ll nsum(ll num){return (num*(num+1))/2;}
void edge (ll u,ll v) {adj[u].PSB(v) ;adj[v].PSB(u);}
/*------------------START---------------------*/

/*-----*/
void solve(){
   ll n;
   string s;
   cin>>n;
   for(ll i=1;i<=38;i++){
    ll bal=power(3,i);
    ll baki=n-bal;
    ll k=1;
    while(1){
        ll dhon=power(5,k);
        if(dhon==baki){
            cout<<i<<' '<<k<<endl;
            return;
        }
        if(dhon>baki) break;
        k++;
    }
   }
   cout<<"-1"<<endl;

}
/*-----*/
int main(){
   InTheNameOfGod

   ll Test=1;
   //cin>>Test;
   while(Test--){
     solve();
    }
  loser;
}
///////   C O D I N G  I S  L I F E   ///////

#include <bits/stdc++.h>
using namespace std;
using ll = long long;//大きなint型
using P = pair<int,int>;//pair型の型エイリアス
#define rep(i,n) for (int i = 0; i < (n); ++i)//iをnまですすめる。

ll my_pow(ll x, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 0) return my_pow(x * x, n / 2);
    return x * my_pow(x, n - 1);
}
int main(){
    ll n;
    cin >> n;
    for(int i=1;i<50;i++){
        ll p = my_pow(3,i);
        if(p>n) break;
        for(int j=1;j<50;j++){
            ll q = my_pow(5,j);
            if(q>n) break;
            if(n == p+q){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
    return 0;
}


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

struct Edge {
    int to;
};
using Graph = vector<vector<Edge>>;

vector<int> V[200010];

// 深さ優先探索
vector<bool> seen;  // 探索したか記録
void dfs2(const Graph &GG, int v,int cnt) {
    //printf("z");
    seen[v] = true;
    for (auto e : GG[v]) {
        if (!seen[e.to]) {  // 訪問済みでなければ探索
            V[cnt].push_back(e.to);
            dfs2(GG, e.to,cnt);
        }
    }
}

int64 start[200010]={0};
int64 goal[200010]={0};

int main() {
    int n, m;
    int flag=1;
    cin >> n >> m;

    for(int i=0;i<n;i++)
    {
        int64 x=0;
        scanf("%lld",&x);
        start[i]=x;
    }

    for(int j=0;j<n;j++)
    {
        int64 y=0;
        scanf("%lld",&y);
        goal[j]=y;
    }

    Graph G(n);
    for (int i = 0; i < m; i++) {
        //printf("a");
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back({b});
        G[b].push_back({a});
    }
    //printf("a");
    seen.assign(n, false);  // 初期化
    int cnt = 0;

    int64 size=0;
    int64 asum=0;
    int64 bsum=0;

    for (int i = 0; i < n; i++) {
        if (!seen[i]) {
            //printf("a");

            V[cnt].push_back(i);

            dfs2(G, i,cnt);

            size = V[cnt].size();
            asum = 0;
            bsum = 0;
            for(int j=0;j<size;j++)
            {
                //printf("%d ",V[cnt][j]);
                asum+=start[V[cnt][j]];
                bsum+=goal[V[cnt][j]];
            }
            //printf("\nasum=%lld\n",asum);
            //printf("bsum=%lld\n",bsum);
            if(asum!=bsum)flag=0;

            cnt++; // dfsした回数をカウント
        }
    }
    //cout << cnt << endl;
    //cout << flag << endl;

    if(flag)printf("Yes");
    else printf("No");

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double dd;
#define tst int tttt;cin>>tttt;for(int TTTT=1;TTTT<=tttt;TTTT++)
#define nl cout<<"\n";
#define forn(a,b) for(int ii=a;ii<b;ii++)
const ll MOD1=1e9+7;
const ll MOD2=998244353;
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define vi vector<int>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define hhh cout<<"here"<<endl;

ll mod=MOD1;
ll po(ll x,ll y) {y%=mod;ll res=1;while(y>0){if(y&1)res=(res*x);x=(x*x);y>>=1;}return res;}
ll gcd(int a, int b){if(a<b) swap(a,b);if(b==0) return a;return gcd(a%b,b);}

void solve(){
    int n,m;cin>>n>>m;
    vi a(n+1),b(n+1);
    forn(1,n+1)cin>>a[ii];
    forn(1,n+1)cin>>b[ii];
    vector<vi> adj(n+1);
    forn(0,m){
        int u,v;cin>>u>>v;
        adj[u].pb(v);adj[v].pb(u);
    }vector<bool> vis(n+1);
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            vis[i]=true;
            ll p=0,q=0;
            stack<int> st;st.push(i);
            while(!st.empty()){
                int u=st.top();st.pop();
                p+=a[u];q+=b[u];
                for(auto v:adj[u]){
                    if(!vis[v]){
                        vis[v]=true;
                        st.push(v);
                    }
                }
            }if(p!=q){
                cout<<"No";return;
            }
        }
    }cout<<"Yes";
}
int main(){

    // fastio
    // ++*(int*)0;// crash
    // freopen("out.txt","r",stdin);freopen("outt.txt","w",stdout);
    // tst
    {
        solve();nl;
    }
}
/*

*/


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

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, n) for (ll i = a; i < n; ++i)
#define rep_down(i, a, n) for (ll i = a; i >= n; --i)
#define P pair<ll, ll>

#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>

constexpr ll INF = (1ll << 60);
constexpr ll mod = 1000000007;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
ll mypow(ll a, ll n) {
    ll ret = 1;
    rep(i, n) {
        if (ret > (ll)(1e18 + 10) / a) return -1;
        ret *= a;
    }
    return ret;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    ll n;
    cin >> n;
    ll b = 0;
    ll p = 1;
    ll ans = INF;
    while(1){
        ll a = n/p, c = n%p;
        chmin(ans, a+b+c);
        b++;
        p *= 2;
        if(p > n)break;
    }
    cout << ans << endl;
    return 0;
}

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

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

using namespace std;

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

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

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
int A[111], B[111];

int cnt[211];

bool dp[211];

int AB[211], BA[211];

void MAIN() {
    scanf("%d", &N);
    REP (i, N) {
	scanf("%d%d", A+i, B+i);
	if (A[i] != -1) A[i]--;
	if (B[i] != -1) B[i]--;
    }

    bool yes = true;
    REP (i, N) {
	if (A[i] == 2*N-1) yes = false;
	if (B[i] == 0) yes = false;
	if (A[i] != -1 && B[i] != -1 && B[i] <= A[i]) yes = false;

	if (A[i] != -1) cnt[A[i]]++;
	if (B[i] != -1) cnt[B[i]]++;
    }

    if (yes) {
	REP (i, 2*N) {
	    if (cnt[i] >= 2) yes = false;
	}
    }

    if (yes) {
	REP (i, N*2) {
	    AB[i] = -2;
	    BA[i] = -2;
	}
	REP (i, N) {
	    if (A[i] != -1) AB[A[i]] = B[i];
	    if (B[i] != -1) BA[B[i]] = A[i];
	}

	dp[0] = true;
	for (int i=0; i<N*2; i+=2) if (dp[i]) {
	    for (int h=1; i+h+h<=N*2; h++) {
		bool ok = true;
		for (int k=i; ok && k<i+h; k++) {
		    if (AB[k] == -1 && BA[k+h] != -2) ok = false;
		    if (BA[k+h] == -1 && AB[k] != -2) ok = false;
		    if (0 <= AB[k] && AB[k] != k+h) ok = false;
		    if (0 <= BA[k]) ok = false;
		    if (0 <= BA[k+h] && BA[k+h] != k) ok = false;
		    if (0 <= AB[k+h]) ok = false;
		}

		if (ok) dp[i+h+h] = true;
	    }
	}

	yes = dp[N*2];
    }

    puts(yes? "Yes": "No");
}

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


#include <bits/stdc++.h>

template <typename T>
T next() {
    T temp; std::cin >> temp;
    return temp;
}

template <>
int next() {
    int temp; scanf("%d", &temp);
    return temp;
}
template <>
long long next() {
    long long temp; scanf("%lld", &temp);
    return temp;
}
template <>
double next() {
    double temp; scanf("%lf", &temp);
    return temp;
}
template <>
float next() {
    float temp; scanf("%f", &temp);
    return temp;
}

template <typename T1, typename T2>
std::pair<T1, T2> next() {
    std::pair<T1, T2> temp;
    temp.first = next<T1>();
    temp.second = next<T2>();
    return temp;
}

template <typename T>
std::vector<T> next(int n) {
    std::vector<T> temp(n);
    for(int i = 0; i < n; i++)
        temp[i] = next<T>();
    return temp;
}

template <typename T1, typename T2>
std::vector<std::pair<T1, T2>> next(int n) {
    std::vector<std::pair<T1, T2>> temp(n);
    for(int i = 0; i < n; i++)
        temp[i] = next<T1, T2>();
    return temp;
}

template <typename T>
void print(const T &x, char endc = '\n') {
    std::cout << x << endc;
    return;
}
void print(const int &x, char endc = '\n') {
    printf("%d%c", x, endc);
    return;
}
void print(const long long &x, char endc = '\n') {
    printf("%lld%c", x, endc);
    return;
}
void print(const size_t &x, char endc = '\n') {
    printf("%zu%c", x, endc);
    return;
}
void print(const float &x, char endc = '\n') {
    printf("%f%c", x, endc);
    return;
}
void print(const double &x, char endc = '\n') {
    printf("%lf%c", x, endc);
    return;
}

template<typename T1, typename T2>
void print(const std::pair<T1, T2> &p, char sepc = ' ', char endc = '\n') {
    print(p.first, sepc);
    print(p.second, endc);
    return;
}

template<typename T>
void print(const std::vector<T> &v, char sepc = ' ', char endc = '\n') {
    for(const T &e : v) print(e, sepc);
    printf("%c", endc);
    return;
}

template<typename T>
class CountMap {
private:
    std::map<T, int> _cntmap;
    int _totalcnt = 0;

public:
    CountMap() {}

    CountMap(const std::vector<T> &v) {
        for(const T &x : v)
            _cntmap[x]++;
        _totalcnt = v.size();
    }

    void add(const T &x) {
        _cntmap[x]++;
        _totalcnt++;
    }

    void remove(const T &x) {
        if(--_cntmap[x] == 0) {
            _cntmap.erase(x);
        }
        _totalcnt--;
    }

    int count() const {
        return _totalcnt;
    }

    T minElement() const {
        return _cntmap.begin()->first;
    }

    T maxElement() const {
        return _cntmap.rbegin()->first;
    }

    bool empty() const {
        return _cntmap.empty();
    }

    std::vector<T> getElements() const {
        std::vector<T> ret;
        for(auto it = _cntmap.begin(); it != _cntmap.end(); it++)
            ret.push_back(it->first);

        return ret;
    }

    int operator[] (const T &x) const {
        auto it = _cntmap.find(x);
        if(it == _cntmap.end()) return 0;
        return it->second;
    }
};

using namespace std;

const int mod = 998244353;

void eachTC() {
    int N = next<int>();
    vector<long long> A = next<long long>(N);

    if(N == 1) {
        print(A[0] * A[0] % mod);
        return;
    }

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

    vector<long long> multiplier(N);
    multiplier[N-1] = A[N-1];

    for(int i = N-2; i >= 0; i--)
        multiplier[i] = (2 * multiplier[i+1] - A[i+1] + A[i] + mod) % mod;

    long long res = 0;
    for(int i = 0; i < N; i++)
        res = (res + (A[i] * multiplier[i]) % mod) % mod;

    print(res);
}

int main() {
    constexpr bool multipleTC = false;
    int T = multipleTC ? next<int>() : 1;
    while(T--) eachTC();

    return 0;
}

// #pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

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

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

template <class key, class value, class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

// Defines

#define pb push_back
#define ff first
#define ss second
#define quick                    \
    ios::sync_with_stdio(false); \
    cin.tie(0);
#define time cerr << (0.1 * clock()) / CLOCKS_PER_SEC << endl;
#define int long long
typedef pair<int, int> pl;
#define forn(n) for (int i = 0; i < n; i++)
#define endl "\n"
#define all(v) (v).begin(), (v).end()
#define ppc __builtin_popcount
#define ppcll __builtin_popcountll
int power(int a, int n, int md) {
    if (n == 0) {
        return 1;
    } else {
        int res = power(a, n / 2, md);
        res = (res * res) % md;
        if (n % 2 != 0) {
            res = (res * a) % md;
        }
        return res;
    }
}
random_device rndm;
mt19937 grndm(rndm());
void mix(int* a, int* b) { shuffle(a, b, grndm); }

// Constants

const int mod = 1000000007;

// Code begins

void solve() {
    double a, b;
    cin >> a >> b;
    double ans = a*b/100;
    cout << ans << '\n';
}

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


#include <cassert>
#include <cstdint>
#include <iostream>
#include <vector>

#define REP_(i, a_, b_, a, b, ...) \
    for (int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)

using namespace std;
using Int = int64_t;

template <class T>
struct Matrix {
    vector<vector<T>> val;

    Matrix(vector<vector<T>> vec) : val(vec) {}
    Matrix(int64_t n = 1, int64_t m = 1, T v = 0) : val(n, vector<T>(m, v)) {}
    void init(int64_t n, int64_t m, T v = 0) { val.assign(n, vector<T>(m, v)); }
    size_t size() const { return val.size(); }
    vector<T> &operator[](int64_t i) { return val[i]; }
    const vector<T> &operator[](int64_t i) const { return val[i]; }
};

template <class T>
Matrix<T> operator*(const Matrix<T> &A, const Matrix<T> &B) {
    assert(A.size() == B[0].size());
    Matrix<T> R(A.size(), B[0].size());
    for (int64_t i = 0; i < A.size(); ++i)
        for (int64_t j = 0; j < B[0].size(); ++j)
            for (int64_t k = 0; k < B.size(); ++k) R[i][j] += A[i][k] * B[k][j];

    return R;
}

template <class T>
Matrix<T> operator+(const Matrix<T> &A, const Matrix<T> &B) {
    assert(A.size() == B.size() && A[0].size() == B[0].size());
    Matrix<T> R(A.size(), A[0].size());
    for (int64_t i = 0; i < A.size(); ++i) {
        for (int64_t j = 0; j < A[0].size(); ++j) {
            R[i][j] = A[i][j] + B[i][j];
        }
    }
    return R;
}

template <class T>
Matrix<T> operator-(const Matrix<T> &A, const Matrix<T> &B) {
    assert(A.size() == B.size() && A[0].size() == B[0].size());
    Matrix<T> R(A.size(), A[0].size());
    for (int64_t i = 0; i < A.size(); ++i) {
        for (int64_t j = 0; j < A[0].size(); ++j) {
            R[i][j] = A[i][j] - B[i][j];
        }
    }
    return R;
}

template <class T>
vector<T> operator*(const Matrix<T> &A, const vector<T> &B) {
    vector<T> v(A.size());
    for (int64_t i = 0; i < A.size(); ++i) {
        for (int64_t k = 0; k < B.size(); ++k) {
            v[i] += A[i][k] * B[k];
        }
    }
    return v;
}

template <class T>
bool operator==(const Matrix<T> &A, const Matrix<T> &B) {
    assert(A.size() == B.size() && A[0].size() == B[0].size());
    for (int64_t i = 0; i < A.size(); ++i) {
        for (int64_t j = 0; j < A[0].size(); ++j) {
            if (A[i][j] != B[i][j]) {
                return false;
            }
        }
    }
    return true;
}

int main() {
    Int N;
    cin >> N;
    vector<Int> X(N), Y(N);
    REP(i, N) cin >> X[i] >> Y[i];
    Int M;
    cin >> M;
    vector<Matrix<Int>> mats;
    Matrix<Int> mat(3, 3, 0);
    mat[0][0] = 1;
    mat[1][1] = 1;
    mat[2][2] = 1;
    mats.push_back(mat);
    REP(i, M) {
        Int t;
        cin >> t;
        if (t == 1) {
            vector<vector<Int>> a = {{0, 1, 0}, {-1, 0, 0}, {0, 0, 1}};
            Matrix<Int> A(a);
            mat = A * mat;
        } else if (t == 2) {
            vector<vector<Int>> a = {{0, -1, 0}, {1, 0, 0}, {0, 0, 1}};
            Matrix<Int> A(a);
            mat = A * mat;
        } else if (t == 3) {
            Int p;
            cin >> p;
            vector<vector<Int>> a = {{-1, 0, 2 * p}, {0, 1, 0}, {0, 0, 1}};
            Matrix<Int> A(a);
            mat = A * mat;
        } else {
            Int p;
            cin >> p;
            vector<vector<Int>> a = {{1, 0, 0}, {0, -1, 2 * p}, {0, 0, 1}};
            Matrix<Int> A(a);
            mat = A * mat;
        }
        mats.push_back(mat);
    }

    Int Q;
    cin >> Q;
    REP(i, Q) {
        Int a, b;
        cin >> a >> b;
        --b;
        vector<Int> vec = {X[b], Y[b], 1};
        auto res = mats[a] * vec;
        cout << res[0] << " " << res[1] << endl;
    }
}

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define pdd pair<double,double>
#define pii pair<ll,ll>
#define fi first
#define sec second
#define MAXN 1000000000000000005
#define N 300005
#define lgn 20

using namespace std;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

ll n,q,a[300001];
ll bit[3000000];

void update(ll x,ll y) {
    // ll org = a[x];
    a[x] = ((a[x])^y);
    while(x<=n) {
        bit[x] = ((bit[x])^y);
        x+=(x&(-x));
    }
    return;
}

ll query(ll x) {
    ll ret = 0;
    while(x) {
        ret = (ret^(bit[x]));
        x-=(x&(-x));
    }
    return ret;
}

ll query(ll x,ll y) {
    return (query(x-1)^query(y));
}

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

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

   	cin>>n>>q;
    for(ll i=1;i<=n;i++) {
        ll p;
        cin>>p;
        update(i,p);
    }
    while(q--) {
        ll t,x,y;
        cin>>t>>x>>y;
        if(t==1) {
            update(x,y);
        }
        else {
            cout<<query(x,y)<<"\n";
        }
    }
    // for(ll i=1;i<=10;i++) cout<<a[i]<<" ";
    // cout<<"\n";
    // for(ll i=1;i<=10;i++) cout<<bit[i]<<" ";

    return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e9;
const LL INF = 1e9;

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int n;
    cin>>n;
    LL a[n], b[n];

    loop(i,0,n) cin>>a[i];
    loop(i,0,n) cin>>b[i];

    LL mx = 0, ans = 0;

    loop(i,0,n)
    {
        mx = max(mx, a[i]);
        b[i] *= mx;

        ans = max(ans, b[i]);

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

    return 0;
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T>>;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

//head

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int r, c;
  cin >> r >> c;
  vector<vector<P>> G(r*c*2);
  auto num = [&](int i, int j) {
    return i*c + j;
  };
  rep(i, r) rep(j, c-1) {
    int a;
    cin >> a;
    G[num(i, j)].emplace_back(num(i, j+1), a);
    G[num(i, j+1)].emplace_back(num(i, j), a);
  }
  rep(i, r-1) rep(j, c) {
    int b;
    cin >> b;
    G[num(i, j)].emplace_back(num(i+1, j), b);
    G[num(i+1, j)].emplace_back(num(i+1, j)+r*c, 1);
    G[num(i, j)+r*c].emplace_back(num(i, j), 0);
    G[num(i+1, j)+r*c].emplace_back(num(i, j)+r*c, 1);
  }
  PQG<P> q;
  q.emplace(0, 0);
  vi dist(r*c*2, INF);
  dist[0] = 0;
  while(not q.empty()) {
    auto [d, now] = q.top();
    q.pop();
    if(d != dist[now]) continue;
    for(auto [ne, c]:G[now]) {
      if(chmin(dist[ne], d+c)) {
        q.emplace(d+c, ne);
      }
    }
  }
  cout << dist[r*c-1] << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
constexpr long long INF = 1000000000 + 100;
constexpr long long LINF = 1000000000000000000 + 100;
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
#define rrep(i, n) for(int i=(n); i>=0; 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; }

struct edge{ll to, time, cost;};
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;
  vector<ll> prev;

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

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

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

  void dijkstra(ll s){
    rep(i,V){
      d[i] = LINF;
    }
    d[s] = 0;
    priority_queue<pll,vector<pll>, greater<pll> > que;
    que.push(pll(0,s)); //[その頂点への最短コスト候補、頂点番号]
    prev.assign(V, -1);
    while(!que.empty()){
      pll p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
          ll ncost = d[v];
          if(ncost % e.time){
              ncost += e.time - (ncost % e.time);
          }
          ncost += e.cost;
        if(d[e.to]>ncost){
          d[e.to] = ncost;
          prev[e.to] = v;
          que.push(pll(d[e.to],e.to));
        }
      }
    }
  }

  vector<int> get_path(int t){ //頂点tへの最短路
    vector<int> path;
    for(; t != -1;t=prev[t]){
        path.push_back(t);
    }

    reverse(path.begin(), path.end());
    return path;
  }
};

int main(){
    int N, M, X, Y; cin >> N >> M >> X >> Y; X--, Y--;
    graph g(N);
    rep(i, M){
        int a, b; ll t, k; cin >> a >> b >> t >> k; a--, b--;
        g.add_edge(a,b,t,k);
        g.add_edge(b,a,t,k);
    }

    g.dijkstra(X);
    cout << (g.d[Y] == LINF ? -1 : g.d[Y]) << ln;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
	int x = 0,f = 1;
	char c = getchar();
	while(c < '0' || c > '9'){
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9'){
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x * f;
}
const int maxn = 505;
int a[maxn][maxn];
int aa[maxn],bb[maxn];
signed main()
{
	int n; n = read();
	for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) a[i][j] = read();
	int akk = 1e9,pos = 0;
	for(int i=1;i<=n;++i){
		if(a[i][1] < akk){
			pos = i;
			akk = a[i][1];//Au，冲啊！！
		}
	}
	for(int i=1;i<=n;++i) bb[i] = a[pos][i];
	for(int i=1;i<=n;++i) aa[i] = a[i][1] - a[pos][1];//差不多吧
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			if(a[i][j] != aa[i] + bb[j]){
				printf("No\n");
				return 0;
			}
		}
	}
	printf("Yes\n");
	for(int i=1;i<=n;++i) printf("%lld ",aa[i]);
	printf("\n");
	for(int i=1;i<=n;++i) printf("%lld ",bb[i]);
}


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

int n,m;

int main()
{
    cin>>n>>m;
    vector<int> v(m+2);
    v[0] = 0;
    v[m+1] = n+1;
    for(int i=1;i<=m;i++){
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    int mm = n;
    for(int i=1;i<m+2;i++){
        int d = v[i]-v[i-1];
        if(d>1){
            mm = min(d-1,mm);
        }
    }
    int res = 0;
    for(int i=1;i<m+2;i++){
        int d = v[i]-v[i-1];
        if(d>1){
            res += (d-1+mm-1)/mm;
        }
    }
    cout<<res<<endl;
    return 0;
}

#include <bits/stdc++.h>
#define arr(i,n) for(ll i=0;i<n;i++)
#define ARR(i,n) for(ll i=n-1;i>=0;i--)
#define f(i,a,b)  for(ll i=a;i<b;i++)
#define F(i,a,b)  for(ll i=b-1;i>=a;i--)
#define float double
#define PI 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define vi vector<ll>
#define ceil(a,b) ceil(a*1.0/b)
#define vpii vector< pair<ll,ll> >
#define debug(x) cout<<(#x)<<" is "<<(x)<<endl
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define all(v) v.begin(),v.end()
#define inputarr(a,n) for(ll i=0;i<n;++i) cin>>a[i]
#define integer_to_string to_string
#define IOS  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long ll;
using namespace std;
const ll  mod = 1000000000 + 7;
int main()
{
    IOS;
    //code start here
    ll n;
    cin>>n;
    vi v;
    ll x,y;
    ll sum=0,sum1=0,res=0;
    arr(i,n)
    {
        cin>>x>>y;
        sum+=x;
        v.pb(2*x+y);
    }
    sort(all(v));
    ARR(i,v.size())
    {
        sum1+=v[i];
        res++;
        if(sum1>sum) break;
    }
    cout<<res;
    return 0;
}

/*freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);*/

/*For graph
    vector< pair<ll,ll> >graph={{0,1},{1,0},{0,-1},{-1,0}}; //4 direction
    vector< pair<ll,ll> >graph={{0,1},{1,0},{0,-1},{-1,0}
                                {1,1}{1,-1}{-1,1}{-1,-1}}; //8 direction

    int check(int i,int j,int n,int m) //for checking valid or not
    {
     return (i>=0&&i<n&&j>=0&&j<m);
    }
*/


#include<bits/stdc++.h>

using namespace std;

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int          long long
#define rep(i,j,n)   for(int i=j;i<n;i++)
#define scn(a)       scanf("%lld",&a)
#define pri(a)       printf("%lld",a)
#define prinl(a)     printf("%lld\n",a)
#define vec          vector<int>
#define pairs        pair<int,int>
#define srt(v)       sort(v.rbegin(),v.rend())
#define mem(a,b)     memset(a,b,sizeof(a))
#define read(v,w)    vec v(w,0); rep(i,0,w) {cin>>v[i];}
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nline "\n"
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
// typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

//======================== SOLUTION ===============
//code

int getValue(string s) {
    int ans = 0;
    debug(s);
    reverse(all(s));

    int mul = 1;
    int n = s.length();

    rep(i,0,n) {
        ans += (s[i] - '0')*mul;
        mul *= 10;
    }
    debug(ans);
    return ans;
}
void solve() {
   int n,k;
   cin >> n >> k;

   while(k--) {

        debug(n);
        if(n % 200 == 0) {
            n = n/200;
        } else {
            string s = to_string(n);
            s += "200";

            n = getValue(s);
        }
   }

   cout << n;

}

///======== check for test cases =====================

signed main() {
#ifndef ONLINE_JUDGE
    freopen("Error.txt", "w", stderr);
#endif

    int test_case = 1;

    //cin >> test_case;

    while(test_case){
        test_case--;
        solve();
    }

}

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

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(dd t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.f); cerr << ","; _print(p.s); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

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

	ll n,k;
	cin>>n>>k;
	while(k--){
		if(n%200){
			n=n*1000+200;
		}
		else{
			n/=200;
		}
	}
	cout<<n<<"\n";
}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define frfr  freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout)
#define ll long long int
#define wh int T;cin >> T;while(T--)
#define foro(i,n) for(int i=0;i<n;i++)

void solve(){
    int n;
    cin >> n;
    ll t = 0;
    int a[n];
    int b[n];
    foro(i,n){
		cin >> a[i];

	}
    foro(i,n){
		cin >> b[i];

	}
    foro(i,n){
		t += a[i]*b[i];

	}

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

}
int main()
{
    //IOS;

    //wh{
        solve();
    //}
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
template<typename T> using vec = vector<T>;
template<typename K, typename V> using umap = unordered_map<K, V>;
using ll = long long;
using ld = long double;
using str = string;
using pll = pair<ll, ll>;
using vll = vec<ll>;
using vi = vec<int>;
using vs = vec<str>;
using mapll = map<ll, ll>;
using umapll = umap<ll, ll>;
#define _rep(i, n) _repi(i, 0, n)
#define _repi(i, l, r) for (ll i = ll(l); i < ll(r); i++)
#define _get_rep(_1, _2, _3, NAME, ...) NAME
#define rep(...) _get_rep(__VA_ARGS__, _repi, _rep) (__VA_ARGS__)
#define rrep(i, n) for (ll i = ll(n) - 1; 0 <= i; i--)
#define each(v) for (auto v)
#define all(x) x.begin(), x.end()
#define mkpair make_pair
#define is_in(x, l, r) ((l) <= (x) && (x) < (r))
#define read(t, ...) t __VA_ARGS__; isin(cin, __VA_ARGS__)
#define readv(t, v, n) vec<t> v(n); isin(cin, v)
#define readv2(t, v, h, w) vec<vec<t>> v(h, vec<t>(w)); isin(cin, v)
#define readvv(t, va, vb, n) vec<t> va(n), vb(n); rep (i, n) { isin(cin, va[i], vb[i]); }
#define readvvv(t, va, vb, vc, n) vec<t> va(n), vb(n), vc(n); rep (i, n) { isin(cin, va[i], vb[i], vc[i]); }
#define print(...) osout(cout, __VA_ARGS__)
#define dbg(...) osout(cerr, __VA_ARGS__)
const ll inf = numeric_limits<ll>::max() / 2;
template<typename T> bool chmax(T &x, const T &y) { if (x < y) { x = y; return 1; } return 0; }
template<typename T> bool chmin(T &x, const T &y) { if (x > y) { x = y; return 1; } return 0; }
template<typename T> void sort(vec<T> &v) { sort(all(v)); }
template<typename T> void rsort(vec<T> &v) { sort(all(v), greater<T>()); }
template<typename T> void dec(vec<T> &v) { rep (i, v.size()) v[i]--; }
template<typename T> istream& operator >>(istream &is, vec<T> &v) {
    rep (i, v.size()) { cin >> v[i]; } return is;
}
template<typename T1, typename T2> ostream& operator <<(ostream &os, pair<T1, T2> p) {
    if (&os == &cout) { os << p.first << ' ' << p.second; }
    if (&os == &cerr) { os << '(' << p.first << ", " << p.second << ')'; }
    return os;
}
template<typename T> ostream& operator <<(ostream &os, vec<T> v) {
    if (&os == &cout) { rep(i, v.size() - 1) { os << v[i] << ' '; } os << v[v.size() - 1]; }
    if (&os == &cerr) { os << '['; rep(i, v.size() - 1) { os << v[i] << ", "; } os << v[v.size() - 1] << ']'; }
    return os;
}
void isin(istream &_) {}
template<class S, class... T> void isin(istream &is, S &s, T&... t) {
    is >> s; isin(is, t...);
}
void osout(ostream& os) { os << endl; }
template<class S, class... T> void osout(ostream &os, S s, T... t) {
    os << s; if (sizeof...(t)) os << ' '; osout(os, t...);
}
void solve();

int main() {
    #define PRECISION 0

    cin.tie(0);
    ios::sync_with_stdio(false);
    if (PRECISION) {
        cout << fixed << setprecision(15);
        cerr << fixed << setprecision(15);
    }
    solve();
    return 0;
}

void solve() {
  read(ll,n);
  readv(ll,a,n);
  readv(ll,b,n);
  ll t=0;
  rep(i,n)t+=a[i]*b[i];
  print(t==0?"Yes":"No");
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a*a + b*b < c*c) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

#include <ctime>
#include <deque>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <climits>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <regex>
#include <set>
#include <bitset>

const int64_t infl = 1LL << 60;
const int64_t cc = pow(10, 9) + 7;
bool sort_pair(std::pair<int64_t, std::string> origin, std::pair<int64_t, std::string> another){return origin.first > another.first;}
template <typename T> bool chmin(T &a, const T& b) {if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b) {if(a < b) {a = b;return true;}return false;}
std::vector<std::string> list;

int main()
{
    //std::vector< std::pair< int64_t, int64_t > > list;
    std::vector< std::string > str_list;
    std::string str1;
    std::string str2;
    int64_t n,k,l,a,b,c;
    std::cin>> a;
    std::cin>> b;
    std::cin>> c;

    if( pow( a, 2 ) + pow( b, 2 ) < pow( c, 2 ) )
    {
        std::cout<< "Yes";
    }
    else
    {
        std::cout<< "No";
    }
}


#include <bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define vpp vector<pair<pair<ll, ll>, ll>>
#define vp vector<pair<ll, ll>>
#define mk make_pair
#define pb push_back
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define N 1000000007
using namespace std;

void fun()
{
    // code begins
    ll n;cin>>n;
    ll a,b,c;
    b = 0;
    ll k = 1;
    ll ans = n;
    while( k <= n)
    {
        a = n/k;
        c = n%k;
        if( a+b+c < ans)
            ans = a+b+c;
        b++;
        k = k*2;
    }
    cout<<ans;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS;
    ll t; t = 1;
    //cin >> t;
    for (ll i = 1; i <= t; i++)
        fun();
}

#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

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 long long INF = 1LL<<60;
const long long MOD = 1000000007;

int main() {
    ll n; cin >> n;
    ll res = 1e18;
    for (int b=0; b<=60; b++) {
        ll a = n / (1LL << b);
        ll c = n - a * (1LL << b);
        res = min(res, a + b + c);
    }
    cout << res << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<bool> vbl;
typedef vector<vector<bool>> vvbl;

typedef pair<string, ll> pstll;

#define ADD emplace_back
#define MP make_pair
#define __LONG_LONG_MIN__ (-__LONG_LONG_MAX__ - 1)

//#define MOD 1000000007 // 10^9 + 7
//setprecision(10)

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

    vector<string> s(M);
    for (ll i = 0; i < M; i++)
    {
        cin >> s[i];
    }

    sort(s.begin(), s.end(), [](string &s1, string &s2){return s1.size() > s2.size();});
    vector<pstll> mp; // string & how many times it appears;
    for(string si : s)
    {
        bool append = true;
        for(auto &x : mp)
        {
            if(x.first.find(si) != string::npos)
            {
                x.second++;
                append = false;
                break;
            }
        }
        if(append) mp.emplace_back(MP(si, 1));
    }
    sort(mp.begin(), mp.end(), [](pstll &p1, pstll &p2){return p1.second > p2.second;});

    vector<vector<char>> result(N, vector<char>(N, '.'));
    for (ll i = 0; i < N; i++)
    {
        string &si = mp[i].first;
        for (ll j = 0; j < si.size(); j++)
        {
            result[i][j] = si[j];
        }
    }
    for (ll i = N; i < N + 8; i++)
    {
        string &si = mp[i].first;
        for (ll j = 0; j < si.size(); j++)
        {
            result[j][i - 8] = si[j];
        }
    }

    for (ll i = 0; i < N; i++)
    {
        for (ll j = 0; j < N; j++)
        {
            cout << result[i][j];
        }
        cout << endl;
    }

    return 0;
}

/********include********/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
//#include <atcoder/all>

/***/
//#include <iomanip>
//#include <cmath>
#include <bits/stdc++.h>

/********define********/
const int MAX = 510000;
const int MOD = 1000000007;

#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define rrep(i,x) for(long long i=x-1;i>=0;i--)
#define rrepn(i,x) for(long long i=x;i>1;i--)
#define REP(i,n,x) for(long long i=n;i<x;i++)
#define REPN(i,n,x) for(long long i=n+1;i<x;i++)

#define pr printf
#define re return
#define mod 1000000007
//#define mod 998244353
#define inf  INT_MAX//19桁
#define INF 1e18+5//19桁
const double PI=3.14159265358979323846;
#define fi first
#define se second
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define all(x) (x).begin(),(x).end()

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

/********変数宣言********/
//vector<long long> g[200020];
vector<pair<long long,long long>> g[200020];
ll s[200020];
bool used[200020];
//bool dp[100005];

ll A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,Q,R,S,T,U,V,W,X,Y,Z;
double dA,dB,dC,dD,dE,dF,dG,dH,dI,dJ,dK,dL,dM,dN,dO,dP,dQ,dR,dS,dT,dU,dV,dW,dX,dY,dZ;

string sa,sb,sc,sd,se,sf,sg,sh,si,sj,sk,sl,sm,sn,so,sp,sq,sr,ss, su,sv,sw,sx,sy,sz;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin>>N;cin>>M;

	vector<string>v(M);

	map<string,ll>mp;
	ll min,sum;
	min=INF;
	sum=0;

	rep(i,M){
		cin>>v[i];
		min=MIN(min,v[i].size());
		mp[v[i]]++;
	}
	map<string,ll>mp2;
	rep(i,M){
		sum=0;
		for(ll j=min;j<=v[i].size();j++){
			sum+=mp[v[i].substr(0,j)];
		}
		mp2[v[i]]+=sum;
	}
	deque<string> dque;
	for(auto p:mp2){
		dque.push_front(p.fi);
	}
	//sort(p.begin(), p.end());
	ll check;
	check=0;

	ll i;
	i=0;
	ll flg;
	while(check<N*N && i<M){
		string now_str;
		string pre_str;
		now_str=dque[i];

		if(check%N!=0){
			if(i!=0 && pre_str[pre_str.size()-1]==now_str[0]){
				rep(j,now_str.size()-1){
					now_str[j]=now_str[j+1];
				}
				now_str.resize(now_str.size()-1);
			}
		}

		if(check%N+now_str.size()<=N){
			cout<<now_str;
			check+=now_str.size();
			if(check%N==0){
				cout<<"\n";
			}
		}
		else{
			while(check%N!=0){
				cout<<".";
				check++;
			}
			cout<<"\n";
		}
		pre_str=now_str;
		i++;
	}
	re 0;
}


#include <bits/stdc++.h>
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define repD(i,a,n) for(int i=a;i>=(n);--i)

using namespace std;
using ll =   long long;
ll dp[5005][5005];
ll fact(ll n)
{
    if(n==0||n==1)return 1;
    else {
        ll ans = n;
        n--;
        while(n!=1)
        {
            ans *= n;
            n--;
        }
        return ans;
    }
}
set<ll> taken;
ll m;
ll a[5005];
//vector <ll> ones, zeros;
// ll solve(ll i, ll start, ll n)
// {
//     if(i==m)return 0;
//     else {
//         if(dp[i][start]!=-1)return dp[i][start];
//         //a[ones[i]] = 0;
//         ll ans = 100000000000;
//         //a[ones[i]] = 0;
//         ans = min( ans, solve(i+1,start + 1,vis1, vis2,n) + abs(ones[i]-start));
//         ans = min(ans, solve(i+1, start))

//         return dp[i][start] = ans;
//     }
// }
int main()
{
    ll n;
    cin>>n;
    //ll a[n];
    ll i,j;
    string s,t;
    cin>>s>>t;
    set <ll,greater<>> szero,tzero;
    for(i=0;i<n;i++)
    {
        if(s[i]=='0')
        {
            szero.insert(i);
        }
        if(t[i]=='0')
        {
            tzero.insert(i);
        }
    }
    if (tzero.size()!=szero.size()) {
      cout << -1;
      return 0;
   }
    ll f = 0;
    ll ans = 0;
    for(auto it: tzero)
    {
        if(it!=*szero.begin())
        {
            ans++;
        }
        szero.erase(szero.begin());

    }
    if(f)ans = -1;
        cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vll;

typedef vector<vi> vvi;
typedef vector<vll> vvll;

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

typedef vector<pii> vpii;
typedef vector<pll> vpll;

typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second

template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

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

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for(auto z : x) cerr << (f++ ? "," : ""), __print(z); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if(sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef ljuba
#define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif

const char nl = '\n';

void solve() {
    int n;
    cin >> n;
    vi v(n);
    for(auto &z : v)
        cin >> z;
    int mini = *min_element(all(v));

    map<int, int> ma;

    for(auto z : v) {
        for(int i = 1; i * i <= z; ++i) {
            if(z % i == 0) {
                ma[i] = __gcd(ma[i], z);
                if(z / i != i)
                    ma[z/i] = __gcd(ma[z/i], z);
            }
        }
    }

    dbg(ma);

    int ans = 0;
    for(auto z : ma) {
        if(z.fi == z.se && z.fi <= mini)
            ++ans;
    }

    cout << ans << nl;
}

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

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

}


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

int main()
{
    ll s, p;
    cin >> s >> p;
    for(ll i = 1; i * i <= p; i++){
        if(p % i == 0 && i + p / i == s){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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

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

void solve()
{
    ll i,j,b,s,p;
    cin>>s>>p;
    for(i=1;i<=(int)sqrt(p);i++)
    {
    	if(p%i==0)
    	{
    		if(i+(p/i)==s)
    		{
    			cout<<"Yes";
    			return ;
    		}
    	}
    }
    cout<<"No\n";
}

int main()
{
    #ifdef Sudarshan
        freopen("F:/Programming/input.txt", "r", stdin);
        freopen("F:/Programming/output.txt", "w", stdout);
    #endif

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

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


#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define Pii pair<int,int>
#define Pll pair<long long,long long>
#define fi first
#define se second
#define pb push_back
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));

using namespace std;

signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int h,w; cin >> h >> w;
    vector<string> a(h);
    int s,g;
    vector<vector<Pii>> G(h*w+30);
    vector<int> al[30];
    rep(i,h){
        cin >> a[i];
        rep(j,w){
            if(a[i][j]=='S') s=i*w+j;
            else if(a[i][j]=='G') g=i*w+j;
            else if(a[i][j]!='.'&&a[i][j]!='#'){
                int x=(a[i][j]-'a');
                al[x].pb(i*w+j);
            }
        }
    }
    //cout << s <<  " " << g  << endl;
    int dx[]={1,0,-1,0};
    int dy[]={0,1,0,-1};
    rep(i,h){
        rep(j,w){
            rep(k,4){
                if(a[i][j]=='#') continue;
                int nx=i+dx[k],ny=j+dy[k];
                if(0<=nx&&nx<h && 0<=ny&&ny<w && a[nx][ny]!='#'){
                    G[i*w+j].pb({nx*w+ny,1});
                    G[nx*w+ny].pb({i*w+j,1});
                }
            }
        }
    }
    rep(i,26){
        rep(j,al[i].size()){
            G[al[i][j]].pb({h*w+i,1});
            G[h*w+i].pb({al[i][j],0});
        }
    }
    vector<int> d(h*w+30,1e9);
    priority_queue<Pii,vector<Pii>,greater<Pii>> pq; //{dist,v}
    d[s]=0;
    pq.push({0,s});
    while(!pq.empty()){
        Pii tp=pq.top(); pq.pop();
        int v=(int)tp.second;
        if(d[v]<tp.first) continue;
        for(auto u:G[v]){
            if(d[v]+u.se<d[u.fi]){
                d[u.fi]=d[v]+u.se;
                pq.push({d[u.fi],u.fi});
            }
        }
    }
    if(d[g]==1e9) cout << -1 << endl;
    else cout << d[g] << endl;
    return 0;
}
// g++ main.cpp -o main.out && ./main.out

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
template<class T> void chmax(T &a, const T b){ a = max(a, b); }
template<class T> void chmin(T &a, const T b){ a = min(a, b); }
long long gcd(long long a, long long b) { return (a % b) ? gcd(b, a % b) : b; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

template<class T>
vector<pair<T, int>> factorize(T n) {
    vector<pair<T, int>> res;
    for (long long i = 2; (i * i) <= n; i++) {
        if (n % i) continue;
        res.emplace_back(i, 0);
        while((n % i) == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1);
    return res;
}

ll n, ans = LONG_LONG_MAX;
vector<ll> x;
vector<vector<pair<ll, int>>> xf;
map<ll, ll> cnt;

void dfs(ll idx) {
    if (idx == n) {
        ll tmp = 1;
        for(auto &v : cnt) {
            tmp *= v.first;
        }
        chmin(ans, tmp);
        return;
    }
    bool f = false;
    for(auto &v : xf[idx]) {
        if (cnt.count(v.first)) {
            f = true;
            break;
        }
    }
    if (f) {
        dfs(idx + 1);
    }
    else {
        for(auto &v : xf[idx]) {
            if (v.first == 1) continue;
            cnt[v.first]++;
            dfs(idx + 1);
            cnt[v.first]--;
            if (cnt[v.first] == 0) cnt.erase(v.first);
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    cin >> n;
    x.resize(n);
    rep(i, n) cin >> x[i];
    xf.resize(n);
    rep(i, n) xf[i] = factorize(x[i]);
    dfs(0);
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
// #include<atcoder/all>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
// using namespace atcoder;
typedef long long int ll;
typedef long double ld;
typedef long long lint;
const ll INF=(1LL<<62);
const ll LINF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"
#define TO_STRING(VariableName) # VariableName

template <typename T>ostream &operator<<(ostream &out,const vector<T> &v) {rep(i,(int)v.size()-1)cout<<v[i]<<" ";cout<<v[(int)v.size()-1];return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const map<T1, T2> &p) {out << "(" << p.first << ", " << p.second << ")";return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const pair<T1, T2> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template<class T>void debag(const T &obj){cout<<obj<<endl;}

bool solve(){
    ll A,B;cin>>A>>B;

    const ll num=20;

    ll primes[num]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
    // ll primes[num]={2,3};
    ll n=B-A+1;
    vector<int>G(n);

    rep(i,n)rep(j,num){
        if((A+i)%primes[j]==0){
           G[i]+=(1LL<<j);
        }
    }

    vector<vector<ll>>dp(n+1,vector<ll>((1LL<<num),0));

    dp[0][0]=1;

    rep(i,n)rep(j,(1LL<<num)){
        dp[i+1][j]+=dp[i][j];

        //使える？
        if(G[i] & j)continue;
        dp[i+1][G[i] | j]+=dp[i][j];
    }

    ll ans=0;
    // rep(i,n+1)cout<<dp[i]<<endl;
    rep(j,(1LL<<num))ans+=dp[n][j];

    cout<<ans<<endl;

    // cout<<(2 | 3)<<endl;

    return false;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(30);
    // ll T;cin>>T;
    // rep(i,T){
    //     cout<<"Case #"<<i+1<<" : ";solve();
    // }
    solve();
}

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

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

int main() {
  int N,W;
  cin >> N >> W;
  if(N%W == 0){
    cout << N/W;
  } else {
    cout << (N-N%W)/W;
  }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll>   vl;
#define f(i,n)  for(i=0;i<n;i++)
#define f1(i,n)  for(i=1;i<n;i++)
#define fr(i,n) for(i=n-1;i>=0;i--)
#define em emplace_back
#define mp make_pair
#define in insert
#define fi first
#define sc second
#define b begin
#define e end
#define er erase
#define l length
#define c clear
#define si size
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
const double pi=3.141592653;
const ll infi=1000000001;
const ll MOD=1000000007;
const ll mod=998244353;
const string no="NO\n",yes="YES\n";

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

// void dfs(vl v[],ll node,ll hai[]){
//     hai[node]=1;
//     for(auto i:v[node]){
//         if(hai[i]==0){
//             dfs(v,i,hai);
//         }
//     }
// }

// ll con(vl v[],ll hai[],ll sz){
//     ll count=0;
//     for(int i=1;i<sz;i++){
//         if(hai[i]==0){
//             count++;
//             dfs(v,i,hai);
//         }
//     }
    // return count;
// }

// void gcde(int a,int b,int *x,int *y){
//     if(a==0){
//         *x=0;
//         *y=1;
//         return;
//     }
//     int x1,y1;
//     gcde(b%a,a,&x1,&y1);

//     *x=y1-(b/a)*x1;
//     *y=x1;
// }

// ll recur(vl v,ll in,ll m,ll n){
//     if(in==-1)  return 1000000000001;
//     ll d,e,c;
//     d=max(m/v[in],n*v[in]);
//     c=recur(v,in-1,m/v[in],n*v[in]);
//     e=recur(v,in-1,m,n);
//     return min(c,min(e,d));
// }

// ll bexpo(ll a,ll p){
//     ll x=1;
//     while(p){
//     if(p&1){
//         x=(x*a)%mod;
//     }
//     a=(a*a)%mod;
//     p>>=1;
//     }
//     return x;
// }
// int dx[8]{-1,0,0,1,-1,-1,1,1};
// int dy[8]{0,-1,1,0,-1,1,-1,1};

int main() {
    fastio
    int t=1;
    // cin>>t;
    ll n,m,i,l,d,bank,s,k,j,x,y,ans,q;

    while(t--){ans=0;
        cin>>n>>m;
        string s[n];
        f(i,n)  cin>>s[i];
        f(i,n){
            f(j,m-1){
                if(s[i][j]==s[i][j+1]&&s[i][j]=='.')    ans++;
            }
        }
        f(i,m){
            f(j,n-1){
                if(s[j][i]==s[j+1][i]&&s[j][i]=='.')    ans++;
            }
        }
    cout<<ans<<endl;
    }

	return 0;
}


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

int main() {
  long long int N, K;
  cin >> N >> K;
  int T[N][N];

  vector<int> array(0);
  for(int i = 0; i < N; i++){
    array.push_back(i);
  }

  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      cin >> T[i][j];
    }
  }

  int ans = 0;
  do{
      long long int tmp = 0;
      for(int i = 0; i < N; i++){
        tmp += T[array[i]][array[(i+1)%N]];
      }
      if(tmp == K) ans++;
  }while(next_permutation(array.begin()+1,array.end()));

  cout << ans << endl;
}

// I SELL YOU...!
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll n,k,pr=0;
  cin >> n >> k;
  vector<ll> a(n),b(n);
  vector<P> ab(n);
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
    ab[i] = P(a[i],b[i]);
  }
  sort(ab.begin(),ab.end());
  for(int i=0;i<n;i++){
    auto [ta,tb] = ab[i];
    ll dist = ta - pr;
    if (dist>k){
      cout << pr + k << endl;
      return 0;
    }
    k = k - dist + tb;
    pr = ta;
  }
  cout << pr + k << endl;
}