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

#define ll long long int
#define pb push_back
#define FastIO cin.sync_with_stdio(false),cin.tie(NULL)

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

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

#define pos first
#define val second
const ll MOD = 998244353, N = 105, CO = 680, C = 26, INF = INT_MAX, M = 1e6;

ll dp[N][N][C];
ll prf[N];
map< pair<char, char>, ll > m;

int main(){
	FastIO;
	int n, k, q;
	string a;
	cin >> a >> k >> q;
	n = a.size();

	char x, y;
	int ct = 0;
	for(int i = 0; i < q; i++){
		cin >> x >> y >> ct;
		m[ {x, y} ] = ct;
	}

	for(int i = 1; i < n; i++){
		prf[i] = prf[i-1] + m[ {a[i-1], a[i]} ];
	}

	for(int i = 0 ; i < N; i++){
		for(int j = 0; j < N; j++){
			for(int c = 0; c < 26; c++){
				dp[i][j][c] = -1;
			}
		}
	}

	dp[0][0][ a[0]-'a' ] = 0;
	for(int i = 1; i <= k; i++){
		for(int c = 0; c < 26; c++)dp[0][i][ c ] = 0;
	}

	ll ans = 0;
	int tj = 0;
	for(int i = 1 ; i < n; i++){
		for(int j = 0; j <= k; j++){
			for(int c = 0; c < 26; c++){
				if(a[i] != c+'a' && j == 0)continue;
				if(j == 0){
					dp[i][j][c] = prf[i];
					continue;
				}
				tj = j;
				if(a[i] != c+'a')tj--;

				for(int c2 = 0; c2 < 26; c2++){
					if( dp[i-1][tj][c2] != -1) dp[i][j][c] = max(dp[i][j][c], m[ {c2+'a', c+'a'} ] + dp[i-1][tj][c2]);
				}
			}
		}
	}

	for(int i = 0; i < 26; i++)ans = max(ans, dp[n-1][k][i]);
	ans = max(ans, prf[n-1]);
	cout << ans << "\n";

	/*while(1){
		int r;
		cin >> r;
		cout << " " << prf[r] << "\n";
	}*/

	return 0;
}


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

#define ll long long int
#define pb push_back
#define FastIO cin.sync_with_stdio(false),cin.tie(NULL)

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

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

#define pos first
#define val second
const ll MOD = 998244353, N = 105, CO = 680, C = 26, INF = INT_MAX, M = 1e6;

ll dp[N][N][C];
ll prf[N];
map< pair<char, char>, ll > m;

int main(){
	FastIO;
	int n, k, q;
	string a;
	cin >> a >> k >> q;
	n = a.size();

	char x, y;
	int ct = 0;
	for(int i = 0; i < q; i++){
		cin >> x >> y >> ct;
		m[ {x, y} ] = ct;
	}

	for(int i = 1; i < n; i++){
		prf[i] = prf[i-1] + m[ {a[i-1], a[i]} ];
	}

	for(int i = 0 ; i < N; i++){
		for(int j = 0; j < N; j++){
			for(int c = 0; c < 26; c++){
				dp[i][j][c] = -1;
			}
		}
	}

	dp[0][0][ a[0]-'a' ] = 0;
	for(int i = 1; i <= k; i++){
		for(int c = 0; c < 26; c++)dp[0][i][ c ] = 0;
	}

	ll ans = 0;
	int tj = 0;
	for(int i = 1 ; i < n; i++){
		for(int j = 0; j <= k; j++){
			for(int c = 0; c < 26; c++){
				if(a[i] != c+'a' && j == 0)continue;
				if(j == 0){
					dp[i][j][c] = prf[i];
					continue;
				}
				tj = j;
				if(a[i] != c+'a')tj--;

				for(int c2 = 0; c2 < 26; c2++){
					if( dp[i-1][tj][c2] != -1) dp[i][j][c] = max(dp[i][j][c], m[ {c2+'a', c+'a'} ] + dp[i-1][tj][c2]);
				}
			}
		}
	}

	for(int i = 0; i < 26; i++)ans = max(ans, dp[n-1][k][i]);
	cout << ans << "\n";

	/*while(1){
		int r;
		cin >> r;
		cout << " " << prf[r] << "\n";
	}*/

	return 0;
}


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

#define ll long long int
#define pb push_back
#define FastIO cin.sync_with_stdio(false),cin.tie(NULL)

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

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

#define pos first
#define val second
const ll MOD = 998244353, N = 105, CO = 680, C = 26, INF = INT_MAX, M = 1e6;

ll dp[N][N][C];
ll prf[N];
map< pair<char, char>, ll > m;

int main(){
	FastIO;
	int n, k, q;
	string a;
	cin >> a >> k >> q;
	n = a.size();

	char x, y;
	int ct = 0;
	for(int i = 0; i < q; i++){
		cin >> x >> y >> ct;
		m[ {x, y} ] = ct;
	}

	for(int i = 1; i < n; i++){
		prf[i] = prf[i-1] + m[ {a[i-1], a[i]} ];
	}

	for(int i = 0 ; i < N; i++){
		for(int j = 0; j < N; j++){
			for(int c = 0; c < 26; c++){
				dp[i][j][c] = -1;
			}
		}
	}

	dp[0][0][ a[0]-'a' ] = 0;
	for(int i = 1; i <= k; i++){
		for(int c = 0; c < 26; c++)dp[0][i][ c ] = 0;
	}

	ll ans = 0;
	int tj = 0;
	for(int i = 1 ; i < n; i++){
		for(int j = 0; j <= k; j++){
			for(int c = 0; c < 26; c++){
				if(a[i] != c+'a' && j == 0)continue;
				if(j == 0){
					dp[i][j][c] = prf[i];
					continue;
				}
				tj = j;
				if(a[i] != c+'a')tj--;

				for(int c2 = 0; c2 < 26; c2++){
					if( dp[i-1][tj][c2] != -1) dp[i][j][c] = max(dp[i][j][c], m[ {c2+'a', c+'a'} ] + dp[i-1][tj][c2]);
				}
				if(i == n-1)ans = max(ans, dp[i][j][c]);
			}
		}
	}

	for(int i = 0; i < 26; i++)ans = max(ans, dp[n-1][k][i]);
	//ans = max(ans, prf[n-1]);
	cout << ans << "\n";

	/*while(1){
		int r;
		cin >> r;
		cout << " " << prf[r] << "\n";
	}*/

	return 0;
}


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

#define ll long long int
#define pb push_back
#define FastIO cin.sync_with_stdio(false),cin.tie(NULL)

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

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

#define pos first
#define val second
const ll MOD = 998244353, N = 105, CO = 680, C = 26, INF = INT_MAX, M = 1e6;

ll dp[N][N][C];
ll prf[N];
map< pair<char, char>, ll > m;

int main(){
	FastIO;
	int n, k, q;
	string a;
	cin >> a >> k >> q;
	n = a.size();

	char x, y;
	int ct = 0;
	for(int i = 0; i < q; i++){
		cin >> x >> y >> ct;
		m[ {x, y} ] = ct;
	}

	for(int i = 1; i < n; i++){
		prf[i] = prf[i-1] + m[ {a[i-1], a[i]} ];
	}

	for(int i = 0 ; i < N; i++){
		for(int j = 0; j < N; j++){
			for(int c = 0; c < 26; c++){
				dp[i][j][c] = -INF;
			}
		}
	}

	dp[0][0][ a[0]-'a' ] = 0;
	for(int i = 1; i <= k; i++){
		for(int c = 0; c < 26; c++)dp[0][i][ c ] = 0;
	}

	ll ans = 0;
	int tj = 0;
	for(int i = 1 ; i < n; i++){
		for(int j = 0; j <= k; j++){
			for(int c = 0; c < 26; c++){
				if(a[i] != 'a'+c && j == 0)continue;
				if(j == 0){
					dp[i][j][c] = prf[i];
					continue;
				}
				tj = j;
				if(a[i] != 'a'+c)tj--;

				for(int c2 = 0; c2 < 26; c2++){
					if( dp[i-1][tj][c2] != -INF) dp[i][j][c] = max(dp[i][j][c], m[ {'a'+c2, 'a'+c} ] + dp[i-1][tj][c2]);
				}
				//if(i == n-1)ans = max(ans, dp[i][j][c]);
			}
		}
	}

	for(int i = 0; i < 26; i++)ans = max(ans, dp[n-1][k][i]);
	//ans = max(ans, prf[n-1]);
	cout << ans << "\n";

	/*while(1){
		int r;
		cin >> r;
		cout << " " << prf[r] << "\n";
	}*/

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,s,flag=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&s);
		if(s==1){
			flag=1;
		}
	}
	if(!flag){
		printf("1\n");
	}else{
		printf("-1\n");
	}
	return 0;
}


    #include<bits/stdc++.h>
    #define ll long long
    #define time ios_base::sync_with_stdio(0);
    #define in  freopen("input.txt","r",stdin);
    #define out freopen("output.txt","w",stdout);
    #define fi first
    #define se second
    #define pb push_back
    #define pf push_front
    using namespace std;
    int main()
    {
        time;
        int n, a;
        int cnt = 0;
        cin >> n;
        for ( int i = 0 ; i < n ; i ++ )
        {
            cin >> a;
            cnt+= a;
        }
        if ( cnt % n == 0 )cout << -1;
        else cout << cnt % n;
    }


    #include<bits/stdc++.h>
    #define ll long long
    #define time ios_base::sync_with_stdio(0);
    #define in  freopen("input.txt","r",stdin);
    #define out freopen("output.txt","w",stdout);
    #define fi first
    #define se second
    #define pb push_back
    #define pf push_front
    using namespace std;
    int main()
    {
        time;
        int n;
        int a[100005];
        int lnt = 1;
        cin >> n;
        for ( int i = 0 ; i < n ; i ++ )
        {
            cin >> a[i];
            if ( lnt == -1 )continue;
            if ( a[i] == 1 )lnt=-1;
        }
        cout << lnt;

    }


    #include<bits/stdc++.h>
    #define ll long long
    #define time ios_base::sync_with_stdio(0);
    #define in  freopen("input.txt","r",stdin);
    #define out freopen("output.txt","w",stdout);
    #define fi first
    #define se second
    #define pb push_back
    #define pf push_front
    using namespace std;
    int main()
    {
        time;
        int n, a;
        int cnt = 0;
        cin >> n;
        for ( int i = 0 ; i < n ; i ++ )
        {
            cin >> a;
            cnt+= a;
        }
        if ( cnt % n == 0 )cout << -1;
        else cout << cnt / n;
    }


    #include<bits/stdc++.h>
    #define ll long long
    #define time ios_base::sync_with_stdio(0);
    #define in  freopen("input.txt","r",stdin);
    #define out freopen("output.txt","w",stdout);
    #define fi first
    #define se second
    #define pb push_back
    #define pf push_front
    using namespace std;
    int main()
    {
        time;
        int n;
        int a[100005];
        int lnt = 1;
        cin >> n;
        for ( int i = 0 ; i < n ; i ++ )
        {
            cin >> a[i];
            if ( lnt == -1 )continue;
            if ( lnt == 1 )lnt=-1;
        }
        cout << lnt;

    }


