#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,count=-1;
        cin>>n;
        while(n>0)
        {
            if(n%6==0)
            {
                n=n/6;
                count++;
            }
            else
            {
                n=n*2;
                count++;
            }
        }
        cout<<count<<"\n";
    }
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long int n,count=-1;
        cin>>n;
        if(n==1)
            cout<<"0\n";
        while(n>1 && n%3==0 && n%6==0)
        {
            if(n%6==0)
            {
                n=n/6;
                count++;
            }
            else
            {
                n=n*2;
                count++;
            }
        }
        cout<<count<<"\n";
    }
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,t=0,count=0;
        cin>>n;
        while(n>1)
        {
            if(n%6==0)
            {
                n/=6;
                t=0;
            }
            else if(t==0)
            {
                n*=2;
                t=1;
            }
            else
            {
                cout<<"-1\n";
                break;
            }
            count++;
        }
        if(n==1)
            cout<<count<<"\n";
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        while(n!=0)
        {
            if(n/6==0)
                c++;
            else
            {
                n=n*2;
                count++;
            }
        }
        cout<<count<<"\n";
    }
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,count=-1;
        cin>>n;
        if(n==1)
            cout<<"0\n";
        while(n>0)
        {
            if(n==1)
                break;
            if(n%2==0 && n%3==0)
            {
                n=n/6;
                count++;
            }
            else
            {
                n=n*2;
                count++;
            }
        }
    }
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,count=-1;
        cin>>n;
        while(n>0)
        {
            if(n/6==0)
                c++;
            else
            {
                n=n*2;
                count++;
            }
        }
        cout<<count<<"\n";
    }
}


include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,t=0,count=0;
        cin>>n;
        while(n>1)
        {
            if(n%6==0)
            {
                n=n/6;
                t=0;
            }
            else if(t==0)
            {
                n=n*2;
                t=1;
            }
            else
            {
                cout<<"-1\n";
                break;
            }
            count++;
        }
        if(n==1)
        cout<<count<<"\n";
    }
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,count=-1;
        cin>>n;
        if(n==1)
            cout<<"0\n";
        while(n>0)
        {
            if(n==1)
                break;
            if(n%2==0 && n%3==0)
            {
                n=n/6;
                count++;
            }
            else
            {
                n=n*2;
                count++;
            }
            cout<<count<<"\n";
        }
    }
}


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

typedef long LL;

LL getAns(LL x){
    LL number2 = 0,number3 = 0;
    while (!(x % 2))
    {
        x /= 2,number2++;
    }
    while (!(x % 3))
    {
        x /= 3,number3++;
    }
    if(x != 1 || number2 > number3)  return -1;
    return 2 * (number3 - number2) + number3;

}
int main(){
    int T;
    cin >> T;
    while (T--){
        LL n;
        cin >> n;
        cout << getAns(n) << endl;

    }

}


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

typedef long LL;

LL getAns(LL x){
    LL number2 = 0,number3 = 0;
    while (!(x % 2))
    {
        x /= 2,number2++;
    }
    while (!(x % 3))
    {
        x /= 3,number3++;
    }
    if(x != 1 || number2 > number3)  return -1;
    return 2 * (number3 - number2);

}
int main(){
    int T;
    cin >> T;
    while (T--){
        LL n;
        cin >> n;
        cout << getAns(n) << endl;

    }

}


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

typedef long LL;

LL getAns(LL x){
    LL number2 = 0,number3 = 0;
    while (!(x % 2))
    {
        x /= 2,number2++;
    }
    while (!(x % 3))
    {
        x /= 3,number3++;
    }
    if(x != 1 || number2 > number3)  return -1;
    return (number3 - number2) + number3;

}
int main(){
    int T;
    cin >> T;
    while (T--){
        LL n;
        cin >> n;
        cout << getAns(n) << endl;

    }

}


#include <bits/stdc++.h>

using namespace std;

