#include<bits/stdc++.h>
#define ll   long long int
#define mp   make_pair
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define pb     push_back
#define fast    ios_base::sync_with_stdio(false);cin.tie(0);
#define r0      return 0
#define all(c)  c.begin(),c.end()
#define s(c)    accumulate(c.begin(),c.end(),static_cast<ll>(0))
#define sz(r)   r.size()
#define  sc     second
#define fs      first
using namespace std;
ll sortbyfirst(const pair<ll,string>&a,const pair<ll,string>&b)
{
    return (a.first>b.first);
}
int main()
{
    fast;
    ll a,b,c,d,r,q,f=0,i=0;
    cin>>a>>b>>c;
    vector<ll>v;
    ll dv=b;
    d=a;
    ll cnt=0;
    while(1)
    {
        q=d/dv;
        r=d%dv;
        if(r!=0)
        {
            d=r*10;v.pb(r);
            if(q==c && cnt>0)
            {cout<<cnt;r0;}
            if(sz(v)>1)
            {
                if(v[i]==v[i-1])
                {cout<<"-1";r0;}
                i++;
            }
            cnt++;
        }
        else
        {break;}
    }
    if(cnt>0 && q==c)
    cout<<cnt;
    else
    {if(c==0)
      cout<<cnt+1;
      else
      cout<<"-1";
    }

    r0;
}


#include <algorithm>
#include <functional>
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <cstdlib>
#include <stack>
#include <vector>
#include <map>
#include <assert.h>
#include <set>

static constexpr int MAXN = 1e6 + 10;

typedef std::pair<int, int> pii;

int main() {
    int n, a, b, c;
    std::cin >> n >> a >> b >> c;
    long long answer = 0;
    for (int i = 0; i <= std::min(a, n / 2); i++) {
        for (int j = 0; j <= std::min(b, n); j++) {
            int have = 2 * i + j;
            int need = n - have;
            if (need < 0)
                continue;

            if (c >= need * 2) {
                answer++;
            }
        }
    }

    std::cout << answer << std::endl;
    return EXIT_SUCCESS;
}


#include <bits/stdc++.h>

using namespace std;