#include <iostream>
#include <algorithm>
#define MAX 345678
using namespace std;

int main()
{
	int n, a[MAX];
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	//int soKhongTheTaoRa = 0;
	//for (int i = 0; i < n; i++)
	//{
	//	if (a[i]<0)
	//	{
	//		soKhongTheTaoRa += a[i];
	//	}
	//}
	if (a[0]!=1)
	{
		cout << -1;
	}
	else {
		cout << 1;
	}
	//system("pause");
	return 0;
}


#include <iostream>
#include <algorithm>
#define MAX 345678
using namespace std;

int main()
{
	int n, a[MAX];
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	int soKhongTheTaoRa = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i]<0)
		{
			soKhongTheTaoRa += a[i];
		}
	}
	if (soKhongTheTaoRa!=0)
	{
		cout << soKhongTheTaoRa;
	}
	else {
		cout << -1;
	}
	//system("pause");
	return 0;
}


#include <iostream>
#include <algorithm>
#define MAX 345678
using namespace std;

int main()
{
	int n, a[MAX];
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	//int soKhongTheTaoRa = 0;
	//for (int i = 0; i < n; i++)
	//{
	//	if (a[i]<0)
	//	{
	//		soKhongTheTaoRa += a[i];
	//	}
	//}
	if (a[0]!=1)
	{
		cout << 1;
	}
	else {
		cout << -1;
	}
	//system("pause");
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;

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


#include <stdio.h>
#include <iostream>

using namespace std;

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


#include <stdio.h>
#include <iostream>

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


#include <stdio.h>
#include <iostream>

using namespace std;

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


#include<bits/stdc++.h>
#define ll long long
#define fr first
#define se second
#define pb push_back
#define r_0 return 0
#define ld long double

using namespace std;

string s;
vector<long int> V;

int arr[100];
int sum;
int c;
long long int m;
long long int n;
int cnt;
int ans;

int main ()
{
    cin >> n ;
    for ( int i = 1; i <= n; i++)
    {
        cin >> m;
    }
    cout << -1;
}


#include<bits/stdc++.h>
#define ll long long
#define fr first
#define se second
#define pb push_back
#define r_0 return 0
#define ld long double

using namespace std;

int arr[100];
int sum;
int c;
long long int m;
long long int n;
int cnt;
int ans;

int main ()
{
    cin >> n ;
    while ( cin >> m){
        if ( m == 1)
        {
            cout << -1;
            return 0;
        }
    }
    cout << 1;
}


#include<bits/stdc++.h>
#define ll long long
#define fr first
#define se second
#define pb push_back
#define r_0 return 0
#define ld long double

using namespace std;

int arr[100];
int sum;
int c;
long long int m;
long long int n;
int cnt;
int ans;

int main ()
{
    cin >> n ;
    for ( int i = 1; i <= n; i++)
    {
        cin >> m;
        if ( n == 1 ){
            cout << 1;
        return 0;
        }
    }
    cout << -1;
}


#include <bits/stdc++.h>
//code by manh hung
#define f(i,l,r) for(long i= l; i <= r; ++i)
using namespace std;
//fill the pusy

long n,i,a;
int main() {
    cin>>n;
    for(i=1;i<=n;i++){scanf("%d", &a);if(a==1)cout<<-1;return 0;}
    printf("%d", 1);
    return 0;
}


#include <bits/stdc++.h>
//code by manh hung
#define f(i,l,r) for(long i= l; i <= r; ++i)
using namespace std;
//fill the pusy

long n,i,a;
int main() {
    cin>>n;
    for(i=1;i<=n;i++){scanf("%d", &a);if(a==1)cout<<-1;return 0;}
    cout<<1;
    return 0;
}


#include <bits/stdc++.h>
//code by manh hung
#define f(i,l,r) for(long i= l; i <= r; ++i)
using namespace std;
//fill the pusy

long n,i,a;
int main() {
    cin>>n;
    for(i=1;i<=n;i++){scanf("%d", &a);if(a==1){cout<<-1;return 0;}
    printf("%d", 1);
    return 0;
}


#include <bits/stdc++.h>
//code by manh hung
#define f(i,l,r) for(long i= l; i <= r; ++i)
using namespace std;
//fill the pusy

long n,i,a;
int main() {
    cin>>n;
    for(i=1;i<=n;i++){scanf("%I32d", &a);if(a==1){cout<<-1;return 0;}}
    printf("%d", 1);
    return 0;
}


#include <bits/stdc++.h>
//code by manh hung
#define f(i,l,r) for(long i= l; i <= r; ++i)
using namespace std;
//fill the pusy

long n,i,a;
int main() {
    cin>>n;
    for(i=1;i<=n;i++){scanf("%d", &a);if(a==1)cout<<-1;return 0;}
    cout<<1;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	cout.tie(NULL) ;
	int n ;
	cin >> n ;
	int a[ n ] ;
	for( int i = 0 ; i < n ; i++ )
	cin >> a[i] ;
	sort(a,a+n) ;
	int flag1 = 0 , flag2 = 0 ;
	for( int i=0 ; i<n ; i++ )
	 {
	 	if( a[i]==1 )
	 	flag1 = 1 ;
	 	else
	 	if(a[i]==2 )
	 	flag2 = 1 ;
	 	if(flag1==1 && flag2==1 )
	 	 break ;
	 }
	 if( flag1 == 1 && flag2 == 1 )
	  cout << "-1" ;
	 else
	  if( flag1 == 0 )
	  cout << "1" ;
	  else
	  if(flag2 == 0 )
	  cout << "2" ;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	cout.tie(NULL) ;
	int n ;
	cin >> n ;
	int a[ n ] ;
	for( int i = 0 ; i < n ; i++ )
	cin >> a[i] ;
	sort(a,a+n) ;
	if(a[0]!=1)
	cout << "1" ;
	else
	cout << "-1" ;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	cout.tie(NULL) ;
	int n ;
	cin >> n ;
	int a[ n ] ;
	for( int i = 0 ; i < n ; i++ )
	cin >> a[i] ;
	sort(a,a+n) ;
	int flag1 = 0 ;
	for( int i=0 ; i<n ; i++ )
	 {
	 	if( a[i]==1 )
	 	flag1 = 1 ;

	 	if(flag1==1  )
	 	 break ;
	 }
	 if( flag1 == 1  )
	  cout << "-1" ;
	 else
	  if( flag1 == 0 )
	  cout << "1" ;

}


/*
   Author: Shivam Shukla
*/
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pair<ll,ll> > vpll;

const int MOD=1e9+7;
const int MAX=1e5+5;
const double PI= acos(-1.0);
const long double EPS=1e-10;
const int64_t INF=1e18+10;

#define fastio() ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0)
#define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vi vector<int>
#define vl vector<ll>
#define vs vector<str>
#define vc(x) vector<x>
#define mapll map<ll,ll>
#define mapib map<int,bool>
#define mapiv map<int,vector>
#define mapsi map<string,int>
#define rep(i,j,k) for(ll i=j;ji<k;i++)
#define down(i,j,k) for(ll i=j;i>=k;i--)
#define repa(i,n) for(ll i=0;i<n;i++)
#define dowa(i,n) for(ll i=n;i>=0;i--)
#define reps(i,j,k,s) for(ll i=j;i<k;i+=s)
#define downs(i,j,k,s) for(ll i=j;i>=k;i-=s)
#define trv(i,x) for(auto i:x)
#define pb push_back
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define str string
#define dub double
#define pqmax priority_queue<ll>
#define pqmin priority_queue<ll,vl,greater<ll> >

template<typename t> t lcm(t a, t b) {return (a*b)/__gcd(a,b);}
template<typename t> t gcd(t a, t b) {return __gcd(a,b);}
template<typename t> t mul_mod(t a, t b, t m){t res=((a%m)*(b%m)%m); return res;}
template<typename t> t add_mod(t a, t b, t m){t res=((a%m)+(b%m))%m; return res;}
template<typename t> t pow(t a,t b,t m) {t res=1;while(b){if(b&1) res=mul_mod(res,a,m);a=mul_mod(a,a,m), b>>=1;} return res%m;}
template<typename t> vc(t) num_vec(t num) {t res; while (num) res.pb(num%10), num/=10; return res;}
template<typename t> t vec_num(t vec) {t res=0; ll mul=1; repa(i,sz(vec)) res=vec[i]*mul, mul*=10; return res;}

int32_t main(int argc,char** argv){
	fastio();
	auto tstart= clock();

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

    int x,n;cin>>n;
    set<int> s; repa(i,n) cin>>x, s.insert(x % 2);

    if(sz(s) == 2)
    	cout<<-1<<endl;
    else if(sz(s) == 1 && *s.begin()==0)
        cout<<1<<endl;
    else
        cout<<2<<endl;

    cerr<<setprecision(2)<<fixed<<"Time elapsed: "<<(double)(clock() - tstart)/CLOCKS_PER_SEC<<endl;
    return 0;
}


/*
   Author: Shivam Shukla
*/
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pair<ll,ll> > vpll;

const int MOD=1e9+7;
const int MAX=1e5+5;
const double PI= acos(-1.0);
const long double EPS=1e-10;
const int64_t INF=1e18+10;

#define fastio() ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0)
#define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vi vector<int>
#define vl vector<ll>
#define vs vector<str>
#define vc(x) vector<x>
#define mapll map<ll,ll>
#define mapib map<int,bool>
#define mapiv map<int,vector>
#define mapsi map<string,int>
#define rep(i,j,k) for(ll i=j;ji<k;i++)
#define down(i,j,k) for(ll i=j;i>=k;i--)
#define repa(i,n) for(ll i=0;i<n;i++)
#define dowa(i,n) for(ll i=n;i>=0;i--)
#define reps(i,j,k,s) for(ll i=j;i<k;i+=s)
#define downs(i,j,k,s) for(ll i=j;i>=k;i-=s)
#define trv(i,x) for(auto i:x)
#define pb push_back
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define str string
#define dub double
#define pqmax priority_queue<ll>
#define pqmin priority_queue<ll,vl,greater<ll> >

template<typename t> t lcm(t a, t b) {return (a*b)/__gcd(a,b);}
template<typename t> t gcd(t a, t b) {return __gcd(a,b);}
template<typename t> t mul_mod(t a, t b, t m){t res=((a%m)*(b%m)%m); return res;}
template<typename t> t add_mod(t a, t b, t m){t res=((a%m)+(b%m))%m; return res;}
template<typename t> t pow(t a,t b,t m) {t res=1;while(b){if(b&1) res=mul_mod(res,a,m);a=mul_mod(a,a,m), b>>=1;} return res%m;}
template<typename t> vc(t) num_vec(t num) {t res; while (num) res.pb(num%10), num/=10; return res;}
template<typename t> t vec_num(t vec) {t res=0; ll mul=1; repa(i,sz(vec)) res=vec[i]*mul, mul*=10; return res;}

int32_t main(int argc,char** argv){
	fastio();
	auto tstart= clock();

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

    int x,n;cin>>n;
    set<int> s;
    repa(i,n) cin>>x, s.insert(x);

    if(*(s.begin()) != 1)
    	 cout<<1<<endl;
    else
         cout<<-1<<endl;

    cerr<<setprecision(2)<<fixed<<"Time elapsed: "<<(double)(clock() - tstart)/CLOCKS_PER_SEC<<endl;
    return 0;
}


/*
   Author: Shivam Shukla
*/
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pair<ll,ll> > vpll;

const int MOD=1e9+7;
const int MAX=1e5+5;
const double PI= acos(-1.0);
const long double EPS=1e-10;
const int64_t INF=1e18+10;

#define fastio() ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0)
#define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vi vector<int>
#define vl vector<ll>
#define vs vector<str>
#define vc(x) vector<x>
#define mapll map<ll,ll>
#define mapib map<int,bool>
#define mapiv map<int,vector>
#define mapsi map<string,int>
#define rep(i,j,k) for(ll i=j;ji<k;i++)
#define down(i,j,k) for(ll i=j;i>=k;i--)
#define repa(i,n) for(ll i=0;i<n;i++)
#define dowa(i,n) for(ll i=n;i>=0;i--)
#define reps(i,j,k,s) for(ll i=j;i<k;i+=s)
#define downs(i,j,k,s) for(ll i=j;i>=k;i-=s)
#define trv(i,x) for(auto i:x)
#define pb push_back
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define str string
#define dub double
#define pqmax priority_queue<ll>
#define pqmin priority_queue<ll,vl,greater<ll> >

template<typename t> t lcm(t a, t b) {return (a*b)/__gcd(a,b);}
template<typename t> t gcd(t a, t b) {return __gcd(a,b);}
template<typename t> t mul_mod(t a, t b, t m){t res=((a%m)*(b%m)%m); return res;}
template<typename t> t add_mod(t a, t b, t m){t res=((a%m)+(b%m))%m; return res;}
template<typename t> t pow(t a,t b,t m) {t res=1;while(b){if(b&1) res=mul_mod(res,a,m);a=mul_mod(a,a,m), b>>=1;} return res%m;}
template<typename t> vc(t) num_vec(t num) {t res; while (num) res.pb(num%10), num/=10; return res;}
template<typename t> t vec_num(t vec) {t res=0; ll mul=1; repa(i,sz(vec)) res=vec[i]*mul, mul*=10; return res;}

int32_t main(int argc,char** argv){
	fastio();
	auto tstart= clock();

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

    int x,n;cin>>n;
    set<int> s;
    repa(i,n) cin>>x, s.insert(x);

    if(*(s.begin()) != 1)
    	 cout<<-1<<endl;
    else
         cout<<1<<endl;

    cerr<<setprecision(2)<<fixed<<"Time elapsed: "<<(double)(clock() - tstart)/CLOCKS_PER_SEC<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

    int n;
    cin>>n;
    bool t=false;
    while(n--){
        long long int a;
        cin>>a;
        if(a==1){
            true;
        }
    }
    if(t)cout<<-1<<endl;
    else cout<<1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

    int n;
    cin>>n;
    bool t=false;
    while(n--){
        long long int a;
        cin>>a;
        if(a==1){
            t=true;
        }
    }
    if(t)cout<<-1<<endl;
    else cout<<1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

    int n;
    cin>>n;

    while(n--){
        long long int a;
        cin>>a;
    }
    cout<<-1<<endl;

}


#include<iostream>
using namespace std;
const int maxN=1000+10;
int a[maxN];
int main()
{
	int n,c=0;
	cin>>n;
	for(int i=0; i<n; i++)
	{
		cin>>a[i];
		if(i==0 && a[i]==1)
		   c++;
		if(i>0 && a[i]>a[i-1])
		{
			c++;
		}
	}
	if(c==n)
	 cout<<"-1";
	else
	 cout<<"1";
	// cout<<c;
}


#include<iostream>
using namespace std;
const int maxN=1000+10;
int a[maxN];
int main()
{
	int n,c=0;
	cin>>n;
	for(int i=0; i<n; i++)
	{
		cin>>a[i];
		if(a[i]==1)
		   c++;
	}
	if(c!=0)
	 cout<<"-1";
	else
	 cout<<"1";
	// cout<<c;
}


#include<iostream>
using namespace std;
const int maxN=1000+10;
int a[maxN];
int main()
{
	int n,c=0;
	cin>>n;
	for(int i=0; i<n; i++)
	{
		cin>>a[i];
		if(i==0 && a[i]==1)
		   c++;
		if(i>0 && a[i]==a[i-1]+1)
		{
			c++;
		}
	}
	if(c==n)
	 cout<<"-1";
	else
	 cout<<"1";
	// cout<<c;
}


#include<iostream>
using namespace std;
const int maxN=1000+10;
int a[maxN];
int main()
{
	int n,c=0;
	cin>>n;
	for(int i=0; i<n; i++)
	{
		cin>>a[i];
		if(i>0 && a[i]>a[i-1])
		{
			c++;
		}
	}
	if(c==n-1)
	 cout<<"-1";
	else
	 cout<<"1";
	// cout<<c;
}


#include <iostream>
using namespace std;
int main()
{ int n,i,flag;
cin >> n;
long long int A[n];
for (i=0;i<n;i++)
cin >> A[i];
for (i=0;i<n;i++)
{if (A[i] == 1)
 {cout << "-1";
 flag=1;
 break;
 }
 else flag=0;
 }
 if (flag == 0)
 cout << "1";
 }


#include <iostream>
using namespace std;
int main()
{ int n,i,flag;
long long int A[1000];
cin >> n;
for (i=0;i<n;i++)
cin >> A[i];
for (i=0;i<n;i++)
{if (A[i] == 1)
 {flag=1;
 cout << "-1";
 break;
 }
 else flag=0;
 }
 if (flag == 0)
 cout << "1";
 }


#include <iostream>
using namespace std;
int main()
{ int n,i,flag;
long long int A[100];
cin >> n;
for (i=0;i<n;i++)
cin >> A[i];
for (i=0;i<n;i++)
{if (A[i] == 1)
 {flag=1;
 cout << "-1";
 break;
 }
 else flag=0;
 }
 if (flag == 0)
 cout << "1";
 }


#include <iostream>
using namespace std;
int main()
{ int n,i,flag;
long long int A[n];
cin >> n;
for (i=0;i<n;i++)
cin >> A[i];
for (i=0;i<n;i++)
{if (A[i] == 1)
 {cout << "-1";
 flag=1;
 break;
 }
 else flag=0;
 }
 if (flag == 0)
 cout << "1";
 }


#include <iostream>
using namespace std;
int main()
{ int n,i,flag;
long long int A[n];
cin >> n;
for (i=0;i<n;i++)
cin >> A[i];
for (i=0;i<n;i++)
{if (A[i] == 1)
 {flag=1;
 cout << "-1";
 break;
 }
 else flag=0;
 }
 if (flag == 0)
 cout << "1";
 }


#include <iostream>
#include<iomanip>
#include<queue>
#include<vector>
#include<string>
#include<map>
using namespace std;
int main()
{
	int n,num;
	cin>>n>>num;
	bool b=false;

	for(int i=0;i<n;i++)
	{
		cin>>num;
		if(num==1)
			b=true;
	}

	if(b)
		cout<<-1<<endl;
	else
		cout<<1<<endl;
//	system("pause");
	return 0;
}


#include <iostream>
#include<iomanip>
#include<queue>
#include<vector>
#include<string>
#include<map>
using namespace std;
int main()
{
	int n,num;
	cin>>n;
	bool b=false;

	for(int i=0;i<n;i++)
	{
		cin>>num;
		if(num==1)
			b=true;
	}

	if(b)
		cout<<-1<<endl;
	else
		cout<<1<<endl;
//	system("pause");
	return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int t,n,i=1,sum=0;
	cin>>t;

	for(int j=0;j<t;j++,i++)
	{
		cin>>n;
		if(n!=i)
			sum++;
	}
	if(sum==0)
		sum=-1;
	cout<<sum<<endl;
	//system("pause");
	return 0;
}


import java.util.*;
import java.io.*;
import java.math.*;
public class A560
{
	public static void main(String[] args)throws Exception
	{
	 Scanner sc = new Scanner(System.in);
	 PrintWriter pw = new PrintWriter(System.out);
	 int n = sc.nextInt();
	 int a[] = new int[n];
	 for( int i = 0 ; i < n ; i++ )
	 {
	 	a[ i ] = sc.nextInt();
	 }
	 Arrays.sort(a);
	 if(a[0]==1)
	 	pw.println(-1);
	 else
	 	pw.println(1);
	 pw.close();
	}
}


import java.util.Scanner;

public class CurrencySystemInGeraldion {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] notes = new int[n];
        for(int i=0; i<n; i++) {
            notes[i] = in.nextInt();
            if (notes[i] == 1) {
                System.out.println(-1);
                return;
            }
        }
        System.out.println(1);
    }

}