int T;
int n;

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

	while (T--)
	{
		scanf("%d", &n);

		if (n == 1)
		{
			printf("0\n");
			continue;
		}

		if (n % 3 != 0)
		{
			printf("-1\n");
			continue;
		}

		int idx = 0, tot = n;
		while (idx <= tot)
		{
			if (n % 6 == 0)
			{
				n /= 6;
				idx++;
			}
			else
			{
				n *= 2;
				idx++;
			}

			if (n == 1) break;
		}

		if (n == 1) printf("%d\n", idx);
		else printf("-1\n");
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int T;
int n;

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

	while (T--)
	{
		scanf("%d", &n);

		if (n == 1)
		{
			printf("1\n");
			continue;
		}

		if (n % 3 != 0)
		{
			printf("-1\n");
			continue;
		}

		int idx = 0, tot = n;
		while (idx <= tot)
		{
			if (n % 6 == 0)
			{
				n /= 6;
				idx++;
			}
			else
			{
				n *= 2;
				idx++;
			}

			if (n == 1) break;
		}

		if (n == 1) printf("%d\n", idx);
		else printf("-1\n");
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int T;
int n;

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

	while (T--)
	{
		scanf("%d", &n);

		if (n == 1)
		{
			printf("0\n");
			continue;
		}

		if (n % 3 != 0)
		{
			printf("-1\n");
			continue;
		}

		map<int, int> mp;
		mp[n] = 1;

		int idx = 0, tot = n;
		while (idx <= tot)
		{
			if (n % 6 == 0)
			{
				n /= 6;
				mp[n] = 1;
				idx++;
			}
			else
			{
				n *= 2;
				idx++;

				if (mp.find(n) != mp.end()) break;
			}

			if (n == 1) break;
			if (n > tot * 3) break;
		}

		if (n == 1) printf("%d\n", idx);
		else printf("-1\n");
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int T;
int n;

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

	while (T--)
	{
		scanf("%d", &n);

		if (n == 1)
		{
			printf("0\n");
			continue;
		}

		int n2 = 0, n3 = 0;
		int t = n;
		while (t % 2 == 0)
		{
			n2++;
			t /= 2;
		}

		while (t % 3 == 0)
		{
			n3++;
			t /= 3;
		}

		if (t > 1 || n2 > n3)
		{
			printf("-1\n");
			continue;
		}

		printf("%d\n", n3 - n2 + n3);
	}

	return 0;
}


#include <iostream>

using namespace std;
int ans(long int n)
{ int c=0; long int N=n;
    while(n<N)
    {if(n==1) return c;
        if(n%6==0){n=n/6; c++;}
    else {n=n*2; c++;}
    }
    return -1;
}
int main()
{ int T;
cin>>T;
while(T--)
{long int n;
cin>>n;
cout<<ans(n)<<endl;

}
        return 0;
}


#include <iostream>
using namespace std;
int checker(int n){
int c2=0,c3=0;
while(n%2==0){
    c2++;
    n=n/2;
};
while(n%3==0){
    c3++;
    n=n/3;
};
if(n!=1||c2>c3)
    return -1;
return 2*c3-c2;
}
int main()
{
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        cout<<checker(n)<<endl;
    };
    return 0;
}


#include <iostream>

using namespace std;
long long int ans(long long int n)
{ int c=0;

    while(n>0 )
    {if(n==1) return c;
        if(n%6==0){n=n/6; c++;}
    else {n=n*2; c++;}
    }
    return -1;
}
int main()
{ int T;
cin>>T;
while(T--)
{long long int n;
cin>>n;
cout<<ans(n)<<endl;

}
        return 0;
}


#include <iostream>

using namespace std;
long int ans(long int n)
{ long int c=0;
    while(n>0)
    {if(n==1) return c;
        if(n%6==0){n=n/6; c++;}
    else {n=n*2; c++;}
    }
    return -1;
}
int main()
{ int T;
cin>>T;
while(T--)
{long int n;
cin>>n;
cout<<ans(n)<<endl;

}
        return 0;
}


#include <iostream>

using namespace std;
int ans(long int n)
{ int c=0;
    while(n>0)
    {if(n==1) return c;
        if(n%6==0){n=n/6; c++;}
    else {n=n*2; c++;}
    }
    return -1;
}
int main()
{ int T;
cin>>T;
while(T--)
{long int n;
cin>>n;
cout<<ans(n)<<endl;

}
        return 0;
}


#include <iostream>
using namespace std;
int no_of_3(int n){
    int c=0;
while(n%3==0){
    c++;
    n=n/3;
};
return c;
}
int no_of_2(int n){
int c=0;
while(n%2==0){
    c++;
    n=n/2;
};
return c;
}
bool anyotherfactor(int n){
while(n%2==0){
    n=n/2;
};
while(n%3==0){
    n=n/3;
};
return n!=1?true:false;
}
int main()
{
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        if(n==1){
            cout<<0<<endl;
        }else{
            if(no_of_2(n)==no_of_3(n)){
                cout<<no_of_2(n)<<endl;
            }else if(no_of_2(n)>no_of_3(n)||anyotherfactor(n)){
            cout<<-1<<endl;
            }else{
            cout<<2*no_of_3(n)-no_of_2(n)<<endl;
            };
        };
    };
    return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while (t--)
    {
        int n;
        cin>>n;
        bool ok=true;
        int counterr=0;
        map <int , int> m;
        while (n!=1)
        {
            if (n%6!=0 && m[n*2]==0)
            {
                n*=2;
                m[n]++;
                counterr++;
                //ok=true;
            }
            else if (n%6==0 && m[n/6]==0)
            {
                n/=6;
                m[n]++;
                counterr++;
                //ok =true;
            }
            else  if (m[n/6]>=1 || m[n*2]>=1 || n >= 1e18)
            {
               ok =false ;
                break;
            }
        }
        if (ok==true && n==1){
        cout << counterr << "\n";}
        else {
            cout << "-1" << "\n";
        }
    }
    return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while (t--)
    {
        int n;
        cin>>n;
        bool ok=true;
        int counterr=0;
        map <int , int> m;
        while (n!=1)
        {
            if (n%6!=0 && m[n*2]==0)
            {
                n*=2;
                m[n]++;
                counterr++;
                //ok=true;
            }
            else if (n%6==0 && m[n/6]==0)
            {
                n/=6;
                m[n]++;
                counterr++;
                //ok =true;
            }
            else  if (m[n/6]>=1 || m[n*2]>=1 || n>1000000000)
            {
               ok =false ;
                break;
            }
        }
        if (ok==true){
        cout << counterr << "\n";}
        else {
            cout << "-1" << "\n";
        }
    }
    return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while (t--)
    {
        long long int  n;
        cin>>n;
        bool ok=true;
        int counterr=0;
        map <long long int  ,long long int > m;
        while (n!=1)
        {
            if (n%6!=0 && m[n*2]==0)
            {
                n*=2;
                m[n]++;
                counterr++;
                //ok=true;
            }
            else if (n%6==0 && m[n/6]==0)
            {
                n/=6;
                m[n]++;
                counterr++;
                //ok =true;
            }
            else  if (m[n/6]>=1 || m[n*2]>=1 || n >= 1e18)
            {
               ok =false ;
                break;
            }
        }
        if (ok==true && n==1){
        cout << counterr << "\n";}
        else {
            cout << "-1" << "\n";
        }
    }
    return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while (t--)
    {
        long long int  n;
        cin>>n;
        bool ok=true;
        int counterr=0;
        //map <long long int  ,long long int > m;
        while (n!=1)
        {
            if (n%6!=0 )//&& m[n*2]==0)
            {
                n*=2;
                //m[n]++;
                counterr++;
                //ok=true;
            }
            else if (n%6==0 )//&& m[n/6]==0)
            {
                n/=6;
                //m[n]++;
                counterr++;
                //ok =true;
            }
            else  if ( n >= 1e18)//|| m[n*2]>=1 ||m[n/6]>=1 )
            {
               ok =false ;
                break;
            }
        }
        if (ok==true && n==1){
        cout << counterr << "\n";}
        else {
            cout << "-1" << "\n";
        }
    }
    return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while (t--)
    {
        long long int  n;
        cin>>n;
        bool ok=true;
        int counterr=0;
        //map <long long int  ,long long int > m;
        while (n!=1 && n <= 1e18 )
        {
            if (n%6!=0 )//&& m[n*2]==0)
            {
                n*=2;
                //m[n]++;
                counterr++;
                //ok=true;
            }
            else if (n%6==0 )//&& m[n/6]==0)
            {
                n/=6;
                //m[n]++;
                counterr++;
                //ok =true;
            }
        }
        if (ok==true && n==1){
        cout << counterr << "\n";}
        else {
            cout << "-1" << "\n";
        }
    }
    return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while (t--)
    {
        long long int  n;
        cin>>n;
        bool ok=true;
        int counterr=0;
        //map <long long int  ,long long int > m;
        while (n!=1 && n < 1e18 )
        {
            if (n%6!=0 )//&& m[n*2]==0)
            {
                n*=2;
                //m[n]++;
                counterr++;
                //ok=true;
            }
            else if (n%6==0 )//&& m[n/6]==0)
            {
                n/=6;
                //m[n]++;
                counterr++;
                //ok =true;
            }
        }
        if (ok==true && n==1){
        cout << counterr << "\n";}
        else {
            cout << "-1" << "\n";
        }
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
 long long t;
 cin>>t;
 while(t--)
 {
     long long n,i,count=0;
     cin>>n;
     while(n!=1)
     {
        if(n%6==0)
        {
         n/=6;
         count++;
        }
        else if(2*n%6==0)
        {
         n*=2;
         count++;
        }
        else
        {
            cout<<-1<<endl;
            return 0;
        }
     }
     cout<<count<<endl;
 }
}


#include<iostream>
using namespace std;
int main()
{
 long long t;
 cin>>t;
 while(t--)
 {
     long long n,i,count=0,flag=0;
     cin>>n;
     while(n!=1)
     {
        if(n%6==0)
        {
         n/=6;
         count++;
        }
        else if(2*n%6==0)
        {
         n*=2;
         count++;
        }
        else
        {
            flag=1;
            break;
        }
     }
     if(flag=1)
      cout<<-1<<endl;
     else cout<<count<<endl;
 }
}


#include<iostream>
using namespace std;
int main()
{
 long long t;
 cin>>t;
 while(t--)
 {
     long long n,i,count=0,flag=0;
     cin>>n;
     while(n!=1)
     {
        if(n%6==0)
        {
         n/=6;
         count++;
        }
        else if(2*n%6==0)
        {
         n*=2;
         count++;
        }
        else
        {
            flag=-1;
            break;
        }
     }
     if(flag=-1)
      cout<<-1<<endl;
     else cout<<count<<endl;
 }
}


#include<iostream>
using namespace std;
int main()
{
 long long t;
 cin>>t;
 while(t--)
 {
     long long n,i,count=0,flag=0;
     cin>>n;
     while(n!=1)
     {
        if(n%6==0)
        {
         n/=6;
         count++;
        }
        else if(2*n%6==0)
        {
         n*=2;
         count++;
        }
        else
        {
            flag=1;
            break;
        }
     }
     if(flag==1)
      cout<<-1<<endl;
     else cout<<count<<endl;
 }
}


#include<iostream>
using namespace std;
int main();
{
 long long t;
 cin>>t;
 while(t--)
 {
     long long n,i,count=0;
     cin>>n;
     while(n!=1)
     {
        if(n%6==0)
        {
         n/=6;
         count++;
        }
        else if(2*n%6==0)
        {
         n*=2;
         count++;
        }
        else
        {
            cout<<-1<<endl;
            return 0;
        }
     }
     cout<<count<<endl;
 }
}


#include<iostream>
int main(){
    using namespace std;
    int x;
    cin >> x;
    while(x--){
        int t;
        cin >> t;
        int a=0,b=0;
        while(t%2==0){
            t=t/2;
            a++;
        }
        while(t%3==0){
            t=t/3
            b++;
        }
        if(t==1 && a<=b)
            cout << 2*(b-a) << endl;
        else
            cout << "-1" << endl;
    }
    return 0;
}


#include<iostream>
int main(){
    using namespace std;
    int x;
    cin >> x;
    while(x--){
        int t;
        cin >> t;
        int a=0,b=0;
        while(t%2==0){
            t=t/2;
            a++;
        }
        while(t%3==0){
            t=t/3;
            b++;
        }
        if(t==1 && a<=b)
            cout << 2*(b-a) << endl;
        else
            cout << "-1" << endl;
    }
    return 0;
}


#include<iostream>
int main(){
    using namespace std;
    int x;
    cin >> x;
    while(x--){
        int t;
        cin >> t;
        int a=0,b=0;
        while(t%2==0){
            t=t/2;
            ++a;
        }
        while(t%3==0){
            t=t/3;
            ++b;
        }
        if(t==1 && a<=b)
            cout << 2*b-a << endl;
        else
            cout << "-1" << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define YY "YES\n"
#define NN "NO\n"
#define F first
#define S second
#define LL long long
using namespace std;

int t,t1,t2,k,now;
LL ans,a,b,c,d,tmp,n,m;
bool ok;
string s;

int main(){
	ios::sync_with_stdio(false);
	cin>>t;
	while(t--){
		cin>>n;
		ans=-1;
		int cnt=0;
		while (n!=1 && cnt<=1e4){
			if (n%6!=0 && (n*2)%6!=0) goto en;
			if (n%6==0) n/=6;
			else n*=2;
			cnt++;
		}
		if (n==1) ans=cnt;
		en: ;
		cout<<ans<<"\n";
	}
}


#include<bits/stdc++.h>
#define YY "YES\n"
#define NN "NO\n"
#define F first
#define S second
#define LL long long
using namespace std;

int t,t1,t2,k,now;
LL ans,a,b,c,d,tmp,n,m;
bool ok;
string s;

int main(){
	ios::sync_with_stdio(false);
	cin>>t;
	while(t--){
		cin>>n;
		ans=-1;
		int cnt=0;
		while (n!=1 && cnt<=1e4){
			if (n%6==0) n/=6;
			else n*=2;
			cnt++;
		}
		if (n==1) ans=cnt;
		cout<<ans<<"\n";
	}
}


#include<bits/stdc++.h>
#define YY "YES\n"
#define NN "NO\n"
#define F first
#define S second
#define LL long long
using namespace std;

int t,t1,t2,k,now;
LL ans,a,b,c,d,tmp,n,m;
bool ok;
string s;

int main(){
	ios::sync_with_stdio(false);
	cin>>t;
	while(t--){
		cin>>n;
		ans=-1;
		int cnt=0;
		while (n!=1 && cnt<=1e4){
			if (n%6!=0 || (n*2)%6!=0) goto en;
			if (n%6==0) n/=6;
			else n*=2;
			cnt++;
		}
		if (n==1) ans=cnt;
		en: ;
		cout<<ans<<"\n";
	}
}


#include<bits/stdc++.h>
#define YY "YES\n"
#define NN "NO\n"
#define F first
#define S second
#define LL long long
using namespace std;

int t,t1,t2,k,now;
LL ans,a,b,c,d,tmp,n,m;
bool ok;
string s;

int main(){
	ios::sync_with_stdio(false);
	cin>>t;
	while(t--){
		cin>>n;
		ans=-1;
		int cnt=0;
		while (n!=1 && cnt<=1e7){
			if (n%6==0) n/=6;
			else n*=2;
			cnt++;
		}
		if (n==1) ans=cnt;
		cout<<ans<<"\n";
	}
}


#include<bits/stdc++.h>
#define YY "YES\n"
#define NN "NO\n"
#define F first
#define S second
#define LL long long
using namespace std;

int t,t1,t2,k,now;
LL ans,a,b,c,d,tmp,n,m;
bool ok;
string s;

int main(){
	ios::sync_with_stdio(false);
	cin>>t;
	while(t--){
		cin>>n;
		ans=-1;
		int cnt=0;
		if (n%6==0 || (n*2)%6==0){
			while (n!=1 && cnt<=1e4){
			if (n%6==0) n/=6;
			else n*=2;
			cnt++;
			}
		}
		if (n==1) ans=cnt;
		cout<<ans<<"\n";
	}
}


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

using namespace std;

int main() {

	int n;

	cin >> n;

	while (n--) {
		long long x;

		int ans = 0;

		cin >> x;

		while (x != 0) {
			if (x == 1) {
				x = 0;
				cout << ans << endl;
			}
			if (x == 2) {
				cout << -1 << endl;
				break;
			}
			else {
				if (x % 6 == 0) {
					x = x / 6;
					++ans;
				}
				else {
					x = x * 2;
					++ans;
					if (x % 3 != 0) {
						cout << -1 << endl;
						break;
					}
				}
			}
		}
	}
	return 0;
}


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

using namespace std;

int main() {

	int n;
	vector<int> v;

	cin >> n;

	while (n--) {
		long long x;

		int ans = 0;

		cin >> x;

		while (x != 0) {
			if (x == 1) {
				x = 0;
				v.push_back(ans);
			}
			if (x == 2) {
				v.push_back(-1);
				break;
			}
			else {
				if (x % 6 == 0) {
					x = x / 6;
					++ans;
				}
				else {
					x = x * 2;
					++ans;
					if (x % 3 != 0) {
						v.push_back(-1);
						break;
					}
				}
			}
		}
	}

	for (int i = 0; i < v.size(); ++i) {
		cout << v[i] << endl;
	}

	return 0;
}


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

using namespace std;

int main() {

	int n;
	vector<int> v;

	cin >> n;

	while (n--) {
		long long x;

		int ans = 0;

		cin >> x;

		while (x != 1) {
			if (x == 2) {
				v.push_back(-1);
				break;
			}
			else {
				if (x % 6 == 0) {
					x = x / 6;
					++ans;
				}
				else {
					x = x * 2;
					++ans;
					if (x % 3 != 0) {
						v.push_back(-1);
						break;
					}
				}
			}
		}
		v.push_back(ans);
	}

	for (int i = 0; i < v.size(); ++i) {
		cout << v[i] << endl;
	}

	return 0;
}


 #include<iostream>
 using namespace std;
int main()
{
    fastRead;
    ll n,m,a,t,x,y;
    cin>>t;
    while(t--)
    {
        cin>>n;
        ll cnt=0;
        if(n==1)
            cout<<0<<endl;
        else
        {
            int f=0;
            for(int i=0;i<4000;i++){
                    if(n==1){
                            f=1;
                    break;
                    }
            if(n%6!=0){
                n*=2;
                cnt++;
            }
            if(n%6==0)
            {
                cnt++;
                n/=6;
            }
            }
            if(f)
            cout<<cnt<<endl;
            else cout<<"-1"<<endl;
        }
    }
}


#include<iostream>
#define ll long long
using namespace std;
int main()
{

    ll n,m,a,t,x,y;
    cin>>t;
    while(t--)
    {
        cin>>n;
        ll cnt=0;
        if(n==1)
            cout<<cnt<<endl;
        else
        {
            int f=0;
            for(int i=0;i<4000;i++){
                    if(n==1){
                            f=1;
                    break;
                    }
            if(n%6!=0){
                n*=2;
                cnt++;
            }
            if(n%6==0)
            {
                cnt++;
                n/=6;
            }
            }
            if(f)
            cout<<cnt<<endl;
            else cout<<"-1"<<endl;
        }
    }
}


#include<iostream>
using namespace std;
int main()
{
    int n,t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>n;
        int count ;
        if(n==1)
        {
            count=0;
        }
        else
        {
            int f;
            for(int i=0;i<4000;i++){
                if(n==1)
                {
                    int f=1;
                }

        if(n%6!=0){
            n*=2;
            count++;
        }
        if(n%6==0)
        {
            count++;
            n/=6;
        }
        if(f)
        {
            cout<<count<<endl;
        }
        else cout<<"-1"<<endl;
        }
    }
 }
 return 0;
}


#include<iostream>
#define ll long long
using namespace std;
int main()
{

    ll n,m,a,t,x,y;
    cin>>t;
    while(t--)
    {
        cin>>n;
        ll cnt=0;
        if(n==1)
            cout<<cnt<<endl;
        else
        {
            int f=0;
            for(int i=0;i<4000;i++){
                    if(n==1){
                            f=1;
                    break;
                    }
            if(n%6!=0){
                n*=2;
                cnt++;
            }
            if(n%6==0)
            {
                cnt++;
                n/=6;
            }
            }
            if(f)
            cout<<cnt<<endl;
            else cout<<"-1"<<endl;
        }
    }
    return 0;
}


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

int main(){
	int t;
	int cnt_3=0, cnt_2=0;
	long long n;
	cin >> t;
	while(t--){
		cin >> n;
		if(n==1){
			cout << 0 <<endl;
			continue;
		}
		cnt_3=0;
		cnt_2=0;
		while(1){
			if(n%3==0){
				n /= 3;
				cnt_3++;
			}
			else if(n%2==0){
					n /= 2;
					cnt_2++;
			}
			else{
				cout << -1 << endl;
				break;
			}

			if(n==1 && cnt_3>=cnt_2){
				cout << 2*cnt_3 - cnt_2 <<endl;
				break;
			}
			else if(n==1 && cnt_3<cnt_2) {
				cout << -1 <<endl;
				break;
			}
		}
	}

	return 0;
}


#include <iostream>
using namespace std;
const int maxn = 1e5+5;

int main(){
	int t, n;
	long long arr[maxn];
	int cnt;
	cin >> t;
	while(t--){
		cin >> n;
		cnt = 0;
		for(int i =0; i < n; i++)
			cin >> arr[i];

		for(int i =0; i < n; i++){
			if(arr[i]==1)
				cnt++;
			else
				break;
		}

		if(cnt == n){
			if(cnt%2==0)
				cout << "Second" << endl;
			else
				cout << "First" << endl;
		}
		else{
			if(cnt%2==0)
				cout << "First" << endl;
			else
				cout << "Second" << endl;
		}
	}
	return 0;
}


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

int main(){
	int t;
	int cnt_3=0, cnt_2=0;
	long long n;
	cin >> t;
	while(t--){
		cin >> n;
		if(n==1){
			cout << 0 <<endl;
			continue;
		}
		cnt_3=0;
		cnt_2=0;
		while(1){
			if(n%3==0 && cnt_3>=cnt_2 ){
				n /= 3;
				cnt_3++;
			}
			else if(n%2==0 && cnt_3 >= cnt_2 ){
					n /= 2;
					cnt_2++;
			}
			else{
				cout << -1 << endl;
				break;
			}

			if(n==1){
				cout << 2*cnt_3 - cnt_2 <<endl;
				break;
			}
		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
     int t;
     cin>>t;
     while(t--){
        long long int a;
        cin>>a;
        int count =0;
        while(a%3==0){
             if(a%6==0){
                  a=a/6;
                  count++;
             }
             else{
                  a=a*2;
                  count++;
             }
        }
        if(a==1)
        cout<<count;
        else
        cout<<-1;
     }
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
void printlist(vector<int >ans){
    for(int i=0; i<ans.size(); i++){
        cout<<ans[i]<<endl;
    }
}
int main(){
     int t;
     cin>>t;
     vector<int >ans(0);
     while(t--){
        long long int a;
        cin>>a;

        int count =0;
        while(a%3==0){
             if(a%6==0){
                  a=a/6;
                  count++;
             }
             else{
                  a=a*2;
                  count++;
             }
        }
        if(a==1)
        ans.push_back(count);
        else
        ans.push_back(-1);

     }

        printlist(ans);

     return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main{
     int t;
     cin>>t;
     while(t--){
        long long int a;
        cin>>a;
        int count =0;
        while(a%3==0){
             if(a%6==0){
                  a=a/6;
                  count++;
             }
             else{
                  a=a*2;
                  count++;
             }
        }
        if(a==1)
        cout<<count;
        else
        cout<<-1;
     }
     return 0;
}


// Author: wlzhouzhuan
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rint register int
#define rep(i, l, r) for (rint i = l; i <= r; i++)
#define per(i, l, r) for (rint i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define debug(x) cerr << #x << " = " << x << '\n';
#define pll pair <ll, ll>

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}

int main() {
  int T = read();
  while (T--) {
    int n = read(), ans = 0;
    while (n % 3 == 0) {
      if (n & 1) {
        ans += 2;
        n = 2 * n / 6;
      } else {
        ans++;
        n /= 6;
      }
    }
    printf("%d\n", n == 1 ? ans : -1);
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int T,x,y,q;
	cin>>T;
	while(T--){
		cin>>x;
		int sum1=0,sum2=0;
		if(x==1){
			cout<<"0"<<endl;
			continue;
		}
		if(x%3==0){
			while(x%3==0){x/=3,sum1++;}
			while(x!=1&&x%2==0) x/=2,sum2++;
			if(x>1){cout<<"-1"<<endl;continue;}
		}
		else{
			cout<<"-1"<<endl;
			continue;
		}
		if(sum1>=sum2){
			cout<<sum1-sum2+sum1<<endl;
		}else{
			cout<<"-1"<<endl;
			continue;
		}

	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long arr_6[100]={0};
long long arr_2[100]={0};
int main()
{
	int n,t;
	arr_6[0]=1;
	arr_2[0]=1;
	for(int i=1;i<25;i++)
	{
		arr_6[i]=arr_6[i-1]*6;
		arr_2[i]=arr_2[i-1]*2;
	}
	cin>>t;
	for(long long i=0;i<t;i++)
	{
		cin>>n;
		if(n==1)
		{
			cout<<0<<endl;
		}
		else
		{
			bool have_ans=false;
			for(long long j=n;j<=789730223053602816;j*=2)
			{
				for(int k=1;k<25;k++)
				{
					if(n==arr_6[k])
					{
						cout<<k<<endl;
						have_ans=true;
						break;
					}

				}
				if(have_ans)
				{
					break;
				}
				for(long long k=1;k<25;k++)
				{
					if(j==arr_6[k])
					{
						long long cnt=arr_6[k]/n;
						long long cnt1=arr_6[k];
						for(int l=1;l<25;l++)
						{
							if(cnt==arr_2[l])
							{
								cnt=l;
							}
							if(cnt1==arr_6[l])
							{
								cnt1=l;
							}
						}
						cout<<cnt+cnt1<<endl;
						have_ans=true;
						break;
					}
				}
				if(have_ans)
				{

					break;
				}
			}
			if(!have_ans)
			{
				cout<<-1<<endl;
			}
		}
	}
	return 0;
}


#include <iostream>
using namespace std;
int t, n, cnt = 0;
int main()
{
	cin >> t;
	while(t--)
	{
		cin >> n;
		cnt = 0;
		while(n % 3 == 0)
		{
			if(n % 6 == 0)
				n /= 6, cnt++;
			else
				n /= 3, cnt += 2; // n / 6 * 2;
		}
		if(cnt > 2)
			cout << cnt << endl;
		else
			cout << -1 << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
int t, n, cnt;
int main()
{
	cin >> t;
	while(t--)
	{
		cin >> n;
		cnt = 0;
		while(n % 3 == 0)
		{
			if(n % 2 == 0)
				n /= 6, cnt++;
			else
				n /= 3, cnt += 2; // n / 6 * 2;
		}
		if(cnt > 1)
			cout << cnt << endl;
		else
			cout << -1 << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	for (int i=1;i<=t;i++)
	{
		int x,ans=0;
		cin>>x;
		while (1)
		{
			if (x%3!=0)
			{
				break;
			}
			if (x%2==0)
			{
				x/=6;
				ans++;
			}
			else
			{
				x/=3;
				ans+=2;
			}
			if (x==1)
			{
				break;
			}
		}
		if (x>1) cout<<-1<<endl;
		else cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	for (int i=1;i<=t;i++)
	{
		int x,ans=0;
		cin>>x;
		while(x%6==0)
		{
			x/=6;
			ans++;
		}
		while(x%3==0)
		{
			x/=3;
			ans+=2;
		}
		if(x>1)
		{
			cout<<-1;
		}
		else cout<<ans+tot3*2<<endl;
	}
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,a2=0,a3=0;
        bool b=0;
        cin>>n;
        while(1)
        {
            if(n%2==0)
            {
                n/=2;
                a2++;
            }
            else if(n%3==0)
            {
                n/=3;
                a3++;
            }
            else if(n==1)
            {
                b=1;
            }
            else
            {
                cout<<-1<<endl;
                break;
            }
            if(b)
            {
                if(a2>a3)
                {
                    cout<<-1<<endl;
                }
                else
                {
                    cout<<2*a3-a2;
                }
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(void){
	int n, t;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> t;
		if(t%2==0||t%3==0){
			int bi=0;
			int tr=0;
			while(t%2==0){
      		bi++;
      		t = t/2;
			}
   		while(t%3==0){
   			tr++;
   		   t = t/3;
			}
   		if(t==1 && bi>=0 && tr>=bi){
   			cout << 2*tr-bi;
   		}
    		else:
      		cout << "-1";
		elif(t==1){
   		cout << "0";
   	}
		else{
			cout << "-1";
		}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(void){
	int n, t;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> t;
		if(t%2==0||t%3==0){
			int bi=0;
			int tr=0;
			while(t%2==0){
      		bi++;
      		t = t/2;
			}
   		while(t%3==0){
   			tr++;
   		   t = t/3;
			}
   		if(t==1 && bi>=0 && tr>=bi){
   			cout << 2*tr-bi << "\n";
   		}
    		else{
				cout << "-1\n";
			}
		}
		else if(t==1){
   		cout << "0\n";
   	}
		else{
			cout << "-1\n";
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(void){
	int n, t;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> t;
		if(t%2==0||t%3==0){
			int bi=0
			int tr=0
			while(t%2==0){
      		bi++;
      		t = t/2
			}
   		while(t%3==0){
   			tr++;
   		   t = t/3
			}
   		if(t==1 && bi>=0 && tr>=bi){
   			cout << 2*tr-bi;
   		}
    		else:
      		cout << "-1";
		elif(t==1){
   		cout << "0";
   	}
		else{
			cout << "-1";
		}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(void){
	int n, t;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> t;
		if(t%2==0||t%3==0){
			int bi=0;
			int tr=0;
			while(t%2==0){
      		bi++;
      		t = t/2;
			}
   		while(t%3==0){
   			tr++;
   		   t = t/3;
			}
   		if(t==1 && bi>=0 && tr>=bi){
   			cout << 2*tr-bi;
   		}
    		else{
				cout << "-1";
			}
		}
		else if(t==1){
   		cout << "0";
   	}
		else{
			cout << "-1";
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int k;
        cin>>k;
        int a2=0;
        int a3=0;
        if(k==1)
        {
            cout<<0<<endl;
            continue;
        }
        int temp=k;
        while(temp%2==0)
       {
       	temp/=2;
       	a2++;
	   }
	   while(temp%3==0)
	   {
	   	temp/=3;
	   	a3++;
	   }
      	if(temp!=1||a2>a3)
      	{
      		cout<<-1<<endl;
      		continue;
		  }
		 cout<<a3-a2+a3;

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int k;
        cin>>k;
        if(k==1)
        {
            cout<<0;
            continue;
        }
        if(k%3!=0)
        {
            cout<<-1;
            continue;
        }
        int j=0;
        while(k!=1)
        {
            j++;
            if(k%6==0)
            k=k/6;
            else
            k=k*2;
        }
        cout<<k;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int k;
        cin>>k;
        int a2=0;
        int a3=0;
        if(k==1)
        {
            cout<<0<<endl;
            continue;
        }
        int temp=k;
        while(temp%2==0)
       {
       	temp/=2;
       	a2++;
	   }
	   while(temp%3==0)
	   {
	   	temp/=3;
	   	a3++;
	   }
      	if(temp!=1||a2>a3)
      	{
      		cout<<-1<<endl;
      		continue;
		  }
		 cout<<a3-a2+a3<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int k;
        cin>>k;
        int a2=0;
        int a3=0;
        if(k==1)
        {
            cout<<0<<endl;
            continue;
        }
        int a[100001];
        int top=0;
       for(int i=2;i*i<k+1;i++)
       {
          if(a%i==0&&i>3)
          {
              cout<<-1<<endl;
              continue;
          }
          if(a%i==0)
          {
              if(i==2)
              a2++;
              else
              a3++;
          }
       }
       cout<<a3+a3-a2;

    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		int cnt2 = 0, cnt3 = 0;
		while (n % 2 == 0) {
			n /= 2;
			++cnt2;
		}
		while (n % 3 == 0) {
			n /= 3;
			++cnt3;
		}
		if (n == 1 && cnt2 <= cnt3) {
			cout << 2 * cnt3 - cnt2 << endl;
		} else {
			cout << -1 << endl;
		}
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		int cnt2 = 0, cnt3 = 0;
		while (n % 2 == 0) {
			n /= 2;
			++cnt2;
		}
		while (n % 3 == 0) {
			n /= 3;
			++cnt3;
		}
		if (n == 1 && cnt2 <= cnt3) {
			cout << 2 * cnt3 - cnt2 << endl;
		} else {
			cout << -1 << endl;
		}
	}

	return 0;
}


#include<iostream>
#include<bits/stdc++.h>

#define E "\n"
using namespace std;

int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    unsigned long long int t;
    cin >> t;
    while (t--)
    {
        long long int n, k, maxi= 0, result = 0,x;
        cin >> n >> k;
        vector<long long int> vec(k,0);
        for (int i = 0;i < n;++i)
        {
            cin >> x;
            long long int rem=x%k;
            if(!rem)
                continue;
            ++vec[k-rem];
            maxi=max(maxi,vec[k-rem]);
        }
        for(int i=0;i<k;++i)
        {
            if(vec[i]==maxi)
                result=(k*(maxi-1))+i+1
        }
        cout << result <<E;

    }
}


#include<bits/stdc++.h>
#include<iostream>
#define endl "\n"
using namespace std;

void  moves(int n,int *p);
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    unsigned long long int t;
    cin>>t;
    while(t--)
    {

        int n;
        int *p=(int*)malloc(sizeof(int));
        *p=0;
        cin>>n;
        moves(n,p);
        cout<<*p<<endl;

    }
    return 0;
}

void  moves(int n,int *p)
{

    if(n==1 )
        return ;
    if(n%3!=0)
    {
        *p=-1;
        return ;
    }
    ++(*p);
    if(n%6!=0)
    {

        moves(n*2,p);
        return ;
    }
    moves(n/6,p);
    return;

}


/* Author : the_compiler*/

#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int siz=2e5+9;
const int MOD=1e9+7;
set<ll>s;
int t;
ll n,Ans;

int main()
{

   cin>>t;
  A: while(t--)
   {
       cin>>n;Ans=0;
       if(n==1){cout<<0<<endl; goto A;}
       if(n==2){cout<<-1<<endl; goto A;}
       //if(n%6==0){cout<<n/6<<endl;goto A;}
       while(n>1)
       {
          while(n%6==0){n/=6;Ans++;}
          while(n%6!=0 && n<=1e10){n*=2;Ans++;}
          while(n%6==0){n/=6;Ans++;}
          if(n>1e10){cout<<-1<<endl; goto A;}
       }
       if(n==1){cout<<Ans<<endl;goto A;}cout<<-1<<endl;
   }

    return 0;
}


/* Author : the_compiler*/

#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int siz=2e5+9;
const int MOD=1e9+7;
set<ll>s;
int t;
ll n,Ans;

int main()
{

   cin>>t;
  A: while(t--)
   {
       cin>>n;Ans=0;
       if(n==1){cout<<0<<endl; goto A;}
       if(n==2){cout<<-1<<endl; goto A;}
       //if(n%6==0){cout<<n/6<<endl;goto A;}
       while(n>1)
       {
          while(n%6==0){n/=6;Ans++;}
          while(n%6!=0){n*=2;Ans++;if(n%4==0){cout<<-1<<endl; goto A;}}
          while(n%6==0){n/=6;Ans++;}

       }
       if(n==1){cout<<Ans<<endl;goto A;}cout<<-1<<endl;
   }

    return 0;
}


/* Author : the_compiler*/

#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int siz=2e5+9;
const int MOD=1e9+7;
set<ll>s;
int t;
ll n,Ans;

int main()
{

   cin>>t;
  A: while(t--)
   {
       cin>>n;Ans=0;
       if(n==1){cout<<0<<endl; goto A;}
       if(n==2){cout<<-1<<endl; goto A;}
       //if(n%6==0){cout<<n/6<<endl;goto A;}
       while(n>1)
       {
          while(n%6==0){n/=6;Ans++;}
          while(n%6!=0){n*=2;Ans++;if(n%4==0){cout<<-1<<endl; goto A;}}
          while(n%6==0){n/=6;Ans++;}

       }
       cout<<Ans<<endl;
   }

    return 0;
}


/* Author : the_compiler*/

#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int siz=2e5+9;
const int MOD=1e9+7;
set<ll>s;
int t;
ll n,Ans;

int main()
{

   cin>>t;
  A: while(t--)
   {
       cin>>n;Ans=0;
       if(n==1){cout<<0<<endl; goto A;}
       if(n==2){cout<<-1<<endl; goto A;}
       //if(n%6==0){cout<<n/6<<endl;goto A;}
       while(n>1)
       {
          while(n%6==0){n/=6;Ans++;}
          while(n%6!=0 && n<=1e10 && n!=1){n*=2;Ans++;}
          //cout<<n<<endl;
          if(n%6!=0)break;

       }
       if(n==1){cout<<Ans<<endl;goto A;}cout<<-1<<endl;
   }

    return 0;
}


/* Author : the_compiler*/

#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int siz=2e5+9;
const int MOD=1e9+7;
set<ll>s;
int t;
ll n,Ans;

int main()
{
    for(int i=2;i<=1e9;i*=2)s.insert(i);
   cin>>t;
  A: while(t--)
   {
       cin>>n;Ans=0;
       if(n==1){cout<<0<<endl; goto A;}
       if(n==2){cout<<-1<<endl; goto A;}
       //if(n%6==0){cout<<n/6<<endl;goto A;}
       while(n>1)
       {
          while(n%6==0){n/=6;Ans++;}
          while(n%6!=0){n*=2;Ans++;if(s.find(n)!=s.end()){cout<<-1<<endl; goto A;}
                                   if(n>1e11){cout<<-1<<endl; goto A;}}
          while(n%6==0){n/=6;Ans++;}

       }
       cout<<Ans<<endl;
   }

    return 0;
}


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

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

	while(t--){
		ll n;
		cin>>n;

		ll cnt_2=0,cnt_3=0;

		while(!(n%2)){
			n/=2;
			cnt_2++;
		}

		while(!(n%3)){
			n/=3;
			cnt_3++ ;
		}

		if(n!=1||cnt_2>cnt_3) cout<<-1<<endl;
		else cout<< (cnt_3-cnt_2) + cnt_3 <<endl;
	}
    return 0;
}


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

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

	while(t--){
		ll n;
		cin>>n;

		ll cnt_2=0,cnt_3=0;

		while(!(n%2)){
			n/=2;
			cnt_2++;
		}

		while(!(n%3)){
			n/=3;
			cnt_3++;
		}

		if(n!=1||cnt_2>cnt_3) cout<<-1<<endl;
		else {
		    if(cnt_3==cnt_2) cout<<cnt_3<<endl;
        else{
        cout<< (cnt_3-cnt_2) + cnt_3 <<endl;
        }
	}
}
}


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

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

	while(t--){
		ll n;
		cin>>n;

		ll cnt_2=0,cnt_3=0;

		while(!(n%2)){
			n/=2;
			cnt_2++;
		}

		while(!(n%3)){
			n/=3;
			cnt_3++;
		}

		if(n!=1) cout<<-1<<endl;
		else cout<< (cnt_3-cnt_2) + cnt_3 <<endl;
	}
    return 0;
}


#include<iostream>
#include<vector>
#define pb push_back
#define ll long long int
using namespace std;
int main()
{
ll t;
cin>>t;
while(t--){
    ll a,count=0;
    cin>>a;
    ll aa=a;
    while(a>1)
    {
    if(a%6==0)a=a/6;
    else a=a*2;
    if(a==aa)
    {
        break;
    }
      count++;
    }
    if(a==1) cout<<count<<endl;
    else cout<<"-1"<<endl;

}
}


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

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

	while(t--){
		ll n;
		cin>>n;

		ll cnt_2=0,cnt_3=0;

		while(!(n%2)){
			n/=2;
			cnt_2++;
		}

		while(!(n%3)){
			n/=3;
			cnt_3++;
		}

		if(n!=1||cnt_2>cnt_3) cout<<-1<<endl;
		else cout<< (cnt_3-cnt_2) + cnt_3 <<endl;
	}
    return 0;
}


#include <bits/stdc++.h>
#include <math.h>
#include <string>
using namespace std;
int main()
{
	int64_t t, n;
	cin >> t;
	while(t--)
	{
	      cin >> n;
	      int64_t dem = 0;
	      while(n >= 6)
	      {
	            if(n % 6 == 0)
	            n = n / 6;
	            else
	            n = n * 2;
	            dem++;
	      }
	      if(n != 1)
	      cout << -1 << endl;
	      else
	      cout << dem << endl;
	}
}


#include <bits/stdc++.h>
#include <math.h>
#include <string>
using namespace std;
int main()
{
	int64_t t, n;
	cin >> t;
	while(t--)
	{
	      cin >> n;
	      int64_t dem = 0;
	      while(n >= 6)
	      {
	            if(n % 6 == 0)
	            n = n / 6;
	            else
	            n = n * 2;
	            dem++;
	      }
	      if(n == 1)
	      cout << dem << endl;
	      else if(n == 2 || n == 4 || n == 5 || n < 1)
	      cout << -1 << endl;
	      else
	      cout << dem + 2 << endl;
	}
}


#include <bits/stdc++.h>
#include <math.h>
#include <string>
using namespace std;
int main()
{
	int64_t t, n;
	cin >> t;
	while(t--)
	{
	      cin >> n;
	      int64_t dem = 0;
	      while(n >= 6)
	      {
	            if(n % 6 == 0)
	            n = n / 6;
	            else
	            n = n * 2;
	            dem++;
	      }
	      if(n == 1)
	      cout << dem << endl;
	      else if(n == 2 || n == 4 || n == 5)
	      cout << -1 << endl;
	      else
	      cout << n + 2 << endl;
	}
}


#include <bits/stdc++.h>
#include <math.h>
#include <string>
using namespace std;
int main()
{
	int64_t t, n;
	cin >> t;
	while(t--)
	{
	      cin >> n;
	      int64_t dem = 0;
	      while(n > 6)
	      {
	            if(n % 6 == 0)
	            n = n / 6;
	            else
	            n = n * 2;
	            dem++;
	      }
	      if(n != 1)
	      cout << -1 << endl;
	      else
	      cout << dem << endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
int tmp;
int get_yinzi(int t)
{
	int res=0;
	while(tmp%t==0)
	{
		res++;
		tmp/=t;
	}
	return res;
}

int main()
{
	int t,n;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		tmp=n;
		int a=get_yinzi(2);
		int b=get_yinzi(3);
		if(a>b||tmp!=1)
		{
			printf("-1\n");
			continue;
		}
		printf("%d\n",a+2*(b-a));
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int t;
int main(){
	cin>>t;
	int a[t],l=0;
	for(int i=0;i<t;++i){
		long long n;
		cin>>n;
		int ans=0,d=n,cnt3=0,cnt2=0;
		while(d!=1){
			if(d%3==0){
				cnt3++;
				d/=3;
			}
			else if(d%2==0){
				cnt2++;
				d/=2;
			}
			else{
				a[l]=-1;break;
			}
		}
		if(cnt3<cnt2)a[l]=-1;
		if(a[l]!=-1){
			ans+=cnt3-cnt2;
			while(n%3==0){
				n/=3;ans++;
			}
			a[l]=ans;
		}
		l++;
	}
	for(int i=0;i<t;++i){
		cout<<a[i]<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int t;
int main(){
	cin>>t;
	int a[t],l=0;
	for(int i=0;i<t;++i){
		long long n;
		cin>>n;
		int ans=0,d=n,cnt3=0,cnt2=0;
		while(d!=1){
			if(d%3==0){
				cnt3++;
				d/=3;
			}
			else if(d%2==0){
				cnt2++;
				d/=2;
			}
			else{
				a[l]=-1;break;
			}
		}
		if(cnt3<cnt2){a[l]=-1;l++;continue;}
		if(a[l]!=-1){
			a[l]=cnt2+2*(cnt3-cnt2);
		}
		l++;
	}
	for(int i=0;i<t;++i){
		cout<<a[i]<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int t;
int main(){
	cin>>t;
	int a[t],l=0;
	for(int i=0;i<t;++i){
		int n;
		cin>>n;
		int ans=0,d=n,cnt3=0,cnt2=0;
		while(d!=1){
			if(d%3==0){
				cnt3++;
				d/=3;
			}
			else if(d%2==0){
				cnt2++;
				d/=2;
			}
			else{
				a[l]=-1;break;
			}
		}
		if(cnt3<cnt2)a[l]=-1;
		if(a[l]!=-1){
			ans+=cnt3-cnt2;
			while(n%3==0){
				n/=3;ans++;
			}
			a[l]=ans;
		}
		l++;
	}
	for(int i=0;i<t;++i){
		cout<<a[i]<<endl;
	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,a2=0,a3=0;
        bool b=0;
        cin>>n;
        while(1)
        {
            if(n%2==0)
            {
                n/=2;
                a2++;
            }
            else if(n%3==0)
            {
                n/=3;
                a3++;
            }
            else if(n==1)
            {
                b=1;
            }
            else
            {
                cout<<-1<<endl;
                break;
            }
            if(b)
            {
                if(a2>a3)
                {
                    cout<<-1<<endl;
                }
                else
                {
                    cout<<2*a3-a2
                }
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,cnt=0;
		scanf("%d",&n);
		while(n%3==0&&n!=0)
		{
			if(n%2==0)
				n/=6,cnt++;
			else
				n/=3,cnt+=2;
		}
		if(n>1)
			cout<<"-1"<<endl;
		else
			cout<<cnt<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
char a[52];
stack<int>s;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		while(!s.empty())
			s.pop();
		int n,cnt=0;
		scanf("%d",&n);
		scanf("%s",a+1);
		for(int i=1;i<=n;i++)
		{
			if(a[i]=='(')
				s.push(1);
			else if(a[i]==')'&&(!s.empty()))
				s.pop();
			else if(a[i]==')'&&s.empty())
				cnt++;
		}
		cout<<cnt<<endl;
	}

	return 0;
}


#include<iostream>
using namespace std;
#define LL long long
const LL inf=1e9+10;
int main(){
    LL t,num,res;
    cin>>t;
    while(t--){
        res=0;
        cin>>num;
        bool flag=true;
        while(num!=1){
            if(num%6==0) num/=6;
            else num*=2;
            res++;
            if(res==inf){
                cout<<-1<<endl;
                flag=false;
            }
            if(!flag) break;
        }
        if(flag)
            cout<<res<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int T,x,y,q;
	cin>>T;
	while(T--){
		cin>>x;
		int sum1=0,sum2=0;
		if(x==1){
			cout<<"0"<<endl;
			continue;
		}
		if(x%3==0){
			while(x%3==0){x/=3,sum1++;}
			while(x!=1&&x%2==0) x/=2,sum2++;
			if(x>1){cout<<"-1"<<endl;continue;}
		}
		else{
			cout<<"-1"<<endl;
			continue;
		}
		if(sum1>=sum2){
			cout<<sum1-sum2+sum1<<endl;
		}else{
			cout<<"-1"<<endl;
			continue;
		}

	}
}


#include<bits/stdc++.h>
using namespace std;
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
int main()
{
	int t=read();
	while(t--)
	{
		long long x=read();
		int qwq=0,awa=0;
		while(!(x%3)) x/=3,++qwq;
		while(!(x&1)) x>>=1,++awa;
		if(qwq<awa || x!=1) puts("-1"); else printf("%d\n",qwq+qwq-awa);
	}
	return 0;
}


//#include<conio.h>
#include<stdio.h>

#include <iostream>

#include<vector>
#include <string>
main()
{
      using namespace std;
      long long a=0, i=0, j=0, b=0, d=0, e=0, n=0, p=0, q=0, t=0, b1=0, a1=0, a2=0, b2=0;
      long long Z=0;

      char c;

      scanf("%d", &n);
      int A[n];
      for(i=0;i<n;i++)
      {
                      scanf("%d", &A[i]);
      }
      for (int i = 0; i < n-1; i++)
      {
         for (int j = 0; j < n-i-1; j++)
         {
             if (A[j] > A[j+1])
             {
                 int b = A[j];
                 A[j] = A[j+1];
                 A[j+1] = b;
             }
         }
      }
      //for(i=0;i<n;i++) printf("%d ", A[i]);
      a=1;
      for(i=0;i<n;)
      {
                   /*printf("%d ", i);
                   printf("%d ", A[i]);
                   printf("%d ", a);
                   printf("\n");*/
                   if(A[i]<a) i++;
                   else if(A[i]==a){a++;i++;}
                   else if(A[i]>a){A[i]=a;a++;i++;}

      }
      Z=A[n-1]+1;
      printf("%d", Z);

      //getch();
}


	//************************************************************************//
//*Author : Handsome How                                                 *//
//************************************************************************//
//#pragma comment(linker, "/STA    CK:1024000000,1024000000")
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <ctime>
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define foreach(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define fur(i,a,b) for(int i=(a);i<=(b);i++)
#define furr(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#ifdef HandsomeHow
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define dbg(x) cout << #x << " = " << x << endl
#else
#define debug(...)
#define dbg(x)
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const int mod=1000000007;
const double pi=acos(-1);
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
int gcd(int a,int b){return a? gcd(b%a,a):b;}
ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
// (づ°ω°)づe★
//-----------------------------------------------------------------
int numb[111111];
int main(){
#ifdef HandsomeHow
    //freopen("E:\\data.in","r",stdin);
    //freopen("E:\\data.out","w",stdout);
    time_t beginttt = clock();
#endif
	int n;
	gn(n);
	fur(i,1,n)gn(numb[i]);
	if(n == 1){
		cout<<numb[1]+1<<endl;
		return 0;
	}
	sort(numb+1,numb+1+n);
	int last = numb[1];
	fur(i,2,n){
		if(numb[i]-numb[i-1]!=1){
			numb[i] = min(numb[i],numb[i-1]+1);
		}
	}
	sort(numb+1,numb+1+n);
	//fur(i,1,n)dbg(numb[i]);
	fur(i,2,n){
		if(numb[i]-numb[i-1]>1){
			cout<<numb[i-1]+1<<endl;
			return 0;
		}
	}
	cout<<numb[n]+1<<endl;
#ifdef HandsomeHow
	time_t endttt = clock();
    debug("time: %d\n",(int)(endttt - beginttt));
#endif
	return 0;
}


	//************************************************************************//
//*Author : Handsome How                                                 *//
//************************************************************************//
//#pragma comment(linker, "/STA    CK:1024000000,1024000000")
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <ctime>
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define foreach(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define fur(i,a,b) for(int i=(a);i<=(b);i++)
#define furr(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#ifdef HandsomeHow
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define dbg(x) cout << #x << " = " << x << endl
#else
#define debug(...)
#define dbg(x)
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const int mod=1000000007;
const double pi=acos(-1);
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
int gcd(int a,int b){return a? gcd(b%a,a):b;}
ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
// (づ°ω°)づe★
//-----------------------------------------------------------------
int numb[111111];
int main(){
#ifdef HandsomeHow
    //freopen("E:\\data.in","r",stdin);
    //freopen("E:\\data.out","w",stdout);
    time_t beginttt = clock();
#endif
	int n;
	gn(n);
	fur(i,1,n)gn(numb[i]);
	if(n == 1){
		cout<<2<<endl;
		return 0;
	}
	sort(numb+1,numb+1+n);
	int last = numb[1];
	fur(i,2,n){
		if(numb[i]-numb[i-1]!=1){
			numb[i] = min(numb[i],numb[i-1]+1);
		}
	}
	sort(numb+1,numb+1+n);
	//fur(i,1,n)dbg(numb[i]);
	numb[1] = 1;
	fur(i,2,n){
		if(numb[i]-numb[i-1]>1){
			cout<<numb[i-1]+1<<endl;
			return 0;
		}
	}
	cout<<numb[n]+1<<endl;
#ifdef HandsomeHow
	time_t endttt = clock();
    debug("time: %d\n",(int)(endttt - beginttt));
#endif
	return 0;
}


	//************************************************************************//
//*Author : Handsome How                                                 *//
//************************************************************************//
//#pragma comment(linker, "/STA    CK:1024000000,1024000000")
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <ctime>
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define foreach(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define fur(i,a,b) for(int i=(a);i<=(b);i++)
#define furr(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#ifdef HandsomeHow
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define dbg(x) cout << #x << " = " << x << endl
#else
#define debug(...)
#define dbg(x)
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const int mod=1000000007;
const double pi=acos(-1);
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
int gcd(int a,int b){return a? gcd(b%a,a):b;}
ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
// (づ°ω°)づe★
//-----------------------------------------------------------------
int numb[111111];
int main(){
#ifdef HandsomeHow
    //freopen("E:\\data.in","r",stdin);
    //freopen("E:\\data.out","w",stdout);
    time_t beginttt = clock();
#endif
	int n;
	gn(n);
	fur(i,1,n)gn(numb[i]);
	if(n == 1){
		cout<<2<<endl;
		return 0;
	}
	sort(numb+1,numb+1+n);
	int last = numb[1];
	fur(i,2,n){
		if(numb[i]-numb[i-1]!=1){
			numb[i] = min(numb[i],numb[i-1]+1);
		}
	}
	sort(numb+1,numb+1+n);
	//fur(i,1,n)dbg(numb[i]);
	if(numb[1]!=1){
		cout<<1<<endl;
		return 0;
	}
	fur(i,2,n){
		if(numb[i]-numb[i-1]>1){
			cout<<numb[i-1]+1<<endl;
			return 0;
		}
	}
	cout<<numb[n]+1<<endl;
#ifdef HandsomeHow
	time_t endttt = clock();
    debug("time: %d\n",(int)(endttt - beginttt));
#endif
	return 0;
}


	//************************************************************************//
//*Author : Handsome How                                                 *//
//************************************************************************//
//#pragma comment(linker, "/STA    CK:1024000000,1024000000")
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <ctime>
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define foreach(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define fur(i,a,b) for(int i=(a);i<=(b);i++)
#define furr(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#ifdef HandsomeHow
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define dbg(x) cout << #x << " = " << x << endl
#else
#define debug(...)
#define dbg(x)
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const int mod=1000000007;
const double pi=acos(-1);
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
int gcd(int a,int b){return a? gcd(b%a,a):b;}
ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
// (づ°ω°)づe★
//-----------------------------------------------------------------
int numb[111111];
int main(){
#ifdef HandsomeHow
    //freopen("E:\\data.in","r",stdin);
    //freopen("E:\\data.out","w",stdout);
    time_t beginttt = clock();
#endif
	int n;
	gn(n);
	fur(i,1,n)gn(numb[i]);
	if(n == 1){
		if(ans==1) cout<<2<<endl
		else cout<<1<<endl;
		return 0;
	}
	sort(numb+1,numb+1+n);
	int last = numb[1];
	fur(i,2,n){
		if(numb[i]-numb[i-1]!=1){
			numb[i] = min(numb[i],numb[i-1]+1);
		}
	}
	sort(numb+1,numb+1+n);
	//fur(i,1,n)dbg(numb[i]);
	if(numb[1]!=1){
		cout<<1<<endl;
		return 0;
	}
	fur(i,2,n){
		if(numb[i]-numb[i-1]>1){
			cout<<numb[i-1]+1<<endl;
			return 0;
		}
	}
	cout<<numb[n]+1<<endl;
#ifdef HandsomeHow
	time_t endttt = clock();
    debug("time: %d\n",(int)(endttt - beginttt));
#endif
	return 0;
}


	//************************************************************************//
//*Author : Handsome How                                                 *//
//************************************************************************//
//#pragma comment(linker, "/STA    CK:1024000000,1024000000")
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <ctime>
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define foreach(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define fur(i,a,b) for(int i=(a);i<=(b);i++)
#define furr(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#ifdef HandsomeHow
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define dbg(x) cout << #x << " = " << x << endl
#else
#define debug(...)
#define dbg(x)
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const int mod=1000000007;
const double pi=acos(-1);
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
int gcd(int a,int b){return a? gcd(b%a,a):b;}
ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
// (づ°ω°)づe★
//-----------------------------------------------------------------
int numb[111111];
int main(){
#ifdef HandsomeHow
    //freopen("E:\\data.in","r",stdin);
    //freopen("E:\\data.out","w",stdout);
    time_t beginttt = clock();
#endif
	int n;
	gn(n);
	fur(i,1,n)gn(numb[i]);
	if(n == 1){
		cout<<2<<endl;
		return 0;
	}
	sort(numb+1,numb+1+n);

	numb[1] = 1;
	fur(i,2,n){
		if(numb[i]-numb[i-1]!=1){
			numb[i] = min(numb[i],numb[i-1]+1);
		}
	}
	sort(numb+1,numb+1+n);
	//fur(i,1,n)dbg(numb[i]);

	fur(i,2,n){
		if(numb[i]-numb[i-1]>1){
			cout<<numb[i-1]+1<<endl;
			return 0;
		}
	}
	cout<<numb[n]+1<<endl;
#ifdef HandsomeHow
	time_t endttt = clock();
    debug("time: %d\n",(int)(endttt - beginttt));
#endif
	return 0;
}


	//************************************************************************//
//*Author : Handsome How                                                 *//
//************************************************************************//
//#pragma comment(linker, "/STA    CK:1024000000,1024000000")
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <ctime>
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define foreach(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define fur(i,a,b) for(int i=(a);i<=(b);i++)
#define furr(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#ifdef HandsomeHow
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define dbg(x) cout << #x << " = " << x << endl
#else
#define debug(...)
#define dbg(x)
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const int mod=1000000007;
const double pi=acos(-1);
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
int gcd(int a,int b){return a? gcd(b%a,a):b;}
ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
// (づ°ω°)づe★
//-----------------------------------------------------------------
int numb[111111];
int main(){
#ifdef HandsomeHow
    //freopen("E:\\data.in","r",stdin);
    //freopen("E:\\data.out","w",stdout);
    time_t beginttt = clock();
#endif
	int n;
	gn(n);
	fur(i,1,n)gn(numb[i]);
	if(n == 1){
		if(numb[1]==1) cout<<2<<endl;
		else cout<<1<<endl;
		return 0;
	}
	sort(numb+1,numb+1+n);
	int last = numb[1];
	fur(i,2,n){
		if(numb[i]-numb[i-1]!=1){
			numb[i] = min(numb[i],numb[i-1]+1);
		}
	}
	sort(numb+1,numb+1+n);
	//fur(i,1,n)dbg(numb[i]);
	if(numb[1]!=1){
		cout<<1<<endl;
		return 0;
	}
	fur(i,2,n){
		if(numb[i]-numb[i-1]>1){
			cout<<numb[i-1]+1<<endl;
			return 0;
		}
	}
	cout<<numb[n]+1<<endl;
#ifdef HandsomeHow
	time_t endttt = clock();
    debug("time: %d\n",(int)(endttt - beginttt));
#endif
	return 0;
}


/*
"The advantage you had yesterday, will be replaced by the trends of tomorrow.
You dont have to do anything wrong as long as your competitors catch the wave and do it right.

Those who refuse to learn & improve, will definitely one day become redundant & not relevant to the industry.
They will learn the lesson in a hard & expensive way."

"Mistakes have consequences. They can cause companies to lose customers, money and credibility.
But the only thing worse than making a mistake is deciding to never put yourself in a position to make the mistake in the first place.
The risk of stalling innovation & learning, and letting your competitors move faster than you is far more dangerous."
*/

#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define mm(a,b) memset(a,b,sizeof(a))
#define max3(a,b,c) max((max((a),(b))),(c))
#define min3(a,b,c) min((min((a),(b))),(c))
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define VI vector<int>
#define VL vector<ll>
#define FOR(i,a,b) for(i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define PI (2.0)*acos(0.0)
#define sf(n) scanf("%d",&n)
#define pf(n) printf("%d\n",n)
#define get(a) for(int i=0;i<n;i++) {int j; cin>>j; a.pb(j);}
#define show(a) for(auto val:a) {cout << val << ' ';}

int gcd(int a,int b){

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

/***** Code Starts Here *****/

int main(){

    int n;
    sf(n);

    int l=0,s=0;

    VI num;

    get(num);

    sort(all(num));

    for(int i=0;i<(n-1);i++){
        if(num[i+1]-num[i]>1) num[i+1]=num[i]+1;
    }

    //show(num);

    cout << num[n-1]+1 << endl;

    return 0;
}


/*
"The advantage you had yesterday, will be replaced by the trends of tomorrow.
You dont have to do anything wrong as long as your competitors catch the wave and do it right.

Those who refuse to learn & improve, will definitely one day become redundant & not relevant to the industry.
They will learn the lesson in a hard & expensive way."

"Mistakes have consequences. They can cause companies to lose customers, money and credibility.
But the only thing worse than making a mistake is deciding to never put yourself in a position to make the mistake in the first place.
The risk of stalling innovation & learning, and letting your competitors move faster than you is far more dangerous."
*/

#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define mm(a,b) memset(a,b,sizeof(a))
#define max3(a,b,c) max((max((a),(b))),(c))
#define min3(a,b,c) min((min((a),(b))),(c))
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define VI vector<int>
#define VL vector<ll>
#define FOR(i,a,b) for(i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define PI (2.0)*acos(0.0)
#define sf(n) scanf("%d",&n)
#define pf(n) printf("%d\n",n)
#define get(a) for(int i=0;i<n;i++) {int j; sf(j); a.pb(j);}
#define show(a) for(auto val:a) {cout << val << ' ';}

int gcd(int a,int b){

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

/***** Code Starts Here *****/

int main(){

    int n;
    sf(n);

    VI num;

    get(num);

    sort(all(num));

    /*num[0]=1;

    for(int i=0;i<(n-1);i++){
        if(num[i+1]-num[i]>1) num[i+1]=num[i]+1;
    }

    //show(num); cout << endl;

    cout << ++num[n-1] << endl;*/

    int mex=1,i;

    REP(i,n){
        if(num[i]>=mex) mex++;
    }

    cout << mex << endl;

    return 0;
}


/*
"The advantage you had yesterday, will be replaced by the trends of tomorrow.
You dont have to do anything wrong as long as your competitors catch the wave and do it right.

Those who refuse to learn & improve, will definitely one day become redundant & not relevant to the industry.
They will learn the lesson in a hard & expensive way."

"Mistakes have consequences. They can cause companies to lose customers, money and credibility.
But the only thing worse than making a mistake is deciding to never put yourself in a position to make the mistake in the first place.
The risk of stalling innovation & learning, and letting your competitors move faster than you is far more dangerous."
*/

#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define mm(a,b) memset(a,b,sizeof(a))
#define max3(a,b,c) max((max((a),(b))),(c))
#define min3(a,b,c) min((min((a),(b))),(c))
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define VI vector<int>
#define VL vector<ll>
#define FOR(i,a,b) for(i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define PI (2.0)*acos(0.0)
#define pf printf
#define sf scanf
#define sf(n) scanf("%d",&n)
#define pf(n) printf("%d\n",n)
#define get(a) for(int i=0;i<n;i++) {int j; sf(j); a.pb(j);}
#define show(a) for(auto val:a) {cout << val << ' ';}

int gcd(int a,int b){

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

/***** Code Starts Here *****/

int main(){

    int n;
    sf(n);

    VI num;

    get(num);

    sort(all(num));

    num[0]=1;

    for(int i=0;i<(n-1);i++){
        if(num[i+1]-num[i]>1) num[i+1]=num[i]+1;
    }

    //show(num); cout << endl;

    pf(++num[n-1]);

    return 0;
}


/*
"The advantage you had yesterday, will be replaced by the trends of tomorrow.
You dont have to do anything wrong as long as your competitors catch the wave and do it right.

Those who refuse to learn & improve, will definitely one day become redundant & not relevant to the industry.
They will learn the lesson in a hard & expensive way."

"Mistakes have consequences. They can cause companies to lose customers, money and credibility.
But the only thing worse than making a mistake is deciding to never put yourself in a position to make the mistake in the first place.
The risk of stalling innovation & learning, and letting your competitors move faster than you is far more dangerous."
*/

#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define mm(a,b) memset(a,b,sizeof(a))
#define max3(a,b,c) max((max((a),(b))),(c))
#define min3(a,b,c) min((min((a),(b))),(c))
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define VI vector<int>
#define VL vector<ll>
#define FOR(i,a,b) for(i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define PI (2.0)*acos(0.0)
#define sf(n) scanf("%d",&n)
#define pf(n) printf("%d\n",n)
#define get(a) for(int i=0;i<n;i++) {int j; cin>>j; a.pb(j);}
#define show(a) for(auto val:a) {cout << val << ' ';}

int gcd(int a,int b){

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

/***** Code Starts Here *****/

int main(){

    int n;
    sf(n);

    int l=0,s=0;

    VI num;

    get(num);

    sort(all(num));

    num[0]=1;

    for(int i=0;i<(n-1);i++){
        if(num[i+1]-num[i]>1) num[i+1]=num[i]+1;
    }

    //show(num); cout << endl;

    cout << ++num[n-1] << endl;

    return 0;
}


/*
"The advantage you had yesterday, will be replaced by the trends of tomorrow.
You dont have to do anything wrong as long as your competitors catch the wave and do it right.

Those who refuse to learn & improve, will definitely one day become redundant & not relevant to the industry.
They will learn the lesson in a hard & expensive way."

"Mistakes have consequences. They can cause companies to lose customers, money and credibility.
But the only thing worse than making a mistake is deciding to never put yourself in a position to make the mistake in the first place.
The risk of stalling innovation & learning, and letting your competitors move faster than you is far more dangerous."
*/

#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define mm(a,b) memset(a,b,sizeof(a))
#define max3(a,b,c) max((max((a),(b))),(c))
#define min3(a,b,c) min((min((a),(b))),(c))
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define VI vector<int>
#define VL vector<ll>
#define FOR(i,a,b) for(i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define PI (2.0)*acos(0.0)
#define sf(n) scanf("%d",&n)
#define pf(n) printf("%d\n",n)
#define get(a) for(int i=0;i<n;i++) {int j; cin>>j; a.pb(j);}
#define show(a) for(auto val:a) {cout << val << ' ';}

int gcd(int a,int b){

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

/***** Code Starts Here *****/

int main(){

    int n;
    sf(n);

    int l=0,s=0;

    VI num;

    get(num);

    sort(all(num));

    num[0]=1;

    for(int i=0;i<(n-1);i++){
        if(num[i+1]-num[i]>1) num[i+1]=num[i]+1;
    }

    show(num); cout << endl;

    cout << ++num[n-1] << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
map<int, int> arr;

int main(void) {
    int n, x, maxi = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &x);
        arr[x]++;
        maxi = max(maxi, x);
    }
    int hold = n, acc = 0;
    for (int i = 1; i <= maxi; ++i) {
        if (!arr[i]) {
            if (!hold) {
                printf("%d\n", i);
                return 0;
            } else hold--;
        } else {
            acc += arr[i];
            hold = min(n - acc, hold);
        }
    }
    printf("%d\n", maxi + 1);
}


#include <bits/stdc++.h>

using namespace std;
int arr[1000001];

int main(void) {
    int n, x, maxi = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &x);
        arr[x]++;
        x = max(maxi, x);
    }
    int hold = 0;
    for (int i = maxi; i >= 0; --i) {
        if (arr[i])hold += (arr[i] - 1);
        else if (!hold) {
            printf("%d\n", i);
            return 0;
        }
    }
    printf("%d\n", maxi + 1);
}


#include <bits/stdc++.h>

using namespace std;
map<int, int> arr;

int main(void) {
    int n, x, maxi = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &x);
        arr[x]++;
        maxi = max(maxi, x);
    }
    int hold = n, acc = 0;
    for (int i = 1; i <= maxi; ++i) {
        if (!hold) {
            printf("%d\n", i);
            return 0;
        } else hold--;
        acc += arr[i];
        hold = min(n - acc, hold);
    }
    printf("%d\n", maxi + 1);
}


#include <bits/stdc++.h>

using namespace std;
map<int, int> arr;

int main(void) {
    int n, x, maxi = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &x);
        arr[x]++;
        maxi = max(maxi, x);
    }
    int hold = 0;
    for (int i = maxi; i > 0; --i) {
        if (arr[i])hold += (arr[i] - 1);
        else {
            if (!hold) {
                printf("%d\n", i);
                return 0;
            } else hold--;
        }
    }
    printf("%d\n", maxi + 1);
}


#include <bits/stdc++.h>

using namespace std;
int arr[1000000001];

int main(void) {
    int n, x, maxi = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &x);
        arr[x]++;
        maxi = max(maxi, x);
    }
    int hold = 0;
    for (int i = maxi; i > 0; --i) {
        if (arr[i])hold += (arr[i] - 1);
        else {
            if (!hold) {
                printf("%d\n", i);
                return 0;
            } else hold--;
        }
    }
    printf("%d\n", maxi + 1);
}


#include <bits/stdc++.h>

using namespace std;
int arr[1000001];

int main(void) {
    int n, x, maxi = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &x);
        arr[x]++;
        maxi = max(maxi, x);
    }
    int hold = 0;
    for (int i = maxi; i > 0; --i) {
        if (arr[i])hold += (arr[i] - 1);
        else {
            if (!hold) {
                printf("%d\n", i);
                return 0;
            } else hold--;
        }
    }
    printf("%d\n", maxi + 1);
}


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

ll n,a[100010],chk[100010],k,m;

int main(){
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		chk[a[i]]++;
	}
	sort(a,a+n);
	for(ll i=0;i<n;i++){
		if(a[i]<i+1-m){
			m++;
		}
		else if(a[i]!=i+1-m&&a[i]>i+1-m){
			chk[a[i]]--;
			a[i]==i+1-m;
			chk[a[i]]++;
		}
	}
	if(m==0){
		cout<<n+1;
		return 0;
	}
	cout<<n-m+1;
}


#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;

int n,a[100010],chk[100010],k,m;

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		chk[a[i]]++;
	}
	sort(a,a+n);
	m=0;
	for(int i=0;i<n;i++){
		if(a[i]<i+1-m){
			m++;
		}
		else if(a[i]!=i+1-m&&a[i]>i+1-m){
			chk[a[i]]--;
			a[i]==i+1-m;
			chk[a[i]]++;
		}
	}
	if(m==0){
		printf("%d",n+1);
		return 0;
	}
	printf("%d",n-m+1);
}


#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;

int n,a[100010],chk[100010],k,m;

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&k);
		a[i]=100000-k;
		chk[i]++;
	}
	sort(a,a+n);
	m=0;
	for(int i=0;i<n;i++){
		if(a[i]!=i+1-m){
			chk[a[i]]--;
			a[i]==i+1-m;
			chk[a[i]]++;
		}
	}
	if(m==0){
		printf("%d",n+1);
		return 0;
	}
	printf("%d",n-m);
}


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

ll n,a[100010],chk[50000000],k,m;

int main(){
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		chk[a[i]]++;
	}
	sort(a,a+n);
	for(ll i=0;i<n;i++){
		if(a[i]<i+1-m){
			m++;
		}
		else if(a[i]!=i+1-m&&a[i]>i+1-m){
			chk[a[i]]--;
			a[i]==i+1-m;
			chk[a[i]]++;
		}
	}
	if(m==0){
		cout<<n+1;
		return 0;
	}
	cout<<n-m+1;
}


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

ll n,a[100010],chk[100010],k,m;

int main(){
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>=100000){
			chk[100000]++;
		}
		else{
			chk[a[i]]++;
		}
	}
	sort(a,a+n);
	for(ll i=0;i<n;i++){
		if(a[i]<i+1-m){
			m++;
		}
		else if(a[i]!=i+1-m&&a[i]>i+1-m){
			chk[a[i]]--;
			a[i]==i+1-m;
			chk[a[i]]++;
		}
	}
	if(m==0){
		cout<<n+1;
		return 0;
	}
	cout<<n-m+1;
}


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

ll n,a[1000100],chk[1000010],k,m;

int main(){
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		chk[a[i]]++;
	}
	sort(a,a+n);
	for(ll i=0;i<n;i++){
		if(a[i]<i+1-m){
			m++;
		}
		else if(a[i]!=i+1-m&&a[i]>i+1-m){
			chk[a[i]]--;
			a[i]==i+1-m;
			chk[a[i]]++;
		}
	}
	if(m==0){
		cout<<n+1;
		return 0;
	}
	cout<<n-m+1;
}


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

ll n,a[100010],chk[10000000],k,m;

int main(){
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		chk[a[i]]++;
	}
	sort(a,a+n);
	for(ll i=0;i<n;i++){
		if(a[i]<i+1-m){
			m++;
		}
		else if(a[i]!=i+1-m&&a[i]>i+1-m){
			chk[a[i]]--;
			a[i]==i+1-m;
			chk[a[i]]++;
		}
	}
	if(m==0){
		cout<<n+1;
		return 0;
	}
	cout<<n-m+1;
}


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

ll n,a[100010],chk[100000000],k,m;

int main(){
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		chk[a[i]]++;
	}
	sort(a,a+n);
	for(ll i=0;i<n;i++){
		if(a[i]<i+1-m){
			m++;
		}
		else if(a[i]!=i+1-m&&a[i]>i+1-m){
			chk[a[i]]--;
			a[i]==i+1-m;
			chk[a[i]]++;
		}
	}
	if(m==0){
		cout<<n+1;
		return 0;
	}
	cout<<n-m+1;
}


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

ll n,a[100010],chk[32500000],k,m;

int main(){
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		chk[a[i]]++;
	}
	sort(a,a+n);
	for(ll i=0;i<n;i++){
		if(a[i]<i+1-m){
			m++;
		}
		else if(a[i]!=i+1-m&&a[i]>i+1-m){
			chk[a[i]]--;
			a[i]==i+1-m;
			chk[a[i]]++;
		}
	}
	if(m==0){
		cout<<n+1;
		return 0;
	}
	cout<<n-m+1;
}


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

ll n,a[100010],chk[40000000],k,m;

int main(){
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		chk[a[i]]++;
	}
	sort(a,a+n);
	for(ll i=0;i<n;i++){
		if(a[i]<i+1-m){
			m++;
		}
		else if(a[i]!=i+1-m&&a[i]>i+1-m){
			chk[a[i]]--;
			a[i]==i+1-m;
			chk[a[i]]++;
		}
	}
	if(m==0){
		cout<<n+1;
		return 0;
	}
	cout<<n-m+1;
}


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

ll n,a[100010],chk[35000000],k,m;

int main(){
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		chk[a[i]]++;
	}
	sort(a,a+n);
	for(ll i=0;i<n;i++){
		if(a[i]<i+1-m){
			m++;
		}
		else if(a[i]!=i+1-m&&a[i]>i+1-m){
			chk[a[i]]--;
			a[i]==i+1-m;
			chk[a[i]]++;
		}
	}
	if(m==0){
		cout<<n+1;
		return 0;
	}
	cout<<n-m+1;
}


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

ll n,a[100010],chk[30000000],k,m;

int main(){
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		chk[a[i]]++;
	}
	sort(a,a+n);
	for(ll i=0;i<n;i++){
		if(a[i]<i+1-m){
			m++;
		}
		else if(a[i]!=i+1-m&&a[i]>i+1-m){
			chk[a[i]]--;
			a[i]==i+1-m;
			chk[a[i]]++;
		}
	}
	if(m==0){
		cout<<n+1;
		return 0;
	}
	cout<<n-m+1;
}


#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include<functional>
#include <fstream>
#include <iomanip>
#define ii pair<int,int>
#define INF 1000000000
using namespace std;

int main() {
	//freopen("output.txt", "w", stdout);
	int n, arr[100100];
	cin >> n;
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	sort(arr, arr + n);
	int j = 1;
	for (int i = 0; i < n; i++) {
		if (arr[i] == j)
			j++;
		else if (arr[i] > i) {
			arr[i] = j;
			j++;
		}
	}
	int i = 0;
	while (i < n - 1) {
		if (arr[i] == arr[i + 1])
			i++;
		if (arr[i] + 1 != arr[i + 1])
			break;
		i++;
	}
	if (i < n - 1) {
		cout << arr[i] + 1 << endl;
	} else
		cout << arr[n - 1] + 1 << endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include<functional>
#include <fstream>
#include <iomanip>
#define ii pair<int,int>
#define INF 1000000000
using namespace std;

int main() {
	//freopen("output.txt", "w", stdout);
	int n, arr[100100];
	cin >> n;
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	sort(arr, arr + n);
	int j = 1;
	for (int i = 0; i < n; i++) {
		if (arr[i] == j)
			j++;
		else if (arr[i] > j) {
			arr[i] = j;
			j++;
		}
	}
	cout << j << endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include<functional>
#include <fstream>
#include <iomanip>
#define ii pair<int,int>
#define INF 1000000000
using namespace std;

int main() {
	//freopen("output.txt", "w", stdout);
	int n, arr[100100];
	cin >> n;
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	sort(arr, arr + n);
	int j = 1;
	for (int i = 0; i < n; i++) {
		if (arr[i] > i) {
			arr[i] = j;
			j++;
		}
	}
	int i = 0;
	while (i < n - 1) {
		if (arr[i] == arr[i + 1])
			i++;
		if (arr[i] + 1 != arr[i + 1])
			break;
		i++;
	}
	if (i < n - 1) {
		cout << arr[i] + 1 << endl;
	} else
		cout << arr[n - 1] + 1 << endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include<functional>
#include <fstream>
#include <iomanip>
#define ii pair<int,int>
#define INF 1000000000
using namespace std;

int main() {
	//freopen("output.txt", "w", stdout);
	int n, arr[100100];
	cin >> n;
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	sort(arr, arr + n);
	int j = 1;
	for (int i = 0; i < n; i++) {
		if (arr[i] == j)
			j++;
		else if (arr[i] > i) {
			arr[i] = j;
			j++;
		}
	}
	cout << j << endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include<functional>
#include <fstream>
#include <iomanip>
#define ii pair<int,int>
#define INF 1000000000
using namespace std;

int main() {
	//freopen("output.txt", "w", stdout);
	int n, arr[100100];
	cin >> n;
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	sort(arr, arr + n);
	int i = n - 1;
	while (i > 0) {
		if (arr[i] == arr[i - 1])
			i--;
		if (arr[i] - 1 != arr[i - 1])
			break;
		i--;
	}
	if (i > 0) {
		cout << arr[i] - 1 << endl;
	} else
		cout << arr[n - 1] + 1 << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,arr[100001],cnt=1,i;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    for(i=0;i<n;i++)
    {
        if(arr[i]>=cnt)
            cnt++;
    }
    cout<<cnt;
    return 0;
}


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

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


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

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


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

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


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

#define int long long
#define endl '\n'

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

	int n, cur = 1; cin >> n; int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	for (int i = 0; i < n; i++)
		if (a[i] >= cur)
			cur++;
	cout << cur;
}


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

#define int long long
#define endl '\n'

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

	int n; cin >> n; int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];

	asort(a, a + n);
	for (int i = 1; i < n; i++) {
		if (a[i] - a[i - 1] > 1) {
			a[i] = a[i - 1] + 1;
		}
	}

	for (int i = 0; i < n; i++) {
		if (a[i] - a[i - 1] > 1) {
			cout << a[i - 1] + 1 << endl;
			return 0;
		}
	}
	cout << a[n - 1] + 1;
}


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

#define int long long
#define endl '\n'

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

	int n; cin >> n; int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];

	for (int i = 1; i < n; i++) {
		if (a[i] - a[i - 1] > 1) {
			a[i] = a[i - 1] + 1;
		}
	}

	for (int i = 0; i < n; i++) {
		if (a[i] - a[i - 1] > 1) {
			cout << a[i - 1] + 1 << endl;
			return 0;
		}
	}
	cout << a[n - 1] + 1;
}


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

#define int long long
#define endl '\n'

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

	int n; cin >> n; int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];

	if (n != 1) {
		sort(a, a + n);
		for (int i = 1; i < n; i++) {
			if (a[i] - a[i - 1] > 1) {
				a[i] = a[i - 1] + 1;
			}
		}

		for (int i = 0; i < n; i++) {
			if (a[i] - a[i - 1] > 1) {
				cout << a[i - 1] + 1 << endl;
				return 0;
			}
		}
		cout << a[n - 1] + 1;
	} else {
		cout << (a[0] == 2 ? 3 : 2) << endl;
	}
}


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

#define int long long
#define endl '\n'

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

	int n; cin >> n; int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	for (int i = 0; i < n; i++)
		if (a[i] >= cur)
			cur++;
	cout << cur;
}


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

#define int long long
#define endl '\n'

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

	int n; cin >> n;
	int cur = 1;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		if (x >= cur)
			cur++;
	}
	cout << cur;
}


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

#define int long long
#define endl '\n'

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

	int n; cin >> n; int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];

	sort(a, a + n);
	for (int i = 1; i < n; i++) {
		if (a[i] - a[i - 1] > 1) {
			a[i] = a[i - 1] + 1;
		}
	}

	for (int i = 0; i < n; i++) {
		if (a[i] - a[i - 1] > 1) {
			cout << a[i - 1] + 1 << endl;
			return 0;
		}
	}
	cout << a[n - 1] + 1;
}


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

#define int long long
#define endl '\n'

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

	int n; cin >> n; int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];

	if (n != 1) {
		sort(a, a + n);
		for (int i = 1; i < n; i++) {
			if (a[i] - a[i - 1] > 1) {
				a[i] = a[i - 1] + 1;
			}
		}

		for (int i = 0; i < n; i++) {
			if (a[i] - a[i - 1] > 1) {
				cout << a[i - 1] + 1 << endl;
				return 0;
			}
		}
		cout << a[n - 1] + 1;
	} else {
		cout << "2\n";
	}
}


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