int S,n,i,x,k;
stack <int> p;
int main()
{
cin>>n;
cin>>S;
x=k=i=0;
while(x!=S)
{
    while(x<S)
    {
p.push(n-i);
x=x+(n-i);
k++;
    }
while(x>S){p.pop();x=x-(n-i);k--;}
i++;
}
cout<<k;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
const int N=2000004;
string a[10];
string b[20];
int main()
{
    int n;
    a[2]="twenty";
    a[3]="thirty";
    a[4]="forty";
    a[5]="fifty";
    a[6]="sixty";
    a[7]="seventy";
    a[8]="eighty";
    a[9]="ninety";
    b[1]="one";
    b[2]="two";
    b[3]="three";
    b[4]="four";
    b[5]="five";
    b[6]="six";
    b[7]="seven";
    b[8]="eight";
    b[9]="nine";
    b[10]="ten";
    b[11]="eleven";
    b[12]="twelve";
    b[13]="thirteen";
    b[14]="fourteen";
    b[15]="fifteen";
    b[16]="sixteen";
    b[17]="seventeen";
    b[18]="eighteen";
    b[19]="nineteen";
    while(scanf("%d",&n))
    {
            if(n<20)
            {
                cout<<b[n]<<endl;
            }
            else
            {
                cout<<a[n/10];
                if(n%10)
                {
                    cout<<"-"<<b[n%10]<<endl;
                }
                else
                    cout<<endl;
            }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(x) push_back(x)
#define REP(i,x,y) for(int (i)=(x);(i)<(y);(i)++)
#define REPIT(it,A) for(typeof(A.begin()) it = (A.begin()); it!=A.end();it++)
#define sqr(x) ((x)*(x))
#define mp(x,y) make_pair((x),(y))
#define fast_io() ios_base::sync_with_stdio(0);cin.tie(0);
//#define NDEBUG 1
#define fst first
#define snd second
#define itm1 fst.fst
#define itm2 fst.snd
#define itm3 snd
#define mt(a,b,c) mp(mp(a,b),c)
#define sz(v) ((int)v.size())
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ii, int> tri;
typedef unsigned int ui;

const int MOD = 1000000007;

int n;
int a[7];
int cum[7];
int id[770000]; // maxheight - 1

map<int,int> dp[770000][7][2]; // dp[pos][height][isBaseBlocked][msk], with 0 <= msk < 2^7 = 128

const int FULL = 127;

int bprn(int x){
	vector<int> v;
	while (x) {
		v.pb(x%2);
		x /= 2;
	}
	reverse(all(v));
	REP(i,0,v.size()) cerr << v[i];
}

int go(int i, int h, int b, int msk){
	if (h > id[i]){
		i++;
		h = 0;
		b = 1;
		int wall = (1<<(id[i]+1)) - (1<<(id[i-1]+1));
//		cerr << "At i:" << i << ", wall:"; bprn(wall); cerr << endl;
		msk |= wall;
	}

	if (i >= n) return 1;
	if (dp[i][h][b].count(msk)) return dp[i][h][b][msk];

	int top = (h == id[i]);
	int right = (i == n-1);
	int rem = 4 - b - top - right - (int)((bool)(msk & 1<<h));

	if (rem == 0) return dp[i][h][b][msk] = 0;

//	cerr << "Status for (" << i << "," << h << "," << b << "," << msk << "): " << endl;
//	cerr << "\tRem:" << rem << ", Top:" << top << ", Right:" << right << endl;

	int ans = go(i,h+1,0,msk & ~(1<<h));
	if (rem > 1 && !right) ans = (ans + go(i,h+1,0,msk | (1<<h)) ) % MOD;
	if (rem > 1 && !top) ans = (ans + go(i,h+1,1,msk & ~(1<<h))) % MOD;
	if (rem > 2 && !top && !right) ans = (ans + go(i,h+1,1,msk | (1<<h))) % MOD;

//	cerr << "dp[" << i << "][" << h << "][" << b << "][" << msk << "]: " << ans << endl;
	return dp[i][h][b][msk] = ans;
}

int main(){
	fast_io();
	REP(i,0,7) cin >> a[i];
	cum[0] = 0;
	REP(i,1,8) cum[i] = cum[i-1]+a[i-1];
	n = cum[7];
	int u = 0;
	REP(i,0,n) {
		while (cum[u+1] <= i) u++;
		id[i] = u;
	}
//	REP(i,0,n) cerr << i << ": " << id[i] << endl;

	cout << go(0,0,1,(1<<(id[0]+1))-1);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    bool check=true;

    string s,out="";
    cin >> s;

    if(((int)s[0]>=97 && (int)s[0]<=122))
    {
        out = s[0]-32;
    }

    if(((int)s[0]>=65 && (int)s[0]<=90))
    {
        out = s[0];
    }

    for(int i=1; i<s.size(); i++)
    {
        if((s[i]<=90 && s[i+1]<=90) || (s[i]>=97 && s[i+1]>=90) && i<s.size()-1) check = true;
        else
        {
            cout << s << endl;
            return 1;
        }

        string p;

        if(s[i]<=90) p=(int)s[i]+32;
        else p = s[i];

        out = out + p;
    }

    cout << out << endl;

    return 0;
}


#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <fstream>
#include <math.h>
using namespace std;

double d(int _x1,int _y1,int _x2 ,int _y2)
{
	double d1=(pow(_x1-_x2,2)+pow(_y1-_y2,2));
	return d1;
}
bool Right (double d1, double d2,double d3)
{
	if(d1+d2==d3) return 1;
		return 0;
}
bool t(int x1,int y1,int x2,int y2,int x3,int y3)
{
	double d1=d(x1,y1,x2,y2);
	double d2=d(x1,y1,x3,y3);
	double d3=d(x3,y3,x2,y2);
	if(Right(d1,d2,d3)||Right(d2,d1,d3)||Right(d1,d3,d2))return 1;
}
int main()
{
	while (true)
	{
	int x1,y1,x2,y2,x3,y3;
	scanf("%d %d %d %d %d %d",&x1,&y1,&x2,&y2,&x3,&y3);
	if(t( x1,y1,x2,y2,x3,y3)) printf ("RIGHT\n");
	else if(t( x1-1,y1,x2,y2,x3,y3)||t( x1+1,y1,x2,y2,x3,y3)||t( x1,y1-1,x2,y2,x3,y3)||t( x1,y1+1,x2,y2,x3,y3)||
		    t( x1,y1,x2-1,y2,x3,y3)||t( x1,y1,x2+1,y2,x3,y3)||t( x1,y1,x2,y2-1,x3,y3)||t( x1,y1,x2,y2+1,x3,y3)||
			t( x1,y1,x2,y2,x3-1,y3)||t( x1,y1,x2,y2,x3+1,y3)||t( x1,y1,x2,y2,x3,y3-1)||t( x1,y1,x2,y2,x3,y3+1))
			printf("ALMOST\n");
	else
		printf("NEITHER\n");
	}
	return  0;
}


#include<iostream>
using namespace std;
int main(void)
{    int i,j;
	string str1,str2,str;
	cin>>str1>>str2;
	str=str1[0];
	i=1;j=0;
	while(1)
	{
		if(str1[i]>=str2[j])
		{
			str=str+str2[j];
			break;
		}
		else
		{str=str+str1[i];
		 i++;}

		if(i==(str1.length()))
		{
			str=str+str2[j];
			break;
		 }
	}
	cout<<str;
}


#include<bits/stdc++.h>
using namespace std;
const int MAX = 1e4 + 5;
typedef pair<long long, int> PII;
bool marked[MAX];
vector <PII> adj[MAX];
long long prim(int x)
{
    priority_queue<PII, vector<PII>, greater<PII> > Q;
    int y;
    long long minimumCost = 0;
    PII p;
    Q.push(make_pair(0, x));
    while(!Q.empty())
    {
        // Select the edge with minimum weight
        p = Q.top();
        Q.pop();
        x = p.second;
        // Checking for cycle
        if(marked[x] == true)
            continue;
        minimumCost += p.first;
        marked[x] = true;
        for(int i = 0;i < adj[x].size();++i)
        {
            y = adj[x][i].second;
            if(marked[y] == false)
                Q.push(adj[x][i]);
        }
    }
    return minimumCost;
}

int main()
{
	  int n; cin>>n;
	  long long mincost;
	  for(int i=1;i<n;i++)
	  {
	  	  for(int j=i+1;j<=n;j++)
	  	  {
	  	  	    adj[i].push_back(make_pair((i+j)%(n+1),j));
	  	  	    adj[j].push_back(make_pair((i+j)%(n+1),i));
			}
	  }
	  mincost = prim(1);
	  cout<< mincost ;
}


#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
int n;
int a,b;

int main()
{
    //scanf("%d",&n);
    while(scanf("%d",&n)){
    scanf("%d",&a);
    int flag=-1;
    for(int i=1;i<n;i++)
    {
        scanf("%d",&b);
        int x=b-a;
        if(flag==-1)
        {
            if(x>0) flag=1;  //����
            if(x==0) flag=0; //��ֵ
            if(x<0) flag=2;  //�ݼ�
        }
        else
        {
           if(flag==1)
           {
               if(x==0) flag=0;
               if(x<0) flag=2;
           }
           if(flag==0)
           {
               if(x>0) flag=666;
               if(x<0) flag=2;
           }
           if(flag==2)
           {
               if(x==0||x==1) flag=666;
           }
        }
        a=b;
    }
    if(flag==666) puts("NO");
    else puts("YES");
    }

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back()
#define F first
#define S second
ll  M=1e9+7;

int main()
{
  ll n,sum=0,i;
  cin>>n;
  ll a[n];
  for(i=0;i<8;i++)
  {
    cin>>a[i];
    sum+=a[i];
  }
  n=n%sum;
  for(i=0;i<8;i++)
  {
      if(n<=a[i])
      {
          cout<<i+1;
          return 0;
      }
      else
        n-=a[i];
  }
  return 0;

}


#include<iostream>
#define mod 1000000007
#define maxn 1000006
using namespace std;

unsigned long long store[maxn];  //store[i]=i!% mod

unsigned long long power(int n,unsigned long long k ,int m=1000000007)  //return n^k % m
{
 if(k==0) return 1;
 if(k==1) return n;
 unsigned long long f=power(n,k/2,m);
 unsigned long long p=(f*f)%m;
 if(k%2!=0)
  p=(p*n)%m;

 return p;
}

unsigned long long invmod(int n,int m)
{
 return power(n,m-2,m);
}

unsigned long long smcomb(int n,int r,int m)      //evaluates comb for small numbers (n<mod,n<10^7) ,mod must be a prime no.
{
 if(n<r) return 0;
 if(n==r) return 1;
 if(r==0) return 1;
 unsigned long long ans=store[n],x=invmod(store[n-r],m),y=invmod(store[r],m);
 ans=(ans*x)%m;
 ans=(ans*y)%m;
 return ans;
}

void create_store(int m)
{

       store[0]=1;
    for(int i=1;i<maxn;i++)
    {
        store[i]=(store[i-1]*i)%m;
    }

}

long long od[maxn], ev[maxn];

int main()
{
    create_store(mod);

    int n,m,a,b;
    cin>>n>>m>>a>>b;

    if(n==2)
    {
        cout<<1;
        return 0;
    }

    od[0]  =1;
    long long e= 1;
    for(int i=1;i<=n;i++)
    {
        od[i] = od[i-1]*e;
        e+=2;
    }

    ev[0]  =1;
    e= 2;
    for(int i=1;i<=n;i++)
    {
        ev[i] = ev[i-1]*e;
        e+=2;
    }

    long long ans =0 ;
    for(int k1=2;k1<=n;k1++)
    {
        int k2 = n-k1;
        long long term = (smcomb(m-1,k1-2, mod) *smcomb(n-2, k1-2, mod))%mod;
        term = (term * store[k1-2])%mod;
        term = (term*power(m, k2))%mod;

        //cout<<k1<<" ::  "<<smcomb(m-1,k1-2,mod)<<" "<<smcomb(n-2,k1-2,mod)<<" "<<power(m,k2)<<" ";
        long long term2=0;
        if(k1%2==1)
        {
            int ind = (k1+1)/2;
            term2 = od[ind+k2-1]*invmod(od[ind-1],mod);
        }
        else
        {
            int ind = (k1)/2;
            term2 = ev[ind+k2-1]*invmod(ev[ind-1],mod);
        }

        term2  = power(n*k1,k2-1)*power(k2,k2-2);
        term2 = term2%mod*invmod(store[k2]);
        term = (term*(term2%mod))%mod;
        //cout<<term2%mod<<" "<<term<<"\n";
        ans= (ans+term)%mod;
    }
    cout<<ans;
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

const int MAXK = (1 << 27);

int n;
int T[MAXK][2];

int rec(int mask, int t)
{
    if(T[mask][t] != -1)
    {
        return T[mask][t];
    }
    for(int i = 1; i <= n; i++)
    {
        if(!(mask & (1 << i)))
        {
            //printf("%d %d\n", mask, t);
            int nMask = mask;
            for(int j = i; j <= n; j *= i)
            {
                nMask |= (1 << j);
                if(j == 1) break;
            }
            int temp = rec(nMask, t ^ 1);
            if(t == temp)
            {
                return T[mask][t] = t;
            }
        }
    }
    return T[mask][t] = t ^ 1;
}

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

    /*for(int i = 1; i < 20; i++)
    {
        n = i;*/
        memset(T, -1, sizeof(T));
        if(rec(0, 0) == 0)
        {
            printf("Vasya\n");
        }
        else
        {
            printf("Petya\n");
        }
    //}

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define d(x)                cout << #x << " = " << (x) << endl;
#define fr                  freopen("in.txt", "r", stdin);
#define fw                  freopen("out.txt", "w", stdout);
#define mem(x)              memset((x), 0, sizeof((x)));
#define pb                  push_back
#define ll                  long long
#define fastIO              ios_base::sync_with_stdio(false)
#define sf                  scanf
#define pf                  printf
#define SQR(x)              ((x)*(x))
#define sc1(x)              scanf("%d", &x)
#define sc2(x, y)           scanf("%d %d", &x, &y)
#define sc3(x, y, z)        scanf("%d %d %d", &x, &y, &z)
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x-1); i>=int(y); i--)
#define all(c)              (c.begin(), c.end())
#define unq(v)              sort(all(v)), (v).erase(unique(all(v)),v.end())
#define EPSILON    (1.0E-8)
#define siz 100000
#define s 1000000
#define ino printf("dhuksi\n");

int main(){
    #ifndef ONLINE_JUDGE
        clock_t tStart = clock();
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif

        string strcw = "^>v<";
        string strccw = "^<v>";

        string strcw_result = "";
        string strccw_result = "";

        string str;
        getline(cin, str);
        int n; cin >> n;
        // d(n)

        int startcw;
        int startccw;
        for(int i = 0; i < 4; i++){
            if(strcw[i] == str[0]){
                startcw = i;
            }
        }
        // d(startcw)
        // d(str)
        for(int i = 0; i < n; i++){
            startcw++;
            int index = startcw%4;
            strcw_result += strcw[index];
        }

         for(int i = 0; i < 4; i++){
            if(strccw[i] == str[0]){
                startccw = i;
            }
        }
        // d(startccw)

        for(int i = 0; i < n; i++){
            startccw++;
            int index = startccw%4;
            strccw_result += strccw[index];
        }

        // cout << strcw_result[n-1] << endl;

        // cout << strccw_result[n-1] << endl;

        if(strcw_result[n-1] == strccw_result[n-1]){
            printf("undefined");
        }
        else if(strcw_result[n-1] == str[2]){
            printf("cw");
        }
        else{
            printf("ccw");
        }

    #ifndef ONLINE_JUDGE
        printf("\n>>Time taken: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
}


#include<iostream>
using namespace std;
int main ()
{
    int n;
    if (n>0)
    cout<<n;

    else
    {
        int n1 ,n2 ;
        n1 = n /10;
        n2 = (n/100)*10+(n%10);
        if (n1 > n2)
        cout<<n1 ;
         else
         cout<<n2;
    }
    return 0;
}


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

int main()
{
    int p1, p2, p3, p4, a, b;
    cin >> p1 >> p2 >> p3 >> p4 >> a >> b;
    int p = min(p1, min(p2, min(p3, p4)));
    if (p <= b)
    {
        if (p - a > 0)
            cout << p - a;
        else
            cout << 0;
    }
    else
        cout << b - a;
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<iostream>
#include<iomanip>
#include<utility>
#include<algorithm>
#include<stack>
#include<assert.h>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define fi first
#define sec second
#define rep(a,b,c) for(int a=1;a<=b;a+=c)
#define repp(a,b,c,d) for(int a=b;a<=c;a+=d)

const double PI=acos(-1);
const double EPS=1e-12;
const int MOD=1e9+7;
const int INF=1<<30;

using namespace std;

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a==1&&b==1&&c==1&&d==1)while(1);
	if((c>=b-1&&c<=b+3)||(d>=a-1&&d<=a+3))cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

inline ll read(){
    ll Hashimoto=0;
	bool Kanna=1;
    char I_Love=getchar();
    while(I_Love<'0'||I_Love>'9'){
        if(I_Love=='-')Kanna=0;
        I_Love=getchar();
    }
    while(I_Love>='0'&&I_Love<='9'){
        Hashimoto=Hashimoto*10+I_Love-'0';
        I_Love=getchar();
    }
    return (Kanna?Hashimoto:-Hashimoto);
}
template<typename T1,typename T2> inline void Umax(T1 &a,T2 b){
	if(a<b)a=b;
}
template<typename T1,typename T2> inline void Umin(T1 &a,T2 b){
	if(a>b)a=b;
}

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<(Kanna);++I_Love)cout<<Hashimoto[I_Love]<<(I_Love==(Kanna)-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(ll I_Love=Hashimoto;I_Love<(Kanna);++I_Love)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define UNIQUE(Kanna) Kanna.erase(unique(Kanna.begin(),Kanna.end()),Kanna.end());
#define inf (int)1e9
#define linf (ll)1e18
#define mod (inf+7)

ll d,k,a,b,t;
vector<ll> tr;
inline ll check(ll x){
	if(x<0||x>=d)return linf;
	return x*a+(x-1)/k*t+(d-x)*b;
}

int I_Love_Hashimoto_Kanna() {
	//完全想清楚了再开始写。
	//写不顺、不知道怎么写、很乱的时候，停下来好好想想。
	//做得慢总比做不出好。
	fastio;
	cin>>d>>k>>a>>b>>t;
	ll l=0,r=d/k+1;

	FOR(i,l,r){
		if(i*k<=d){
			tr.push_back(i*k);
			if((i+1)*k>d){
				FOR(j,i*k+1,d+1){
					tr.push_back(j);
				}
			}
		}
	}
	l=0,r=tr.size();
	while(l<r-1){
		ll mid=l+r>>1;
		if(mid==0){
			if(check(tr[0])<check(tr[1])){
				l=0;
				break;
			}
			else {
				l=1;
				break;
			}
		}
		if(mid==tr.size()-1){
			if(check(tr[mid])<check(tr[mid-1])){
				l=mid;
				break;
			}
			else {
				l=mid-1;
				break;
			}
		}
		if(check(tr[mid-1])<check(tr[mid])&&check(tr[mid])<check(tr[mid+1])){
			r=mid;
		}
		else if(check(tr[mid-1])>check(tr[mid])&&check(tr[mid])>check(tr[mid+1])){
			l=mid+1;
		}
		else if(check(tr[mid-1])>check(tr[mid])&&check(tr[mid])<check(tr[mid+1])){
			l=mid;
			break;
		}
		else {
			if(check(tr[0])<check(tr[tr.size()-1])){
				l=0;
				break;
			}
			else {
				r=0;
				break;
			}
		}
	}
	ll ans=linf;
	FOR(i,-k,k+1){
		Umin(ans,check(tr[l]+i));
	}
	Tone(ans);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
//#define int long long
#define mod 1000000007
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define f(i,n) for(ll i=0;i<n;i++)
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define ms(v,n) memset((v),n,sizeof(v));
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define sll set<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define maxi(a,b,c) max(a,max(b,c))
#define maxii(a,b,c,d) max(max(a,b),max(c,d))
#define mini(a,b,c) min(a,min(b,c))
#define md(a,b)  ((a%mod)*(b%mod)+mod)%mod
#define ad(a,b)  (a%mod+b%mod+mod)%mod
#define nl endl
#define inf 1e18
#define cases ll t;cin>>t;while(t--)
#define BLOCK 500
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;

using namespace std;

int main()
{

    fast
    ll n,m;
    cin>>n>>m;
    vll k(n);
    f(i,n)
    {
        cin>>k[i];

    }
    ll max_k=2*accumulate(all(k),0);
    vll sales[n];
    f(i,m)
    {
        ll x,y;
        cin>>x>>y;
        sales[y-1].pb(x-1);

    }

    ll low=0,high=max_k;
    while(low<high)
    {
        ll mid=(low+high)/2;
        vll hits(mid);

        for(ll i=0;i<n;i++)
        {
            ll big=-1;
            for(ll j=0;j<sales[i].size();j++)
            {
                if(sales[i][j]<=mid)
                {
                    big=max(big,sales[i][j]);
                }
            }
            if(big!=-1)
            {
                hits[big]+=k[i];
            }

        }

        ll money=0,save=0;
        for(ll day=0;day<mid;day++)
        {
            money++;
            ll use=min(money,hits[day]);
            money-=use;
            save+=use;
        }

        ll money_min=max_k-save;
        if(mid>=money_min)
        {
            high=mid;

        }
        else
        {
            low=mid+1;
        }

    }
    cout<<low;

    return 0;

}


#include<iostream>
using namespace std;
int main()
{
    long long int n;
    int a[50];
    cin>>n;
    int count=0;
    long long int m=n;
    while(m!=0)
    {
        count++;
        m=m/10;
    }
    for(int i=count-1;i>=0;--i)
    {
        a[i]=n%10;
        n=n/10;
    }
    for(int i=0;i<count;++i)
    {
        if(a[i]!=1 || a[i]!=4  || a[0]==4)
        {
            cout<<"NO";
            return 0;
        }
        if(i<=count-3)
        {
            if(a[i]==4 && a[i+1]==4 && a[i+2]==4)
         {
            cout<<"NO";
            return 0;
        }
        }

    }
    cout<<"YES";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,k,i,c=0;
	cin>>n>>m>>k;
	int a[n],b[]={};
	for(i=0;i<n;i++)
		cin>>a[i];
	for(i=0;i<n;i++)
	{
		if(a[i]<=k and a[i]!=0)
			b[c++]=abs(m-i-1);
	}
	sort(b,b+c);
	cout<<b[0]*10<<endl;
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    uint64_t k;
    cin >> n >> k;
    vector<int> ar1, ar2;
    for (int i = 0, j; i < n; i++)
    {
        ar2.clear();
        ar2 = ar1;
        ar1.push_back(i+1);
        ar1.reserve(ar1.size() + distance(ar2.begin(),ar2.end()));
        ar1.insert(ar1.end(),ar2.begin(),ar2.end());
    }
    cout << ar1[k-1] << endl;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using namespace chrono;
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef tuple<int, int, int> tpl;
template<class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &P){
	in >> P.first >> P.second;
	return in;
}
template<class T>
istream &operator>>(istream &in, vector<T> &arr){
	for(auto &x: arr) in >> x;
	return in;
}
template<class T>
istream &operator>>(istream &in, deque<T> &arr){
	for(auto &x: arr) in >> x;
	return in;
}
template<class T1, class T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &P){
	out << P.first << " " << P.second << "\n";
	return out;
}
template<class T>
ostream &operator<<(ostream &out, const vector<T> &arr){
	for(auto &x: arr) out << x << ' '; cout << "\n";
	return out;
}
template<class T>
ostream &operator<<(ostream &out, const deque<T> &arr){
	for(auto &x: arr) out << x << ' '; cout << "\n";
	return out;
}
template<class T>
ostream &operator<<(ostream &out, const set<T> &arr){
	for(auto &x: arr) out << x << ' '; cout << "\n";
	return out;
}
template<class T1, class T2>
ostream &operator<<(ostream &out, const map<T1, T2> &arr){
	for(auto &x: arr) out << x << ' '; cout << "\n";
	return out;
}
mt19937 rnd(time(0));

ll euclid(ll x, ll y, ll &a, ll &b){
	if(y){
		ll d = euclid(y, x % y, b, a);
		return b -= x / y * a, d;
	}
	return a = 1, b = 0, x;
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
	ll n, m, x, y, vx, vy;
	cin >> n >> m >> x >> y >> vx >> vy;
	if(vx == 0){
		if(x == 0){
			if(vy > 0){
				cout << "0 " << m;
			}
			else{
				cout << "0 0";
			}
		}
		else if(x == n){
			if(vy > 0){
				cout << n << " " << m;
			}
			else{
				cout << n << " 0";
			}
		}
		else{
			cout << -1;
		}
	}
	else if(vy == 0){
		if(y == 0){
			if(vx > 0){
				cout << n << " 0";
			}
			else{
				cout << "0 0";
			}
		}
		else if(y == m){
			if(vx > 0){
				cout << n << " " << m;
			}
			else{
				cout << "0 " << m;
			}
		}
		else{
			cout << -1;
		}
	}
	else{
		x *= vx, y *= vy;
		ll a, b, g = euclid(n, m, a, b);
		b = -b;
		if((x - y) % g){
			cout << -1;
		}
		else{
			a *= (x - y) / g, b *= (x - y) / g;
			//cout << "a, b = " << a << " " << b << "\n";
			ll da = m / g, db = n / g;
			//cout << "da, db = " << pii(da, db);
			if(a < x && a * n < x){
				ll d = (x - a * n + da - 1) / da;
				a += da * d, b += db * d;
				//cout << "Middle: a, b = " << a << " " << b << "\n";
			}
			while(a - da >= (x + n - 1) / n){
				a -= da, b -= db;
			}
			//cout << "After: a, b = " << a << " " << b << "\n";
			int X = 0, Y = 0;
			if(a % 2){
				X = n;
			}
			if(b % 2){
				Y = m;
			}
			cout << X << " " << Y;
		}
	}
	return 0;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                //
//                                                                                //
//                                              _____________                                       //
//             ++++++++++                ___------------------\                                    //
//           +++`+``+`+`++++        ///`````````````````````````````\                              //
//           ++`+`+``+++`++++  /////```````````````````````````````````\                            //
//           +++`++`+`+``+++/////`````````````````````````````````````````\                         //
//             +++`++`+``+///```````````|```````````````````````````````````\                       //
//          ____++++/++++/`````````````/````````|````````|```````````````````\                      //
//        /  /  / |    //``````````````|````````|```````|````````|````````````\                     //
//       /  /  /  | ///````````/```````|```````||```````|````````|``````\```````\                   //
//       | /  /   |///`````````|``````/````````|````````|````````|```````|```````\                  //
//       |/   |   |//``|```````|``````|````````|`````````|```````|```````|````````\                 //
//       /\___|__//`|``|```````|`    |      ``:|````````|:```````|```````|```|`````|                //
//      /     /  /``|``|``````|/     |        :|     ```:|```````|```````|``++````++                //
//     /     / //```|``|``````|      |        |:        :|    ```|```````|```++``++`\               //
//     |    /  /````|``|``````/    _.::::.    |          |      |    ````|```|`++`\`|               //
//     |   /   |````|``|`````|            `                    |       ``|```++``++`|               //
//     |  /    |````|``|`````|                                 :         |``++````++|               //
//     | /     /````|``|`````|                              _.-:::.      |..`|``.`|.|               //
//     |/     /`````|``|`````|                                     `     |```|````|`|               //
//    /|      |`````|``|`````|                    :'                    .|```|````|.|               //
//   / |      |`````|``|`````|                                         /|-|``|````|`|               //
//  /  |      |`````|```\````|                                        / ||```|````|``\              //
// /   |      |`````|````|```|::                                    /_| ||```|````|``|              //
//            |`````|````|```|:|:.        `.._                    .\___/:|```|````|``|              //
//            |`````\````|```|:|::-          ``:::....           -:|:|:::|```|````|``|              //
//            |``````|```|```|:|::`|.                          .:::|:|:::|```|````|``|              //
//             \`````|```|```|:|::/|--.                     .`:|:::|:|:::/```|````|``|              //
//              |````|```|```\:|:|:|-----             _..-:|:|:|:::|:|::|````|````|`/               //
//              |````|```|````\|:|:|-------.____.....------|/::|:::|:|::|````|````|`|               //
//              |````|```|\````\:|/\___________    ________/\--\:::|:|::|````/````|`|               //
//              |````\```| \```|:/-------------\  /----------\``\::|:|::|```/`````|`|               //
//              |`````|``|  \``|/---------------\/------------\_________|```|`````|`|               //
//                                                                                //
//////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                //
//                                        Created by Aeren                                          //
//                                                                                //
//////////////////////////////////////////////////////////////////////////////////////////////////////


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

const int N = 24;
int a[N] , n , dp[N][1<<N];
vector < vector < int > > v;

int rec(int x , int mask)
{
	if(x==n)
	{
		return __builtin_popcount(mask);
	}

	if(dp[x][mask]!=-1) return dp[x][mask];

	int ret = 1e9;
	bool ok = false;
	for(int i=0;i<v[x].size();i++)
	{
		if( (v[x][i] & mask) == v[x][i])
		{
			ok = true;
			int tmp = mask;
			while(tmp)
			{
				int _ = (tmp & -tmp);
				tmp = tmp - (_);
				int tmpmask = mask;
				tmpmask = tmpmask - _;
				tmpmask = (tmpmask | (1<<x));
				ret = min(ret , rec(x+1 , tmpmask));
			}
		}
	}

	if(ok)
	{
		ret = min(ret , rec(x + 1 , (mask | (1<<x))));
		return dp[x][mask] = ret;
	}
	return dp[x][mask] = 1e9;
}

int main()
{
	cin >> n;
	v.resize(n+1);
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<n;i++) scanf("%d",&a[i]);

	for(int i=1;i<n;i++)
	{
		for(int j=0;j<i;j++)
		{
			for(int k=0;k<i;k++)
			{
				if(a[j] + a[k] == a[i])
				{
					int mask = 0;
					mask = mask | (1<<j);
					mask = mask | (1<<k);
					v[i].push_back(mask);
				}
			}
		}
	}

	for(int i=1;i<n;i++)
	{
		if(v[i].size() == 0)
		{
			cout << "-1";
			return 0;
		}
	}

	cout << rec(1 , 1);
}


// eddy1021
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long ll;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<LD,LD> Pt;
#define mod9 1000000009ll
#define mod7 1000000007ll
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define FI first
#define SE second
#define X FI
#define Y SE
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...)
#endif
inline ll getint(){
  ll _x=0,_tmp=1; char _tc=getchar();
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
ll mypow( ll _a , ll _x , ll _mod ){
  if( _x == 0 ) return 1ll;
  ll _tmp = mypow( _a , _x / 2 , _mod );
  _tmp = ( _tmp * _tmp ) % _mod;
  if( _x & 1 ) _tmp = ( _tmp * _a ) % _mod;
  return _tmp;
}
inline ll add( ll _x , ll _y , ll _mod = mod7 ){
  ll _ = _x + _y;
  if( _ >= _mod ) _ -= _mod;
  return _;
}
inline ll sub( ll _x , ll _y , ll _mod = mod7 ){
  ll _ = _x - _y;
  if( _ < 0 ) _ += _mod;
  return _;
}
inline ll mul( ll _x , ll _y , ll _mod = mod7 ){
  ll _ = _x * _y;
  if( _ >= _mod ) _ %= _mod;
  return _;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
int __ = 1 , _cs;
/*********default*********/
void build(){

}
ll n;
void init(){
  n = getint();
}
void solve(){
  if( n == 0 ){
    puts( "0 0" );
    return;
  }
  ll lyr = 1 , tmp = 6ll;
  while( n > tmp ){
    lyr ++;
    n -= tmp;
    tmp *= 2ll;
  }
  ll av = tmp / 6;
  if( n <= av ){
    assert( false );
    ll x = ( lyr * 2ll ) - 1 , y = 2ll;
    x -= ( n - 1 );
    y += ( n - 1 ) * 2ll;
    cout << x << " " << y << endl;
    return;
  }
  n -= av;

  if( n <= av ){
    ll x = -1 + ( lyr - 1 ) , y = 2 * lyr;
    x -= 2ll * ( n - 1 );
    cout << x << " " << y << endl;
    return;
    printf( "%lld %lld\n" , x , y );
    exit( 0 );
  }
  n -= av;

  if( n <= av ){
    ll x = -2 - ( lyr - 1 ) , y = 2 * ( lyr - 1 );
    x -= ( n - 1 );
    y -= 2ll * ( n - 1 );
    cout << x << " " << y << endl;
    return;
    printf( "%lld %lld\n" , x , y );
    exit( 0 );
  }
  n -= av;

  if( n <= av ){
    ll x = -1 - 2ll * ( lyr - 1 ) , y = -2;
    x += ( n - 1 );
    y -= 2ll * ( n - 1 );
    cout << x << " " << y << endl;
    return;
    printf( "%lld %lld\n" , x , y );
    exit( 0 );
  }
  n -= av;

  if( n <= av ){
    ll x = 1 - ( lyr - 1 ) , y = -2 - 2ll * ( lyr - 1 );
    x += 2ll * ( n - 1 );
    cout << x << " " << y << endl;
    return;
    printf( "%lld %lld\n" , x , y );
    exit( 0 );
  }
  n -= av;

  if( n <= av ){
    ll x = 2 + ( lyr - 1 ) , y = -2ll * ( lyr - 1 );
    x += ( n - 1 );
    y += 2ll * ( n - 1 );
    cout << x << " " << y << endl;
    return;
    printf( "%lld %lld\n" , x , y );
    exit( 0 );
  }
  n -= av;
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


#include <iostream>
using namespace std;
#define ll long long
int minReplace(int arr[], int n){
    int idx[4] = {0};
    for(int i = 0; i < n; i++){
        idx[arr[i]]++;
    }
    int count = 0;
    for(int i = 1; i < 4; i++){
        if(count < idx[i]){
            count = idx[i];
        }
    }
    return n - count;
}
int main(){
    int n;
    cin>>n;
    int arr[n];
    for(int i = 0; i < n; i++){
        cin>>arr[i];
    }
    cout << minReplace(arr, n) << endl;
    return 0;
}