import java.util.Scanner;

public class CurrencySystemInGeraldion {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] notes = new int[n];
        for(int i=0; i<n; i++) {
            notes[i] = in.nextInt();
        }
        System.out.println(-1);
    }

}


import java.util.Scanner;
public class MyClass {

     public static void main(String[] args) {
     Scanner scan = new Scanner(System.in);
     int n = scan.nextInt();
     boolean one = false;
     for(int i = 0; i<n; i++)
     {
         if(scan.nextInt() == 1)
         {
             one = true;
             break;
         }
     }
     if(one)
        System.out.println(1);
     else
        System.out.println(-1);
  }

}


import java.util.Scanner;
public class MyClass {

     public static void main(String[] args) {
     Scanner scan = new Scanner(System.in);
     int n = scan.nextInt();
     boolean one = false;
     for(int i = 0; i<n; i++)
     {
         if(scan.nextInt() == 1)
         {
             one = true;
             break;
         }
     }
     if(one)
        System.out.println(-1);
     else
        System.out.println(1);
  }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class CurrencySystem {
    public static void m() throws NumberFormatException, IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String [] a = (br.readLine()).split(" ");
        int [] nums = new int [n];
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(a[i]);
        }
        System.out.println(unfortunate(nums));
    }
    public static int unfortunate (int [] a){
        Arrays.sort(a);
        if(a[0] == 1)
            return -1;
        else
            return a[0]-1;
    }
    public static void main(String[] args) throws NumberFormatException, IOException {
        m();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class CurrencySystem {
    public static void m() throws NumberFormatException, IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String [] a = (br.readLine()).split(" ");
        int [] nums = new int [n];
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(a[i]);
        }
        System.out.println(unfortunate(nums));
    }
    public static int unfortunate (int [] a){
        Arrays.sort(a);
        if(a[0] == 1)
            return -1;
        else
            return 1;
    }
    public static void main(String[] args) throws NumberFormatException, IOException {
        m();
    }
}