int main() {
	int n;
	cin>>n;
	int arr[n];
	for(int i=0 ; i<n ; i++) cin>>arr[i];
	sort(arr,arr+n);
	int ans=0;
	for (int i=0 ; i<n ; i++){
		ans=min(ans+1,arr[i]);
	}
	cout<<++ans;
	return 0;
}


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

int main() {
	int n;
	cin>>n;
	int arr[n];
	for(int i=0 ; i<n ; i++) cin>>arr[i];
	sort(arr,arr+n);
	int ans=0;
	for (int i=0 ; i<n ; i++){
		if(arr[i]<i+1){
			ans=arr[i];
			continue;
		}
		ans++;
	}
	cout<<++ans;
	return 0;
}


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

vector <int> v;

int main() {
	int n,k=0;
	cin>>n;
	k=n+1;
	long long a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if(a[i]<i+1) k--;
	}
	cout<<k;
	return 0;
}


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

int main() {
	int n;
	cin>>n;
	int arr[n];
	for(int i=0 ; i<n ; i++) cin>>arr[i];
	sort(arr,arr+n);
	int ans=n+1;
	for (int i=n-1 ; i>=0 ; i--){
		if(arr[i]<i+1) ans--;
	}
	cout<<ans;
	return 0;
}


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

int main() {
	int n;
	cin>>n;
	int arr[n];
	for(int i=0 ; i<n ; i++) cin>>arr[i];
	sort(arr,arr+n);
	int ans=0;
	for (int i=0 ; i<n ; i++){
		if(arr[i]<i+1){
			ans=i;
			continue;
		}
		ans++;
	}
	cout<<++ans;
	return 0;
}


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