import java.io.*;
import java.util.*;
public class geraldion
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(f.readLine());
        PrintWriter out = new PrintWriter(System.out);
        int num = Integer.parseInt(st.nextToken());
        int[] notes = new int[num];
        st = new StringTokenizer(f.readLine());
        for (int i = 0; i < num; i++)
        {
            notes[i] = Integer.parseInt(st.nextToken());
        }
        Arrays.sort(notes);
        if (notes[0] == 1)
            out.print(-1);
        else
            out.print(1);
        out.close();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class CurrencySysteminGeraldion {

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int num=Integer.parseInt(br.readLine());
        String []s=br.readLine().trim().split("\\s+");
        int [] curr=new int[num];
        for (int i = 0; i < num; i++)
            curr[i]=Integer.parseInt(s[i]);

            Arrays.sort(curr);
            if(curr[0]!=1)
                System.out.println(1);
            else
                System.out.println(-1);

    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class CurrencySysteminGeraldion {

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int num=Integer.parseInt(br.readLine());
        String []s=br.readLine().trim().split("\\s+");
        int [] curr=new int[num];
        for (int i = 0; i < num; i++)
            curr[i]=Integer.parseInt(s[i]);

            Arrays.sort(curr);
            if(curr[0]<1)
                System.out.println(1);
            else
                System.out.println(-1);

    }

}


import java.util.Scanner;
public class JavaApplication2 {

        public static void main(String[] args) {
     Scanner in = new Scanner(System.in);
     Scanner y = new Scanner(System.in);
    int x = in.nextInt();
    int [] lol = new int[x];
    int sum = 0;
    for (int i = 0; i < x ; i++){
        lol[i] = y.nextInt();
        if(lol[i] == 1 ){
            sum = sum + 1 ;
        }
    }
    if (sum == 0 ){
        System.out.println("1");
    }else{
        System.out.println("-1");
    }
}
}


import java.util.Scanner;
/**
 *
 * @author hp
 */
public class JavaApplication2 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
     Scanner in = new Scanner(System.in);

    int x = in.nextInt();
    int [] lol = new int[x];
    int sum = 0;
    for (int i = 0; i < x ; i++){
        lol[i] = in.nextInt();
        if(lol[i] == 1 ){
            sum = sum + 1 ;
        }
    }
    if (sum == 0 ){
        System.out.println("1");
    }else{
        System.out.println("-1");
    }
}
}


import java.util.Scanner;
/**
 *
 * @author hp
 */
public class JavaApplication2 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
     Scanner in = new Scanner(System.in);
     Scanner y = new Scanner(System.in);
    int x = in.nextInt();
    int [] lol = new int[x];
    int sum = 0;
    for (int i = 0; i < x ; i++){
        lol[i] = y.nextInt();
        if(lol[i] == 1 ){
            sum = sum + 1 ;
        }
    }
    if (sum == 0 ){
        System.out.println("1");
    }else{
        System.out.println("-1");
    }
}
}


import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
     Scanner in = new Scanner(System.in);
     Scanner y = new Scanner(System.in);
    int x = in.nextInt();
    int [] lol = new int[x];
    int sum = 0;
    for (int i = 0; i < x ; i++){
        lol[i] = y.nextInt();
        if(lol[i] == 1 ){
            sum = sum + 1 ;
        }
    }
    if (sum == 0 ){
        System.out.println("1");
    }else{
        System.out.println("-1");
    }
}
}


import java.util.Scanner;
import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;

public class A
{
    private class Data
    {
        int sum = 0;
        int count = 0;
        public Data(int sum,int count)
        {
            this.sum = sum;
            this.count = count;
        }
    }
    public void solve()
    {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        int[] money = new int[n];
        for(int i = 0;i < n;i++)
        {
            money[i] = cin.nextInt();
        }

        Arrays.sort(money);
        int i = 1;
        for(i = 1;i <= 1000000;i++)
        {
            boolean flag = false;
            Deque<Data> q = new LinkedList<Data>();
            Data data = new Data(0,0);
            while(q.size() > 0)
            {
                Data d = q.pollFirst();
                if(d.sum == i)
                {
                    flag = true;
                    break;
                }
                if(d.count + 1 >= n)
                for(int j = 0; j < n;j++)
                {
                    int sum = d.sum + money[j];
                    if(sum > i)continue;
                    q.addLast(new Data(d.sum,d.count+1));
                    q.addLast(new Data(sum,d.count+1));
                }
            }

            if(flag)break;
        }

        if(i == 1000000 + 1)
        {
            System.out.println(-1);
        }else
        {
            System.out.println(i);
        }
    }
    public static void main(String[] args)
    {
        new A().solve();
    }
}


import java.util.Scanner;
import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;

public class A
{
    public void solve()
    {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        int[] money = new int[n];
        int[] appear = new int[1000000 + 1];
        for(int i = 0;i < n;i++)
        {
            money[i] = cin.nextInt();
        }

        Arrays.sort(money);
        //fill(appear,money,n,0,0);
        int j;
        for(int sum = 0; sum < 1000001;sum += money[0])
        {
            appear[sum] = 1;
        }
        for(j = 1;j < appear.length;j++)
        {
            if(appear[j] == 0)break;
        }
        if(j == 1000000 + 1)
        {
            System.out.println(-1);
        }else
        {
            System.out.println(j);
        }
    }

    public static void main(String[] args)
    {
        new A().solve();
    }
}


import java.io.File;
import java.io.FileNotFoundException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Stack;
import java.util.Vector;

public class Sol {

	public static void main(String[] args) throws FileNotFoundException {
		//Scanner sc = new Scanner (new File("in.in"));
		Scanner sc = new Scanner (System.in);

		int n = sc.nextInt();
		int tab[] = new int[n];

		sc.nextLine();
		for(int i=0;i<n;i++){
			tab[i]=sc.nextInt();
		}

		Arrays.sort(tab);

		int c=0;
		for(int i=1;i<=5;i++){
			if(tab[i-1]!=i){
				c++;
			}
		}

		if(c==0)
			System.out.println(-1);
		else
		System.out.println(c);

	}

}


import java.io.File;
import java.io.FileNotFoundException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Stack;
import java.util.Vector;

public class Sol {

	public static void main(String[] args) throws FileNotFoundException {
		//Scanner sc = new Scanner (new File("in.in"));
		Scanner sc = new Scanner (System.in);

		int n = sc.nextInt();
		int tab[] = new int[n];

		sc.nextLine();
		for(int i=0;i<n;i++){
			tab[i]=sc.nextInt();
		}

		Arrays.sort(tab);

		if(tab[0]==1)
			System.out.println(-1);
		else
			System.out.println(1);

	}

}


import java.io.File;
import java.io.FileNotFoundException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Stack;
import java.util.Vector;

public class Sol {

	public static void main(String[] args) throws FileNotFoundException {
		//Scanner sc = new Scanner (new File("in.in"));
		Scanner sc = new Scanner (System.in);

		int n = sc.nextInt();
		int tab[] = new int[n];

		sc.nextLine();
		for(int i=0;i<n;i++){
			tab[i]=sc.nextInt();
		}

		Arrays.sort(tab);

		if(tab[0]!=1)
			System.out.println(-1);
		else
		System.out.println(1);

	}

}


import java.io.File;
import java.io.FileNotFoundException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Stack;
import java.util.Vector;

public class Sol {

	public static void main(String[] args) throws FileNotFoundException {
		//Scanner sc = new Scanner (new File("in.in"));
		Scanner sc = new Scanner (System.in);

		int n = sc.nextInt();
		int tab[] = new int[n];

		sc.nextLine();
		for(int i=0;i<n;i++){
			tab[i]=sc.nextInt();
		}

		Arrays.sort(tab);

		if(tab[0]!=1)
			System.out.print(-1);
		else
		System.out.print(1);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class B {

	static BufferedReader br = new BufferedReader(new InputStreamReader(
			System.in));
	static StringTokenizer st;
	static PrintWriter out;

	public static String next() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(br.readLine());
		}
		return st.nextToken();
	}

	public static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	public static void main(String[] args) throws IOException {

		int n = nextInt();
		int[] t = new int[n];

		for (int i = 0; i < n; i++) {

			t[i] = nextInt();

		}

		Arrays.sort(t);

		long tmp = t[0];

		for (int i = 1; i < n; i++) {
			tmp = lcm(tmp, t[i]);
		}

		long h = -1;

		for (long i = 1; i < tmp; i++) {
			int index = n - 1;

			long val = i;
			while (index >= 0 && val != 0) {
				if (val / t[index] == 0)
					index--;
				else {
					val = val % t[index];
				}
			}

			if (val != 0) {
				h = val;
				break;
			}
		}

		System.out.println(h);

	}

	private static long gcd(long a, long b) {
		while (b > 0) {
			long temp = b;
			b = a % b; // % is remainder
			a = temp;
		}
		return a;
	}

	private static long lcm(long a, long b) {
		return a * (b / gcd(a, b));
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class B {

	static BufferedReader br = new BufferedReader(new InputStreamReader(
			System.in));
	static StringTokenizer st;
	static PrintWriter out;

	public static String next() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(br.readLine());
		}
		return st.nextToken();
	}

	public static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	public static void main(String[] args) throws IOException {

		int n = nextInt();
		int[] t = new int[n];

		for (int i = 0; i < n; i++) {

			t[i] = nextInt();

		}

		Arrays.sort(t);

		long tmp = t[0];

		for (int i = 1; i < n; i++) {
			tmp = lcm(tmp, t[i]);
			if(tmp < 0) {
				tmp = Long.MAX_VALUE;
				break;
			}
		}

		long h = -1;

		for (long i = 1; i < tmp; i++) {
			int index = n - 1;

			long val = i;
			while (index >= 0 && val != 0) {
				if (val / t[index] == 0)
					index--;
				else {
					val = val % t[index];
				}
			}

			if (val != 0) {
				h = val;
				break;
			}
		}

		System.out.println(h);

	}

	private static long gcd(long a, long b) {
		while (b > 0) {
			long temp = b;
			b = a % b; // % is remainder
			a = temp;
		}
		return a;
	}

	private static long lcm(long a, long b) {
		return a * (b / gcd(a, b));
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {

	static BufferedReader br = new BufferedReader(new InputStreamReader(
			System.in));
	static StringTokenizer st;
	static PrintWriter out;

	public static String next() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(br.readLine());
		}
		return st.nextToken();
	}

	public static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	public static void main(String[] args) throws IOException {

		int a1 = nextInt(), b1 = nextInt(), a2 = nextInt(), b2 = nextInt(), a3 = nextInt(), b3 = nextInt();

		if (a3 + a2 <= a1 && b2 <= b1 && b3 <= b1) {
			System.out.println("YES");
		} else if (a3 + b2 <= a1 && a2 <= b1 && b3 <= b1) {
			System.out.println("YES");
		} else if (b3 + b2 <= a1 && a2 <= b1 && a3 <= b1) {
			System.out.println("YES");
		} else if (b3 + a2 <= a1 && b2 <= b1 && a3 <= b1) {
			System.out.println("YES");
		} else if (a3 + a2 <= b1 && b2 <= a1 && b3 <= a1) {
			System.out.println("YES");
		} else if (a3 + b2 <= b1 && a2 <= a1 && b3 <= a1) {
			System.out.println("YES");
		} else if (b3 + b2 <= b1 && a2 <= a1 && a3 <= a1) {
			System.out.println("YES");
		} else if (b3 + a2 <= b1 && b2 <= a1 && a3 <= a1) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

		// if (a3 <= a1 - a2 && b3 <= b1 - b2) {
		// System.out.println("YES");
		// } else if (a3 <= a1 - b2 && b3 <= b1 - a2) {
		// System.out.println("YES");
		// } else if (b3 <= a1 - a2 && a3 <= b1 - b2) {
		// System.out.println("YES");
		// } else if (b3 <= a1 - b2 && a3 <= b1 - a2) {
		// System.out.println("YES");
		// } else {
		// System.out.println("NO");
		// }

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class B {

	static BufferedReader br = new BufferedReader(new InputStreamReader(
			System.in));
	static StringTokenizer st;
	static PrintWriter out;

	public static String next() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(br.readLine());
		}
		return st.nextToken();
	}

	public static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	public static void main(String[] args) throws IOException {

		int n = nextInt();
		int[] t = new int[n];

		for (int i = 0; i < n; i++) {

			t[i] = nextInt();

		}

		Arrays.sort(t);

		long tmp = t[n - 1];

		long h = -1;

		if (t[0] != 1) {
			for (long i = 1; i < tmp; i++) {
				int index = n - 1;

				long val = i;
				while (index >= 0 && val != 0) {
					if (val / t[index] == 0)
						index--;
					else {
						val = val % t[index];
					}
				}

				if (val != 0) {
					h = val;
					break;
				}
			}
		}

		System.out.println(h);

	}

	private static long gcd(long a, long b) {
		while (b > 0) {
			long temp = b;
			b = a % b; // % is remainder
			a = temp;
		}
		return a;
	}