vector <int> v;

int main() {
	int n,k=0;
	cin>>n;
	k=n+1;
	for(int i=0;i<n;i++){
		long long m;
		cin>>m;
		v.push_back(m);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++){
		if(v[i]<i+1) k--;
	}
	cout<<k;
	return 0;
}


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

vector <int> v;

int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int m;
		cin>>m;
		v.push_back(m);
	}
	sort(v.begin(),v.end());
	int r=n+1;
	for(int i=0;i<n;i++){
		if(v[i]<i+1) r--;
	}
	cout<<r;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a, kol = 0, min1 = 10e9;
    cin >> a;
    int s[a];
    for(int i = 0 ; i < a; i++)
    {
        cin >> s[i];
        if(min1 > s[i])
        {
            min1 = s[i];
        }
    }
    sort(s, s + a);
    for(int i = 0; i < a - 1; i ++)
    {
        while(s[i] + 1 < s[i + 1])
        {
            s[i + 1]--;
            kol++;
        }
    }
    if(min1 != 1)
        cout << 1;
    else
        cout << s[a - 1] + 1;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a, kol = 0, min1 = 10e9;
    cin >> a;
    int s[a];
    s[0] = 0;
    for(int i = 1 ; i <= a; i++)
    {
        cin >> s[i];
    }
    if(a == 1)
    {
        cout << 2;
        return 0;
    }
    sort(s, s + a + 1);
    for(int i = 0; i < a; i ++)
    {
        while(s[i] + 1 < s[i + 1])
        {
            s[i + 1]--;
        }
    }
        cout << s[a] + 1;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long a, kol = 0, min1 = 10e9;
    cin >> a;
    long long s[a];
    s[0] = 0;
    for(int i = 1 ; i <= a; i++)
    {
        cin >> s[i];
    }
    if(a == 1)
    {
        cout << 2;
        return 0;
    }
    sort(s, s + a + 1);
    for(int i = 0; i < a; i ++)
    {
        while(s[i] + 1 < s[i + 1])
        {
            s[i + 1]--;
        }
    }
        cout << s[a] + 1;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k = 1;
    cin >> n;
    int s[n];
    for(int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    sort(s + 0, s + n);
    for(int i = 0; i < n; i++)
    {
        if(k < s[i])
            k++;
    }
    cout << k;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k = 1;
    cin >> n;
    int s[n];
    for(int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    sort(s, s + n + 1);
    for(int i = 0; i <= n; i++)
    {
        if(k < s[i])
            k++;
    }
    cout << k;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k = 1;
    cin >> n;
    int s[n];
    for(int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    sort(s, s + n);
    for(int i = 0; i < n; i++)
    {
        if(k <= s[i])
            k++;
    }
    cout << k;
}


#include<bits/stdc++.h>
using namespace std;
set<long long> s;
map<long long,long long> mp,mp1;
vector<long long> v;
set<long long>::iterator it,it1;
long long a[100000],b[100000],arr[100000];
int main()
{
	long long i,j,k,l,m,n,c=0,h,x,y,z,t,ans=0,sum=0,max1=0;
    cin>>n;
    memset(b,0,sizeof(b));
    for(i=0;i<n;i++)
    {
    	cin>>m;
    	s.insert(m);
    	a[i]=m;
    	mp1[m]=1;
    }
    if(s.size()==1)
    {
    	if(*s.begin()==1)
    		m=2;
    	else
    		m=1;
    }
    else
    {
    for(it=s.begin();it!=s.end();it++)
    {
    	//cout<<*it<<" ";
        arr[c++]=*it;
    }
    m=0;
    for(i=0;i<c-1;i++)
    {
    	if(arr[i+1]-arr[i]>1)
    		{
              m=arr[i]+1;
              break;
    		}
    }
    if(m==0)
    	m=arr[c-1];
}
    for(i=0;i<n;i++)
    {
    	if(m==a[i])
    		{
    			m++;
    		}
    	if(a[i]>m)
    		{
    			m++;
    			mp[a[i]]=1;
    		}

    }
    cout<<m<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
set<long long> s;
map<long long,long long> mp,mp1;
vector<long long> v;
set<long long>::iterator it,it1;
long long a[100000],b[100000],arr[100000];
int main()
{
	long long i,j,k,l,m,n,c=0,h,x,y,z,t,ans=0,sum=0,max1=0;
    cin>>n;
    memset(b,0,sizeof(b));
    for(i=0;i<n;i++)
    {
    	cin>>m;
    	s.insert(m);
    	a[i]=m;
    	mp1[m]=1;
    }
    if(s.size()==1)
    {
    	if(*s.begin()==1)
    		m=2;
    	else
    		m=1;
    }
    else
    {
    for(it=s.begin();it!=s.end();it++)
    {
    	//cout<<*it<<" ";
        arr[c++]=*it;
    }
    m=0;
    for(i=0;i<c-1;i++)
    {
    	if(arr[i+1]-arr[i]>1)
    		{
              m=arr[i]+1;
              break;
    		}
    }
    if(m==0)
    	m=arr[c-1];
}
sort(a,a+n);
    for(i=0;i<n;i++)
    {
    	if(m==a[i])
    		{
    			m++;
    		}
    	if(a[i]>m)
    		{
    			m++;
    			mp[a[i]]=1;
    		}

    }
    cout<<m<<endl;
    return 0;
}