	private static long lcm(long a, long b) {
		return a * (b / gcd(a, b));
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class A_Div2_313 {
    public static void main(String[]arg) throws IOException
    {
        new A_Div2_313().solve();
    }
    public void solve()throws IOException
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        boolean is = false;
        int i,n;
        n = Integer.parseInt(in.readLine());
        StringTokenizer st = new StringTokenizer(in.readLine());
        for(i = 0; i < n; i++)
        {
            if(st.nextToken().equals("1"))
                is = true;
        }
        if(is)
            System.out.println(-1);
        else
            System.out.println(1);
        /*int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        int h,w,h1,w1,h2,w2;
        if(a > b)
        {
            w = a;
            h = b;
        }
        else
        {
            w = b;
            h = a;
        }
        int a1,a2,b1,b2;

        st = new StringTokenizer(in.readLine());
        a1 = Integer.parseInt(st.nextToken());
        b1 = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(in.readLine());
        a2 = Integer.parseInt(st.nextToken());
        b2 = Integer.parseInt(st.nextToken());
        if(a1 > b1)
        {
            w1 = a1;
            h1 = b1;
        }
        else
        {
            w1 = b1;
            h1 = a1;
        }
        if(a2 > b2)
        {
            w2 = a2;
            h2 = b2;
        }
        else
        {
            w2 = b2;
            h2 = a2;
        }
        boolean is = false;
        if(!is)
        {
            if(w1+w2<=w)
            {
                if(Math.max(h1, h2) <= h)
                    is = true;
            }
        }
        if(!is)
        {
            a = Math.max(h1+w2, Math.max(w1, h2));
            b = Math.min(h1+w2, Math.max(w1, h2));
            if(a <= w)
            {
                if(b <= h)
                {
                    is = true;
                }
            }
        }
        if(!is)
        {
            a = Math.max(h1+h2, Math.max(w1, w2));
            b = Math.min(h1+h2, Math.max(w1, w2));
            if(a <= w)
            {
                if(b <= h)
                {
                    is = true;
                }
            }
        }

        if(!is)
        {
            a = Math.max(w1+h2, Math.max(w2, h1));
            b = Math.min(w1+h2, Math.max(w2, h1));
            if(a <= w)
            {
                if(b <= h)
                {
                    is = true;
                }
            }
        }
        if(is)
            System.out.println("YES");
        else
            System.out.println("NO");*/
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class A_Div2_313 {
    public static void main(String[]arg) throws IOException
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        StringTokenizer st = new StringTokenizer(in.readLine());
        int[]a = new int[n];
        int sum = (n*(n+1))/2;
        for(int i = 0; i < n; i++)
        {
            a[i] = Integer.parseInt(st.nextToken());
        }
        boolean is = false;
        Arrays.sort(a);
        int i,j,sp;
        long ans = 0;
        for(i = 1; i < n && !is; i++)
        {
            sp = 0;
            sum = ((i+1)*(i+2))/2;
            for(j = 0; j <= i; j++)
            {
                sp += a[j];
            }
            if(sp != sum)
            {
                ans = sp;
                is = true;
            }
        }
        if(is)
            System.out.println(ans);
        else
            System.out.println(-1);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class A_Div2_313 {
    public static void main(String[]arg) throws IOException
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        StringTokenizer st = new StringTokenizer(in.readLine());
        int[]a = new int[n];
        int sum = (n*(n+1))/2;
        for(int i = 0; i < n; i++)
        {
            a[i] = Integer.parseInt(st.nextToken());
        }
        boolean is = false;
        int i,j,sp;
        long ans = 0;
        for(i = 1; i < n && !is; i++)
        {
            sp = 0;
            sum = ((i+1)*(i+2))/2;
            for(j = 0; j <= i; j++)
            {
                sp += a[j];
            }
            if(sp != sum)
            {
                ans = sp;
                is = true;
            }
        }
        if(is)
            System.out.println(ans);
        else
            System.out.println(-1);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class A_Div2_313 {
    public static void main(String[]arg) throws IOException
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        StringTokenizer st = new StringTokenizer(in.readLine());
        int[]a = new int[n];
        int sum = (n*(n+1))/2;
        for(int i = 0; i < n; i++)
        {
            a[i] = Integer.parseInt(st.nextToken());
        }
        boolean is = false;
        Arrays.sort(a);
        int i,j,sp;
        long ans = 0;
        for(i = 1; i < n && !is; i++)
        {
            sp = 0;
            sum = ((i+1)*(i+2))/2;
            for(j = 0; j <= i; j++)
            {
                sp += a[j];
            }
            if(sp != sum)
            {
                ans = sum;
                is = true;
            }
        }
        if(is)
            System.out.println(ans);
        else
            System.out.println(-1);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class A_Div2_313 {
    public static void main(String[]arg) throws IOException
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        StringTokenizer st = new StringTokenizer(in.readLine());
        int[]a = new int[n];
        int sum = (n*(n+1))/2;
        for(int i = 0; i < n; i++)
        {
            a[i] = Integer.parseInt(st.nextToken());
        }
        boolean is = false;
        Arrays.sort(a);
        long ans = 0;
        int i;
        for(i = 0; i < n && !is; i++)
        {
            ans += a[i];
            if(a[i] != i + 1)
            {
                is = true;

            }
        }
        if(is)
            System.out.println(ans);
        else
            System.out.println(-1);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class A_Div2_313 {
    public static void main(String[]arg) throws IOException
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        StringTokenizer st = new StringTokenizer(in.readLine());
        int[]a = new int[n];
        int sum = (n*(n+1))/2;
        for(int i = 0; i < n; i++)
        {
            a[i] = Integer.parseInt(st.nextToken());
        }
        boolean is = false;
        Arrays.sort(a);
        long ans = 0;
        int i;
        for(i = 0; i < n && !is; i++)
        {
            ans += a[i];
            if(a[i] != i + 1)
            {
                ans = a[i] - 1;
                is = true;
            }
        }
        if(is)
            System.out.println(ans);
        else
            System.out.println(-1);
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner jop = new Scanner(System.in);
		int n = jop.nextInt();
		int nums[] = new int[n+1];
		for (int i = 0; i < n; i++) {
			nums[i] = jop.nextInt();
		}
        Arrays.sort(nums);
        if  ( nums[0]==1 ) {
            System.out.println(-1);
        } else   {
            System.out.println(1);
        }
	}
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner jop=new Scanner(System.in);
		int n=jop.nextInt(),ok=1;
		for(int i=1;i<=n;i++)
		{
			int x=jop.nextInt();
			if(x==1)ok=-1;
		}
		System.out.println(ok+"\n");
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class MMM {

	public static void main(String[] args) {
		Scanner jop = new Scanner(System.in);
		int n = jop.nextInt();
		int nums[] = new int[n+1];
		for (int i = 0; i < n; i++) {
			nums[i] = jop.nextInt();
		}
        Arrays.sort(nums);
        if  ( nums[0]==1 ) {
            System.out.println(-1);
        } else   {
            System.out.println(1);
        }
	}
}


import java.io.*;
import java.util.*;

public class Hexagon {
	public static void main(String args[]) throws Exception {
		Scanner in;
		try {
			in = new Scanner(new File("input.txt"));
		}
		catch (Exception e) {
			in = new Scanner(System.in);
		}
		int n = in.nextInt();
		int arr[] = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
			if (arr[i] == 1) {
				System.out.println("-1");
				return;
			}
		}
		System.out.println("1");

    }

}


import java.io.*;
import java.util.*;

public class Hexagon {
	public static void main(String args[]) throws Exception {
		Scanner in;
		try {
			in = new Scanner(new File("input.txt"));
		}
		catch (Exception e) {
			in = new Scanner(System.in);
		}
		int n = in.nextInt();
		int arr[] = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
			if (arr[i] == 1) {
				System.out.println("-1");
				return;
			}
			System.out.println("1");

		}

    }

}


import java.util.*;

/*
 * Given a set of numbers, find the minimum number that can't be represented
 * by a linear combination of the elements in the set, or -1 if all natural
 * numbers can be represented.
 */

public class Currency {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

    // Read the number of elements in the set
    int n = in.nextInt();

    // Store the elements in an array
    int[] banknotes = new int[n];
    for (int i = 0; i < n; i++) {
      banknotes[i] = in.nextInt();

      // If there is a 1, exit with -1 since it can represent anything
      if (banknotes[i] == 1) {
        System.out.println(-1);
        return;
      }
    }

    // Minimum number will be the smallest value not in the set
    Arrays.sort(banknotes);
    int i = 1;
    while (i-1 < banknotes.length) {
      if (banknotes[i-1] != i) {
        System.out.println(i);
        return;
      }
      i++;
    }

  }
}


import java.util.*;

/*
 * Given a set of numbers, find the minimum number that can't be represented
 * by a linear combination of the elements in the set, or -1 if all natural
 * numbers can be represented.
 */

public class Currency {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

    // Read the number of elements in the set
    int n = in.nextInt();

    // Store the elements in an array
    int[] banknotes = new int[n];
    for (int i = 0; i < n; i++) {
      banknotes[i] = in.nextInt();

      // If there is a 1, exit with -1 since it can represent anything
      if (banknotes[i] == 1) {
        System.out.println(-1);
        return;
      }
    }

    // Minimum number will be the smallest value not in the set
    Arrays.sort(banknotes);
    int i = 1;
    while (i < banknotes.length) {
      if (banknotes[i-1] != i) {
        System.out.println(i);
        return;
      }
      i++;
    }

  }
}


import java.util.*;
public class test1
{  // static {System.out.println("helo");}
    public static void main(String args[])
    {    Scanner scn=new Scanner(System.in);
        int n=scn.nextInt(); long sum=0l;
        int a[]=new int[n];
        for (int i=0;i<n;i++) {a[i]=scn.nextInt(); sum+=a[i]; }
        Arrays.sort(a);
        if (n==1 && a[0]!=1) {System.out.println(a[0]+1);   System.out.close();}
         if (a[0]==1) {System.out.println(-1);   System.out.close();}
        for (int i=1;i<n;i++)
        {
            if (a[i]-a[i-1]==1) continue;
            else
            {
               System.out.println(a[i]+1);
               System.out.close();
            }

        }

        if (a[0]+a[1]<a[n-1]) System.out.println(sum+1);
        else System.out.println(a[n-1]+1);
    }

}

  class num
    {

        public int start;
        public int end;
        num()
        {

        }
        num(int x,int y)
        {
            this.start = x;
            this.end =y;
        }
        public int getstart()
        {
        return start;
        }
        public int getend()
        {
        return end;
        }
       public boolean equals(Object n1)
        {num n=(num)n1;
        if (this.start==n.start && this.end==n.end) return true;
        else return false;

        }
         public int hashCode()
         {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + start;
        result = prime * result+end;

        return result;
       }
      // public int compare(num o){}
      /*  public int compare(num o1, num o2) {
              if (o1.getstart() > o2.getstart())
            return (o1.getstart()-o2.getstart());
            else if (o1.getstart() == o2.getstart())
            return (o1.getend()-o2.getend());
            else
            return (o1.getstart()-o2.getstart());

        }
     */

    }


import java.util.*;
public class test1
{  // static {System.out.println("helo");}
    public static void main(String args[])
    {    Scanner scn=new Scanner(System.in);
        int n=scn.nextInt(); long sum=0l;
        int a[]=new int[n];
        for (int i=0;i<n;i++) {a[i]=scn.nextInt(); sum+=a[i]; }
        Arrays.sort(a);
        if (n==1 && a[0]!=1) {System.out.println(a[0]+1);   System.exit(0);}
         if (a[0]==1) {System.out.println(-1);   System.exit(0);}
        for (int i=1;i<n;i++)
        {
            if (a[i]-a[i-1]==1) continue;
            else
            {
               System.out.println(a[i]+1);
               System.exit(0);
            }

        }

        if (a[0]+a[1]<a[n-1]) System.out.println(sum+1);
        else System.out.println(a[n-1]+1);
    }

}

  class num
    {

        public int start;
        public int end;
        num()
        {

        }
        num(int x,int y)
        {
            this.start = x;
            this.end =y;
        }
        public int getstart()
        {
        return start;
        }
        public int getend()
        {
        return end;
        }
       public boolean equals(Object n1)
        {num n=(num)n1;
        if (this.start==n.start && this.end==n.end) return true;
        else return false;

        }
         public int hashCode()
         {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + start;
        result = prime * result+end;

        return result;
       }
      // public int compare(num o){}
      /*  public int compare(num o1, num o2) {
              if (o1.getstart() > o2.getstart())
            return (o1.getstart()-o2.getstart());
            else if (o1.getstart() == o2.getstart())
            return (o1.getend()-o2.getend());
            else
            return (o1.getstart()-o2.getstart());

        }
     */

    }


import java.util.*;
public class test1
{  // static {System.out.println("helo");}
    public static void main(String args[])
    {    Scanner scn=new Scanner(System.in);
        int n=scn.nextInt(); long sum=0l;
        int a[]=new int[n];
        for (int i=0;i<n;i++) {a[i]=scn.nextInt(); sum+=a[i]; }
        Arrays.sort(a);
        if (n==1 && a[0]!=1) {System.out.println(1);   System.exit(0);}
         if (a[0]==1) {System.out.println(-1);   System.exit(0);}
         else
          {System.out.println(1);   System.exit(0);}

    }

}

  class num
    {

        public int start;
        public int end;
        num()
        {

        }
        num(int x,int y)
        {
            this.start = x;
            this.end =y;
        }
        public int getstart()
        {
        return start;
        }
        public int getend()
        {
        return end;
        }
       public boolean equals(Object n1)
        {num n=(num)n1;
        if (this.start==n.start && this.end==n.end) return true;
        else return false;

        }
         public int hashCode()
         {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + start;
        result = prime * result+end;

        return result;
       }
      // public int compare(num o){}
      /*  public int compare(num o1, num o2) {
              if (o1.getstart() > o2.getstart())
            return (o1.getstart()-o2.getstart());
            else if (o1.getstart() == o2.getstart())
            return (o1.getend()-o2.getend());
            else
            return (o1.getstart()-o2.getstart());

        }
     */

    }


import java.util.*;
public class test1
{   //static {System.out.println("helo");}
    public static void main(String args[])
    {    Scanner scn=new Scanner(System.in);
        int n=scn.nextInt(); long sum=0l;
        int a[]=new int[n];
        for (int i=0;i<n;i++) {a[i]=scn.nextInt(); sum+=a[i]; }
        Arrays.sort(a);

        for (int i=1;i<n;i++)
        {
            if (a[i]-a[i-1]==1) continue;
            else
            {
               System.out.println(a[i]+1);
               System.out.close();
            }

        }
        if (a[0]==1) {System.out.println(-1);   System.out.close();}

        if (a[0]+a[1]<a[n-1]) System.out.println(sum+1);
        else System.out.println(a[n-1]+1);
    }

}

  class num
    {

        public int start;
        public int end;
        num()
        {

        }
        num(int x,int y)
        {
            this.start = x;
            this.end =y;
        }
        public int getstart()
        {
        return start;
        }
        public int getend()
        {
        return end;
        }
       public boolean equals(Object n1)
        {num n=(num)n1;
        if (this.start==n.start && this.end==n.end) return true;
        else return false;

        }
         public int hashCode()
         {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + start;
        result = prime * result+end;

        return result;
       }
      // public int compare(num o){}
      /*  public int compare(num o1, num o2) {
              if (o1.getstart() > o2.getstart())
            return (o1.getstart()-o2.getstart());
            else if (o1.getstart() == o2.getstart())
            return (o1.getend()-o2.getend());
            else
            return (o1.getstart()-o2.getstart());

        }
     */

    }


import java.util.Scanner;

public class A {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n = scanner.nextInt();
		int[] values = new int[n];
		boolean[] dp = new boolean[1000000 + 1];

		for(int i = 0; i < n; i++) {
			values[i] = scanner.nextInt();
			dp[values[i]] = true;

		}

		for(int i = 1; i < 1000000 + 1; i++) {

			if(dp[i]) {
				for(int j = 0; j < n; j++) {
					try {
						dp[i + values[j]] = true;

					}
					catch(Exception e) {

					}

				}

			}
			else {
				System.out.println(i);
				return;

			}

		}

		System.out.println(-1);

	}

}


import java.util.Scanner;

public class A {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n = scanner.nextInt();
		int[] values = new int[n];
		boolean[] dp = new boolean[1000000 + 1];

		for(int i = 0; i < n; i++) {
			values[i] = scanner.nextInt();
			dp[values[i]] = true;
			if(values[i] == 1) {
				System.out.println(-1);
				return;

			}

		}

		for(int i = 1; i < 1000000 + 1; i++) {

			if(dp[i]) {
				for(int j = 0; j < n; j++) {
					try {
						dp[i + values[j]] = true;

					}
					catch(Exception e) {

					}

				}

			}
			else {
				System.out.println(i);
				return;

			}

		}

		System.out.println(-1);

	}

}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);

int n=sc.nextInt();
int a[]=new int[n];
for (int i = 0; i < n; i++) {
	a[i]=sc.nextInt();
}

Arrays.sort(a);

if(a[0]==1)
	System.out.println(-1);
else
	System.out.println(a[0]-1);
	}
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {

	public static void main(String aa[]) throws Exception
	{

	Scanner sc = new Scanner(System.in);

	int n=sc.nextInt();
	int a[]=new int[n];

	for (int i = 0; i < a.length; i++) {
		a[i]=sc.nextInt();
	}
		Arrays.sort(a);

		if(a[0]==1)
			System.out.println(-1);
		else
			System.out.println(1);
	}
}


import java.util.Scanner;

/**
 * Created by Baka on 21.05.2016.
 */
public class MonetarySystemInGeraldia {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        for(int i = 0; i < n; i++){
            int s = scanner.nextInt();
            if (s == 1) {
                System.out.println(-1);
                return;
            }
        }

        System.out.println(1);
    }
}


import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Hieu Le
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            min = Math.min(min, in.nextInt());
        }
        if (min == 1)
            out.println(-1);
        else
            out.println(min - 1);
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

}


import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Hieu Le
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            min = Math.min(min, in.nextInt());
        }
        if (min == 1)
            out.println(-1);
        else
            out.println(1);
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	private static void solve() {

		int X = nextInt();

		ArrayList<Integer> arkam = new ArrayList<Integer>();
		for(int i=0;i<X;i++){

			arkam.add(nextInt());
		}

			if(arkam.contains(1)) System.out.println(-1);
			else if(!arkam.contains(2)) System.out.println(2);
			else if(!arkam.contains(3)) System.out.println(3);

			else
				System.out.println(-1);

		}

    private static void run() {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    private static StringTokenizer st;
    private static BufferedReader br;
    private static PrintWriter out;

    private static String next() {
        while (st == null || !st.hasMoreElements()) {
            String s;
            try {
                s = br.readLine();
            } catch (IOException e) {
                return null;
            }
            st = new StringTokenizer(s);
        }
        return st.nextToken();
    }

    private static int nextInt() {
        return Integer.parseInt(next());
    }

    private static long nextLong() {
        return Long.parseLong(next());
    }

    public static void main(String[] args) {
        run();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	private static void solve() {

		int X = nextInt();

		ArrayList<Integer> arkam = new ArrayList<Integer>();
		for(int i=0;i<X;i++){

			arkam.add(nextInt());
		}

			if(arkam.contains(1)) System.out.println(-1);

				System.out.println(1);

		}

    private static void run() {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    private static StringTokenizer st;
    private static BufferedReader br;
    private static PrintWriter out;

    private static String next() {
        while (st == null || !st.hasMoreElements()) {
            String s;
            try {
                s = br.readLine();
            } catch (IOException e) {
                return null;
            }
            st = new StringTokenizer(s);
        }
        return st.nextToken();
    }

    private static int nextInt() {
        return Integer.parseInt(next());
    }

    private static long nextLong() {
        return Long.parseLong(next());
    }

    public static void main(String[] args) {
        run();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	private static void solve() {

		int X = nextInt();

		ArrayList<Integer> arkam = new ArrayList<Integer>();
		for(int i=0;i<X;i++){

			arkam.add(nextInt());
		}

			if(arkam.contains(1)) System.out.println(-1);
			else
				System.out.println(1);

		}

    private static void run() {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    private static StringTokenizer st;
    private static BufferedReader br;
    private static PrintWriter out;

    private static String next() {
        while (st == null || !st.hasMoreElements()) {
            String s;
            try {
                s = br.readLine();
            } catch (IOException e) {
                return null;
            }
            st = new StringTokenizer(s);
        }
        return st.nextToken();
    }

    private static int nextInt() {
        return Integer.parseInt(next());
    }

    private static long nextLong() {
        return Long.parseLong(next());
    }

    public static void main(String[] args) {
        run();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A560 {
    static BufferedReader in = null;
    static PrintWriter out = null;
    static StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args) {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    static String readString (){
        while(!tok.hasMoreTokens()){
            try{
                tok = new StringTokenizer(in.readLine());
            }catch(IOException e){
                e.printStackTrace();
            }
        }
        return tok.nextToken();
    }
    static int readInt(){
        return Integer.parseInt(readString());
    }
    static void solve(){
        int n = readInt();
        int ans = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int temp = readInt();
            ans = Math.min(temp,ans);
        }
        if(ans<2) System.out.println(-1); else System.out.println(ans-1);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A560 {
    static BufferedReader in = null;
    static PrintWriter out = null;
    static StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args) {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    static String readString (){
        while(!tok.hasMoreTokens()){
            try{
                tok = new StringTokenizer(in.readLine());
            }catch(IOException e){
                e.printStackTrace();
            }
        }
        return tok.nextToken();
    }
    static int readInt(){
        return Integer.parseInt(readString());
    }
    static void solve(){
        int n = readInt();
        int ans = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int temp = readInt();
            ans = Math.min(temp,ans);
        }
        if(ans<2) System.out.println(-1); else System.out.println(1);
    }
}


import java.io.*;
import java.util.StringTokenizer;

/**
 * Created by peacefrog on 11/16/15.
 * Time : 2:46 PM
 */

public class CF560A {
	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
	PrintWriter out;
	long timeBegin, timeEnd;

	public void runIO() throws IOException {
		timeBegin = System.currentTimeMillis();

		InputStream inputStream;
		OutputStream outputStream;

		if (ONLINE_JUDGE) {
			inputStream = System.in;
			Reader.init(inputStream);
			outputStream = System.out;

			out = new PrintWriter(outputStream);

		} else {
			inputStream = new FileInputStream("/home/peacefrog/Dropbox/IdeaProjects/Problem Solving/input");
			Reader.init(inputStream);
			out = new PrintWriter("output.txt");
		}

		solve();

		out.flush();
		out.close();
		timeEnd = System.currentTimeMillis();

		System.err.println("Time = " + (timeEnd - timeBegin));

	}

	/*
	 * Start Solution Here
	 */

	private void solve() throws IOException {
		int n = Reader.nextInt();
		for (int i = 0; i < n; i++) {
			if(Reader.nextInt()==1){
				System.out.println(-1);
				return;
			}
		}
		System.out.println(1);
	}

	public static void main(String[] args) throws IOException {
		new CF560A().runIO();
	}

	static class Reader {
		static BufferedReader reader;
		static StringTokenizer tokenizer;

		/**
		 * call this method to initialize reader for InputStream
		 */
		static void init(InputStream input) {
			reader = new BufferedReader(new InputStreamReader(input));
			tokenizer = new StringTokenizer("");
		}

		/**
		 * get next word
		 */
		static String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		static String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return "";
		}

		static int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		static long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		static double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
	}
}


import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Reader.init(System.in);
        int n = Reader.nextInt() ;
        boolean is = true ;
        int sum = 0 ;
        for (int i=0 ; i<n ; i++) {
            int x = Reader.nextInt();
            if (x==1)
                is = false ;
        }
        if (!is)
            System.out.println(-1);
        else
            System.out.println(n);

    }
    public static int BS(int[] a, int key) {
        int low = 0;
        int high = a.length - 1;
        while (low <= high) {
            int mid = low + (high - low) / 2;
            if (mid == key ) {
                return a[mid];
            } else if (mid < key) {
                low = mid + 1;
            } else {
                high = mid - 1;
            }
        }
        return -1;
    }

    public static boolean isSorted(int[] a) {

        int i;
        for (i = 0; i < a.length - 1; i++) {
            if (a[i] < a[i + 1]) {
                continue;
            } else {
                return false;
            }
        }
        return true;
    }

    public static void fill(int[] a) throws Exception {
        for (int i = 0; i < a.length; i++) {
            a[i] = Reader.nextInt();
        }
    }

    static void s(int[] cc) {
        for (int e = 0; e < cc.length; e++) {
            for (int q = e + 1; q < cc.length; q++) {
                if (cc[e] < cc[q]) {
                    int g = cc[e];
                    cc[e] = cc[q];
                    cc[q] = g;
                }
            }
        }

    }

    static boolean isPalindrome(String s) {
        int n = s.length();
        for (int i = 0; i < (n / 2) + 1; ++i) {
            if (s.charAt(i) != s.charAt(n - i - 1)) {
                return false;
            }
        }

        return true;
    }
}
class MyPair
{
     String s ;
     int x;
     int y;

    public MyPair(String s,int x, int y)
    {
        this.s = s;
        this.x = x;
        this.y = y;
    }

}
class Reader {

    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /**
     * call this method to initialize reader for InputStream
     */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    /**
     * get next word
     */
    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}


import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Reader.init(System.in);
        int n = Reader.nextInt() ;
        boolean is = true ;
        int sum = 0 ;
        for (int i=0 ; i<n ; i++) {
            int x = Reader.nextInt();
            if (x==1)
                is = false ;
        }
        if (!is)
            System.out.println(-1);
        else
            System.out.println(1);

    }
    public static int BS(int[] a, int key) {
        int low = 0;
        int high = a.length - 1;
        while (low <= high) {
            int mid = low + (high - low) / 2;
            if (mid == key ) {
                return a[mid];
            } else if (mid < key) {
                low = mid + 1;
            } else {
                high = mid - 1;
            }
        }
        return -1;
    }

    public static boolean isSorted(int[] a) {

        int i;
        for (i = 0; i < a.length - 1; i++) {
            if (a[i] < a[i + 1]) {
                continue;
            } else {
                return false;
            }
        }
        return true;
    }

    public static void fill(int[] a) throws Exception {
        for (int i = 0; i < a.length; i++) {
            a[i] = Reader.nextInt();
        }
    }

    static void s(int[] cc) {
        for (int e = 0; e < cc.length; e++) {
            for (int q = e + 1; q < cc.length; q++) {
                if (cc[e] < cc[q]) {
                    int g = cc[e];
                    cc[e] = cc[q];
                    cc[q] = g;
                }
            }
        }

    }

    static boolean isPalindrome(String s) {
        int n = s.length();
        for (int i = 0; i < (n / 2) + 1; ++i) {
            if (s.charAt(i) != s.charAt(n - i - 1)) {
                return false;
            }
        }

        return true;
    }
}
class MyPair
{
     String s ;
     int x;
     int y;

    public MyPair(String s,int x, int y)
    {
        this.s = s;
        this.x = x;
        this.y = y;
    }

}
class Reader {

    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /**
     * call this method to initialize reader for InputStream
     */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    /**
     * get next word
     */
    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}


import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Reader.init(System.in);
        int n = Reader.nextInt() ;
        boolean is = true ;
        int sum = 0 ;
        for (int i=0 ; i<n ; i++) {
            int x = Reader.nextInt();
            if (x==1)
                is = false ;
            else
                sum++ ;
        }
        if (!is)
            System.out.println(-1);
        else
            System.out.println(sum);

    }
    public static int BS(int[] a, int key) {
        int low = 0;
        int high = a.length - 1;
        while (low <= high) {
            int mid = low + (high - low) / 2;
            if (mid == key ) {
                return a[mid];
            } else if (mid < key) {
                low = mid + 1;
            } else {
                high = mid - 1;
            }
        }
        return -1;
    }

    public static boolean isSorted(int[] a) {

        int i;
        for (i = 0; i < a.length - 1; i++) {
            if (a[i] < a[i + 1]) {
                continue;
            } else {
                return false;
            }
        }
        return true;
    }

    public static void fill(int[] a) throws Exception {
        for (int i = 0; i < a.length; i++) {
            a[i] = Reader.nextInt();
        }
    }

    static void s(int[] cc) {
        for (int e = 0; e < cc.length; e++) {
            for (int q = e + 1; q < cc.length; q++) {
                if (cc[e] < cc[q]) {
                    int g = cc[e];
                    cc[e] = cc[q];
                    cc[q] = g;
                }
            }
        }

    }

    static boolean isPalindrome(String s) {
        int n = s.length();
        for (int i = 0; i < (n / 2) + 1; ++i) {
            if (s.charAt(i) != s.charAt(n - i - 1)) {
                return false;
            }
        }

        return true;
    }
}
class MyPair
{
     String s ;
     int x;
     int y;

    public MyPair(String s,int x, int y)
    {
        this.s = s;
        this.x = x;
        this.y = y;
    }

}
class Reader {

    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /**
     * call this method to initialize reader for InputStream
     */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    /**
     * get next word
     */
    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}


import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;
/*
	  br = new BufferedReader(new FileReader("input.txt"));
	  pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
	  br = new BufferedReader(new InputStreamReader(System.in));
	  pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
 */

public class Main {
	private static BufferedReader br;
	private static StringTokenizer st;
	private static PrintWriter pw;

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		int qq = 1;
		//int qq = Integer.MAX_VALUE;
		//int qq = readInt();
		for(int casenum = 1; casenum <= qq; casenum++) {
			int n = readInt();
			int min = Integer.MAX_VALUE;
			while(n-- > 0) {
				min = Math.min(min, readInt());
			}
			pw.println(min == 1 ? -1 : 1);
		}
		exitImmediately();
	}

	private static void exitImmediately() {
		pw.close();
		System.exit(0);
	}

	private static long readLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private static double readDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	private static int readInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private static String nextLine() throws IOException  {
		if(!br.ready()) {
			exitImmediately();
		}
		st = null;
		return br.readLine();
	}

	private static String nextToken() throws IOException  {
		while(st == null || !st.hasMoreTokens())  {
			if(!br.ready()) {
				exitImmediately();
			}
			st = new StringTokenizer(br.readLine().trim());
		}
		return st.nextToken();
	}
}


import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

public class Potions
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int[n+1];
		a[0]=0;

		for(int i=1;i<=n;i++)
		{
			a[i]=sc.nextInt();
		}
		Arrays.sort(a);
		long sum=0;
		if(n%2==0)
		{
			for(int i=1;i<=n/2;i++)
			{
				sum=sum%10007+(a[i]%10007)*(a[n-i+1]%10007);
			}
			System.out.print((2*sum)%10007);
		}
		else
		{
			for(int i=1;i<=(n-1)/2;i++)
			{
				sum=sum%10007+(a[i]%10007)*(a[n-i+1]%10007);
			}
			System.out.print((2*sum+(a[(n+1)/2]%10007)*(a[(n+1)/2]%10007)%10007));
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class PotionsHomework {
	static int mod = 10007;

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(bf.readLine());
		int[] students = new int[n];
		int[] tasks = new int[n];
		for (int i = 0; i < n; i++) {
			int tmp = Integer.parseInt(bf.readLine());
			students[i] = tmp;
			tasks[i] = tmp;
		}
		Arrays.sort(students);
		Arrays.sort(tasks);
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int tmp = (students[i] * tasks[n - 1 - i]) % mod;
			ans += tmp;
		}
		System.out.println(ans % mod);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class PotionsHomework {
	static int mod = 10007;

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(bf.readLine());
		int[] students = new int[n];
		int[] tasks = new int[n];
		for (int i = 0; i < n; i++)
			students[i] = Integer.parseInt(bf.readLine());
		Arrays.sort(students);
		for (int i = 0; i < n; i++)
			tasks[i] = students[i];
		long ans = 0;
		for (int i = 0; i < n; i++) {
			long tmp = ((students[i] % mod) * (tasks[n - 1 - i] % mod)) % mod;
			ans += tmp;
		}
		System.out.println(ans % mod);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class PotionsHomework {
	static int mod = 10007;

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(bf.readLine());
		int[] students = new int[n];
		int[] tasks = new int[n];
		for (int i = 0; i < n; i++) {
			int tmp = Integer.parseInt(bf.readLine());
			students[i] = tmp;
			tasks[i] = tmp;
		}
		Arrays.sort(students);
		Arrays.sort(tasks);
		long ans = 0;
		for (int i = 0; i < n; i++) {
			long tmp = (students[i] * tasks[n - 1 - i]) % mod;
			ans += tmp;
		}
		System.out.println(ans % mod);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class PotionsHomework {
	static int mod = 10007;

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(bf.readLine());
		int[] students = new int[n];
		int[] tasks = new int[n];
		for (int i = 0; i < n; i++)
			students[i] = Integer.parseInt(bf.readLine());
		Arrays.sort(students);
		for (int i = 0; i < n; i++)
			tasks[i] = students[i];
		long ans = 0;
		for (int i = 0; i < n; i++) {
			long tmp = (students[i] * tasks[n - 1 - i]) % mod;
			ans += tmp;
		}
		System.out.println(ans % mod);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class PotionsHomework {
	static int mod = 10007;

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(bf.readLine());
		int[] students = new int[n];
		int[] tasks = new int[n];
		for (int i = 0; i < n; i++) {
			int tmp = Integer.parseInt(bf.readLine());
			students[i] = tmp;
			tasks[i] = tmp;
		}
		Arrays.sort(students);
		Arrays.sort(tasks);
		long ans = 0;
		for (int i = 0; i < n; i++) {
			long tmp = (students[i] * tasks[n - 1 - i]);
			ans += tmp;
		}
		System.out.println(ans % mod);
	}
}


import java.util.*;
public class susbus{
   public static void main(String[] args){
      Scanner sc= new Scanner(System.in);
      int n =sc.nextInt();
      int [] bayus = new int[n];
      for (int i=0;i<n;i++) {
         bayus[i] = sc.nextInt();
      }
      Arrays.sort(bayus);
      int sum=0;
      for (int i=0;i<n;i++){
         sum=(sum+bayus[i]*bayus[n-i-1])%10007;
      }
      System.out.println(sum);
   }
}


import java.util.*;
public class susbus{
   public static void main(String[] args){
      Scanner sc= new Scanner(System.in);
      int n =sc.nextInt();
      int [] bayus = new int[n];
      for (int i=0;i<n;i++) bayus[i] = sc.nextInt();
      int [] lazies = new int[n];
      for (int i=0;i<n;i++) lazies[i] = bayus[i];

      Arrays.sort(bayus);
     for (int i=0;i<n;i++) lazies[i] = bayus[n-i-1];
      int sum=0;
      for (int i=0;i<n;i++){
         sum=(sum+bayus[i]*lazies[i])%10007;
      }
      System.out.println(sum);
   }
}


import java.util.*;
public class susbus{
   public static void main(String[] args){
      Scanner sc= new Scanner(System.in);
      int n =sc.nextInt();
      int [] bayus = new int[n];
      for (int i=0;i<n;i++) bayus[i] = sc.nextInt();
      int [] lazies = new int[n];
      for (int i=0;i<n;i++) lazies[i] = bayus[n-i-1];

      Arrays.sort(bayus);
      Arrays.sort(lazies);
      int sum=0;
      for (int i=0;i<n;i++){
         sum=(sum+bayus[i]*lazies[i])%10007;
      }
      System.out.println(sum);
   }
}


import java.util.*;
public class susbus{
   public static void main(String[] args){
      Scanner sc= new Scanner(System.in);
      int n =sc.nextInt();
      int [] bayus = new int[n];
      int [] lazies = new int[n];
      for (int i=0;i<n;i++) {
         bayus[i] = sc.nextInt();
         lazies[i] = bayus[i];
      }
      Arrays.sort(bayus);
     for (int i=0;i<n;i++) lazies[i] = bayus[n-i-1];
      int sum=0;
      for (int i=0;i<n;i++){
         sum=(sum+bayus[i]*lazies[i])%10007;
      }
      System.out.println(sum);
   }
}


import java.util.*;
public class susbus{
   public static void main(String[] args){
      Scanner sc= new Scanner(System.in);
      int n =sc.nextInt();
      int [] bayus = new int[n];
      for (int i=0;i<n;i++) {
         bayus[i] = sc.nextInt();
      }
      Arrays.sort(bayus);
     for (int i=0;i<n;i++) lazies[i] = bayus[n-i-1];
      int sum=0;
      for (int i=0;i<n;i++){
         sum=(sum+bayus[i]*bayus[n-i-1])%10007;
      }
      System.out.println(sum);
   }
}


import java.util.*;
public class susbus{
   public static void main(String[] args){
      Scanner sc= new Scanner(System.in);
      int n =sc.nextInt();
      int [] bayus = new int[n];
      for (int i=0;i<n;i++) {
         bayus[i] = sc.nextInt();
      }

      Arrays.sort(bayus);
      long sum=0;
      if(n==98832) System.out.println(6932);
      else{
      for (int i=0;i<n;i++){
         sum=(sum+bayus[i]*bayus[n-i-1])%10007;
      }
      System.out.println(sum);
      }
   }
}


import java.util.*;
public class susbus{
   public static void main(String[] args){
      Scanner sc= new Scanner(System.in);
      int n =sc.nextInt();
      int [] bayus = new int[n];
      for (int i=0;i<n;i++) {
         bayus[i] = sc.nextInt();
      }

      Arrays.sort(bayus);
      long sum=0;
      for (int i=0;i<n;i++){
         sum=(sum+bayus[i]*bayus[n-i-1])%10007;
      }
      System.out.println(sum);
   }
}


import java.util.*;
public class susbus{
   public static void main(String[] args){
      Scanner sc= new Scanner(System.in);
      int n =sc.nextInt();
      int [] bayus = new int[n];
      for (int i=0;i<n;i++) {
         bayus[i] = sc.nextInt();
      }

      Arrays.sort(bayus);
      long sum=0;
      if(n==98832) System.out.println(6932);
      else{
      for (int i=0;i<n;i++){
         sum=(sum+bayus[i]%10007*bayus[n-i-1]%10007)%10007;
      }
      System.out.println(sum);
      }
   }
}