#include <bits/stdc++.h>

using namespace std;

int minit(vector<long long> t) {
    long long mini = 100000000000000;
    int mini_s;
    for (int i = 1; i < t.size(); i++) {
        mini = min(t[i], mini);
        mini_s = i;
    }
    return mini_s;
}

int maxt(vector<long long> t) {
    long long maxi = 0;
    int max_s;
    for (int i = 0; i < t.size(); i++) {
        maxi = max(t[i], maxi);
        max_s = i;
    }
    return max_s;
}

int min_flash(int m, vector<int> cards) {
    int sum = 0;
    sort(cards.begin(), cards.end());
    for(int i = cards.size() - 1; i > -1 ; i--) {
        sum += cards[i];
        if (sum >= m) {
            return cards.size() - i;
        }
    }
}

//map <int, int> read_map(int n) {
//    map <int, int> elems;
//    for(int i = 0; i < n; ++i) {
//        int t;
//        cin >> t;
//        if (elems.count(t) > 0){
//            elems[t] += 1;
//        } else {
//            elems[t] = 1;
//        }
//    }
//    return elems;
//}

int main() {
    int n, m;
    cin >> n >> m;
    int ar[10] = {0};
    for(int i = 0; i < n; i++) {
        int t;
        cin >> t;
        ar[t - 1] += 1;
    }
    long long sum = 0;
    for (int i = 0; i < 10; i++) {
        for (int j = i + 1; j < 10; j++) {
            sum += ar[i] * ar[j];
        }
    }
    cout << sum;
    //auto books = read_map(n);

}


#include <bits/stdc++.h>

using namespace std;

int main(){

    long long n;
    int m,x;
    scanf("%lld%d",&n,&m);
    int a[m+1];
    fill(a,a+m+1,0);
    for(int i=0;i<n;i++){
        scanf("%d",&x);
        a[x]++;
    }
    long long res=(n*(n-1))/2;
    for(int i=1;i<=m;i++){
        if(a[i]>1)res-=(a[i]*(a[i]-1))/2;
    }
    cout<<res;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){

    int n,m,x;
    scanf("%d%d",&n,&m);
    int a[m+1];
    fill(a,a+m+1,0);
    for(int i=0;i<n;i++){
        scanf("%d",&x);
        a[x]++;
    }
    long long res=(n*(n-1))/2;
    for(int i=1;i<=m;i++){
        if(a[i]>1)res-=(a[i]*(a[i]-1))/2;
    }
    cout<<res;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){

    long long n;
    long long m,x;
    scanf("%lld%lld",&n,&m);
    long long a[m+1];
    fill(a,a+m+1,0);
    for(int i=0;i<n;i++){
        scanf("%lld",&x);
        a[x]++;
    }
    long long res=(n*(n-1))/2;
    for(int i=1;i<=m;i++){
        if(a[i]>1)res-=(a[i]*(a[i]-1))/2;
    }
    cout<<res;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define mod 1000000007

const int sz=1e5+5;
ll inf=1e15;

ll ar[sz],dp[102][100002],n,m;

bool cmp(ll x,ll y)
{
    return x>y;
}

ll f(int i,ll sum)
{
    if(sum>m)
        return inf;
    if(i==n)
    {
        if(sum==m)
            return 0;
        return inf;
    }
    ll &res=dp[i][sum];
    if(res!=-1)
        return res;
    res=f(i+1,sum);
    res=min(res,f(i,sum+ar[i])+1);

    return res;
}
ll cnt[11];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        cin>>n>>m;

        for(int i=0;i<n;i++)
        {
            cin>>ar[i];
            cnt[ar[i]]++;
        }
        ll sum=0;
        for(int i=1;i<=10;i++)
        {
            for(int j=i+1;j<=10;j++)
            {
                sum+=(cnt[i]*cnt[j]);
            }
        }

        cout<<sum<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define mod 1000000007

const int sz=2e5+5;
ll inf=1e15;

ll ar[sz],dp[102][100002],n,m;

bool cmp(ll x,ll y)
{
    return x>y;
}

ll f(int i,ll sum)
{
    if(sum>m)
        return inf;
    if(i==n)
    {
        if(sum==m)
            return 0;
        return inf;
    }
    ll &res=dp[i][sum];
    if(res!=-1)
        return res;
    res=f(i+1,sum);
    res=min(res,f(i,sum+ar[i])+1);

    return res;
}
ll cnt[11];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        cin>>n>>m;

        for(int i=0;i<n;i++)
        {
            cin>>ar[i];
            cnt[ar[i]]++;
        }
        ll sum=0;
        for(int i=1;i<=10;i++)
        {
            for(int j=i+1;j<=10;j++)
            {
                sum+=(cnt[i]*cnt[j]);
            }
        }

        cout<<sum<<endl;
    }

    return 0;
}


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

int main()
{
    int n,m;
    cin>>n>>m;
    int a[n];
    int arr[m]= {0};
    for(int i1=0;i1<n;i1++)
        cin>>a[i1];
    for(int num=2;num<=m;num++)
    {
        for(int i=0;i<n;i++)
        {
            if(a[i]==num)
            {
                arr[num-1]++;
            }
        }
    }
    l1 ans1=0;
    for(int j=1;j<m;j++)
    {
        ans1+=arr[j]*(arr[j]-1)/2;
    }
    l1 ans=0;
    ans+=n*(n-1)/2;
    ans-=ans1;
    cout<<ans<<endl;
	return 0;
}


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

int main()
{
    int n,m;
    cin>>n>>m;
    int a[n];
    int arr[m]= {0};
    for(int i1=0;i1<n;i1++)
        cin>>a[i1];
    for(int num=1;num<=m;num++)
    {
        for(int i=0;i<n;i++)
        {
            if(a[i]==num)
            {
                arr[num-1]++;
            }
        }
    }
    l1 ans1=0;
    for(int j=0;j<m;j++)
    {
        if(arr[j]>1)
            ans1+=arr[j]*(arr[j]-1)/2;
    }
    l1 ans=0;
    ans+=n*(n-1)/2 - ans1;
    cout<<ans<<endl;
	return 0;
}


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

int main()
{
    int n,m;
    cin>>n>>m;
    int a[n];
    int arr[m]= {0};
    for(int i1=0;i1<n;i1++)
    {
        cin>>a[i1];
        arr[a[i1]-1]++;
    }

    l1 ans1=0;
    for(int j=0;j<m;j++)
    {
        if(arr[j]>1)
            ans1+=arr[j]*(arr[j]-1)/2;
    }
    l1 ans=0;
    ans=n*(n-1)/2 - ans1;
    if(n==50000 && m==10)
    {
        cout<<n*(n-1)/2 <<endl;
        cout<<"ans1:"<<ans1<<endl;
    }

    cout<<ans<<endl;
	return 0;
}


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

int main()
{
    int n,m;
    cin>>n>>m;
    int a[n];
    int arr[m]= {0};
    for(int i1=0;i1<n;i1++)
        cin>>a[i1];
    for(int num=1;num<=m;num++)
    {
        for(int i=0;i<n;i++)
        {
            if(a[i]==num)
            {
                arr[num-1]++;
            }
        }
    }
    l1 ans1=0;
    for(int j=0;j<m;j++)
    {
        ans1+=arr[j]*(arr[j]-1)/2;
    }
    l1 ans=0;
    ans+=n*(n-1)/2;
    ans-=ans1;
    cout<<ans<<endl;
	return 0;
}


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

int main()
{
    l1 n,m;
    cin>>n>>m;
    l1 a[n];
    l1 arr[m]= {0};
    for(l1 i1=0;i1<n;i1++)
    {
        cin>>a[i1];
        arr[a[i1]-1]++;
    }

    l1 ans1=0;
    for(l1 j=0;j<m;j++)
    {
        if(arr[j]>1)
            ans1+=arr[j]*(arr[j]-1)/2;
    }
    l1 x=n*(n-1)/2;
    l1 ans= x- ans1;
    if(n==50000 && m==10)
    {
        cout<<"x:"<<x<<endl;
        cout<<"ans1:"<<ans1<<endl;
    }
    cout<<ans<<endl;
	return 0;
}


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

int main()
{
    l1 n,m;
    cin>>n>>m;
    l1 a[n];
    l1 arr[m]= {0};
    for(l1 i1=0;i1<n;i1++)
    {
        cin>>a[i1];
        arr[a[i1]-1]++;
    }

    l1 ans1=0;
    for(l1 j=0;j<m;j++)
    {
        if(arr[j]>1)
            ans1+=arr[j]*(arr[j]-1)/2;
    }
    l1 x=n*(n-1)/2;
    l1 ans= x- ans1;
    /*if(n==50000 && m==10)
    {
        cout<<"x:"<<x<<endl;
        cout<<"ans1:"<<ans1<<endl;
    }*/
    cout<<ans<<endl;
	return 0;
}


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

int main()
{
    int n,m;
    cin>>n>>m;
    int a[n];
    int arr[m]= {0};
    for(int i1=0;i1<n;i1++)
    {
        cin>>a[i1];
        arr[a[i1]-1]++;
    }

    l1 ans1=0;
    for(int j=0;j<m;j++)
    {
        if(arr[j]>1)
            ans1+=arr[j]*(arr[j]-1)/2;
    }
    l1 ans=0;
    ans=n*(n-1)/2 - ans1;
    if(n==50000 && m==10)
    {
        cout<<n*(n-1)/2 <<endl;
        cout<<"ans1:"<<ans1<<endl;
    }

    cout<<ans<<endl;
	return 0;
}


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

int main()
{
    int n,m;
    cin>>n>>m;
    int a[n];
    int arr[m]= {0};
    for(int i1=0;i1<n;i1++)
        cin>>a[i1];
    for(int num=1;num<=m;num++)
    {
        for(int i=0;i<n;i++)
        {
            if(a[i]==num)
            {
                arr[num-1]++;
            }
        }
    }
    l1 ans1=0;
    for(int j=0;j<m;j++)
    {
        if(arr[j]>1)
            ans1+=arr[j]*(arr[j]-1)/2;
    }
    l1 ans=0;
    ans+=n*(n-1)/2;
    ans-=ans1;
    cout<<ans<<endl;
	return 0;
}


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

int main()
{
    int n,m;
    cin>>n>>m;
    int a[n];
    int arr[m]= {0};
    for(int i1=0;i1<n;i1++)
    {
        cin>>a[i1];
        arr[a[i1]-1]++;
    }

    l1 ans1=0;
    for(int j=0;j<m;j++)
    {
        if(arr[j]>1)
            ans1+=arr[j]*(arr[j]-1)/2;
    }
    l1 ans=0;
    ans+=n*(n-1)/2 - ans1;
    if(n==50000 && m==10)
        cout<<"ans1:"<<ans1<<endl;
    cout<<ans<<endl;
	return 0;
}


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

int main()
{
    int n,m;
    cin>>n>>m;
    int a[n];
    int arr[m]= {0};
    for(int i1=0;i1<n;i1++)
        cin>>a[i1];
    for(int num=1;num<=m;num++)
    {
        for(int i=0;i<n;i++)
        {
            if(a[i]==num)
            {
                arr[num-1]++;
            }
        }
    }
    l1 ans1=0;
    for(int j=0;j<m;j++)
    {
        ans1+=arr[j]*(arr[j]-1)/2;
    }
    l1 ans=0;
    ans+=n*(n-1)/2;
    ans-=ans1;
    cout<<ans<<endl;
	return 0;
}


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

int main()
{
    int n,m;
    cin>>n>>m;
    int a[n];
    int arr[m]= {0};
    for(int i1=0;i1<n;i1++)
    {
        cin>>a[i1];
        arr[a[i1]-1]++;
    }

    l1 ans1=0;
    for(int j=0;j<m;j++)
    {
        if(arr[j]>1)
            ans1+=arr[j]*(arr[j]-1)/2;
    }
    l1 ans=0;
    ans+=n*(n-1)/2 - ans1;
    if(n==5000 && m==10)
        cout<<"ans1:"<<ans1<<endl;
    cout<<ans<<endl;
	return 0;
}


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

int main()
{
    int n,m;
    cin>>n>>m;
    int a[n];
    int arr[m]= {0};
    for(int i1=0;i1<n;i1++)
    {
        cin>>a[i1];
        arr[a[i1]-1]++;
    }

    l1 ans1=0;
    for(int j=0;j<m;j++)
    {
        if(arr[j]>1)
            ans1+=arr[j]*(arr[j]-1)/2;
    }
    l1 ans=n*(n-1)/2;
    ans= ans- ans1;
    /*if(n==50000 && m==10)
    {
        cout<<"ans1:"<<ans1<<endl;
    }*/
    cout<<ans<<endl;
	return 0;
}


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

long long n,m,res,decr,k,a[100010],sum,x;

int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	res=n*(n-1)/2;
	k=2;
	while(k<=n){
		if(k==n){
			if(a[k]==a[k-1]){
				sum+=2;
				x=(sum/2)*(sum-1);
				decr=decr+x;
			}
			else{
				sum++;
				x=(sum/2)*(sum-1);
				decr=decr+x;
			}
		}
		else if(a[k]==a[k-1]){
			sum++;
		}
		else{
			sum++;
			x=(sum/2)*(sum-1);
			decr=decr+x;
			sum=0;
		}
		k++;
	}
	res=res-decr;
	cout<<res<<endl;
	return 0;
}


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

long long n,m,res,decr,k,a[100010],sum,x;

int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	res=n*(n-1)/2;
	k=2;
	while(k<=n){
		if(k==n){
			if(a[k]==a[k-1]){
				sum+=2;
				if(sum%2==0){
					x=(sum/2)*(sum-1);
				}
				else{
					x=(sum)*((sum-1)/2);
				}
				decr=decr+x;
			}
			else{
				sum++;
				if(sum%2==0){
					x=(sum/2)*(sum-1);
				}
				else{
					x=(sum)*((sum-1)/2);
				}
				decr=decr+x;
			}
		}
		else if(a[k]==a[k-1]){
			sum++;
		}
		else{
			sum++;
			if(sum%2==0){
					x=(sum/2)*(sum-1);
				}
				else{
					x=(sum)*((sum-1)/2);
				}
			decr=decr+x;
			sum=0;
		}
		k++;
	}
	res=res-decr;
	cout<<res<<endl;
	return 0;
}


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

long long n,m,res,decr,k,a[100010],sum;

int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	res=n*(n-1)/2;
	k=2;
	while(k<=n){
		if(k==n){
			if(a[k]==a[k-1]){
				sum+=2;
				decr=decr+(sum/2)*(sum-1);
			}
			else{
				sum++;
				decr=decr+(sum/2)*(sum-1);
			}
		}
		else if(a[k]==a[k-1]){
			sum++;
		}
		else{
			sum++;
			decr=decr+(sum/2)*(sum-1);
			sum=0;
		}
		k++;
	}
	res=res-decr;
	cout<<res<<endl;
	return 0;
}


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

long long n,m,res,decr,k,a[100010],sum;

int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	res=n*(n-1)/2;
	k=2;
	while(k<=n){
		if(k==n){
			if(a[k]==a[k-1]){
				sum+=2;
				decr=decr+sum*(sum-1)/2;
			}
			else{
				sum++;
				decr=decr+sum*(sum-1)/2;
			}
		}
		else if(a[k]==a[k-1]){
			sum++;
		}
		else{
			sum++;
			decr=decr+sum*(sum-1)/2;
			sum=0;
		}
		k++;
	}
	res=res-decr;
	cout<<res<<endl;
	return 0;
}


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

long long n,m,res,decr,k,a[200010],sum,x;

int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	res=n*(n-1)/2;
	k=2;
	while(k<=n){
		if(k==n){
			if(a[k]==a[k-1]){
				sum+=2;
				if(sum%2==0){
					x=(sum/2)*(sum-1);
				}
				else{
					x=(sum)*((sum-1)/2);
				}
				decr=decr+x;
			}
			else{
				sum++;
				if(sum%2==0){
					x=(sum/2)*(sum-1);
				}
				else{
					x=(sum)*((sum-1)/2);
				}
				decr=decr+x;
			}
		}
		else if(a[k]==a[k-1]){
			sum++;
		}
		else{
			sum++;
			if(sum%2==0){
					x=(sum/2)*(sum-1);
				}
				else{
					x=(sum)*((sum-1)/2);
				}
			decr=decr+x;
			sum=0;
		}
		k++;
	}
	res=res-decr;
	cout<<res<<endl;
	return 0;
}


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

int n,m,res,decr,k,a[100010],sum;

int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	res=n*(n-1)/2;
	k=2;
	while(k<=n){
		if(k==n){
			if(a[k]==a[k-1]){
				sum+=2;
				decr=decr+sum*(sum-1)/2;
			}
			else{
				sum++;
				decr=decr+sum*(sum-1)/2;
			}
		}
		else if(a[k]==a[k-1]){
			sum++;
		}
		else{
			sum++;
			decr=decr+sum*(sum-1)/2;
			sum=0;
		}
		k++;
	}
	res=res-decr;
	cout<<res<<endl;
	return 0;
}


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

int n,m,res,decr,k,a[100010],sum;

int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	res=n*(n-1)/2;
	k=2;
	while(k<=n){
		if(k==n){
			if(a[k]==a[k-1]){
				sum+=2;
				decr=decr+sum*(sum-1)/2;
			}
		}
		else if(a[k]==a[k-1]){
			sum++;
		}
		else{
			sum++;
			decr=decr+sum*(sum-1)/2;
			sum=0;
		}
		k++;
	}
	res=res-decr;
	cout<<res<<endl;
	return 0;
}


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

#define double long double
#define int long long
#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first,l.second+r.second};
}
typedef void (*callback_function)(void); // type for conciseness
const long long INF64 = 1e18;
const int INF32 = 1e9;

int cnt[12], acc[12];

#undef int
int main() {
#define int long long
	ios_base::sync_with_stdio(false);
	cin.tie();
  //auto beginProgram = chrono::steady_clock::now();

  {// Code goes here
    int n, m;
    cin >> n >> m;
    int a[n];
    FOR(i, 0, n) {
      cin >> a[i];
      cnt[a[i]]++;
    }
    acc[1] = cnt[1];
    FORE(i, 2, 10) {
      acc[i] = cnt[i] + acc[i - 1];
    }
    int ans = 0;
    FORD(i, 10, 2) {
      ans += cnt[i] * acc[i - 1];
    }
    cout << ans << endl;
  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}


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

#define double long double
#define int long long
#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first,l.second+r.second};
}
typedef void (*callback_function)(void); // type for conciseness
const long long INF64 = 1e18;
const int INF32 = 1e9;

int cnt[12], acc[12];

#undef int
int main() {
#define int long long
	ios_base::sync_with_stdio(false);
	cin.tie();
  //auto beginProgram = chrono::steady_clock::now();

  {// Code goes here
    int n, m;
    cin >> n >> m;
    int a[n];
    FOR(i, 0, n) {
      cin >> a[i];
      cnt[a[i]]++;
    }
    acc[1] = cnt[1];
    FORE(i, 2, 10) {
      acc[i] = cnt[i] + acc[i - 1];
    }
    int ans = 0;
    FORD(i, 10, 2) {
      ans = cnt[i] * acc[i - 1];
    }
    cout << ans << endl;
  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}


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

#define double long double
#define int long long
#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first,l.second+r.second};
}
typedef void (*callback_function)(void); // type for conciseness
const long long INF64 = 1e18;
const int INF32 = 1e9;

int cnt[12], acc[12];

#undef int
int main() {
#define int long long
	ios_base::sync_with_stdio(false);
	cin.tie();
  //auto beginProgram = chrono::steady_clock::now();

  {// Code goes here
    int n, m;
    cin >> n >> m;
    int a[n];
    FOR(i, 0, n) {
      cin >> a[i];
      cnt[a[i]]++;
    }
    acc[1] = cnt[1];
    FORE(i, 2, 10) {
      acc[i] = cnt[i] + acc[i - 1];
    }
    int ans = 0;
    FORD(i, n, 2) {
      ans = cnt[i] * acc[i - 1];
    }
    cout << ans << endl;
  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}


/*
* @Author: dnhirapara
*/
#include <bits/stdc++.h>

using namespace std;

/************defination************/

#define endl "\n"
#define log(x) cout << __LINE__ << ": " << #x << " -> " << (x) << endl;
#define ll long long int
#define ull unsigned long long int

int nC2(int n)
{
    if (n < 2)
        return 0;
    return (n * (n - 1)) / 2;
}

//@time comp :
//@space comp :
int main()
{
    // ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    // cin.ignore(); must be there when using getline(cin, s)
    ll tc = 1;
    // cin>>tc;
    while (tc--)
    {
        int n, m;
        cin >> n >> m;
        int a[m] = {0};
        int no;
        long long ans = nC2(n);
        for (int i = 0; i < n; i++)
        {
            cin >> no;
            a[no - 1]++;
        }
        // cout << ans << endl;
        for (int i = 0; i < m; i++)
        {
            ans -= nC2(a[i]);
        }
        cout << ans << endl;
    }
    return 0;
}


/*
* @Author: dnhirapara
*/
#include <bits/stdc++.h>

using namespace std;

/************defination************/

#define endl "\n"
#define log(x) cout << __LINE__ << ": " << #x << " -> " << (x) << endl;
#define ll long long int
#define ull unsigned long long int

int nC2(int n)
{
    if (n < 2)
        return 0;
    return (n * (n - 1)) / 2;
}

//@time comp :
//@space comp :
int main()
{
    // ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    // cin.ignore(); must be there when using getline(cin, s)
    ll tc = 1;
    // cin>>tc;
    while (tc--)
    {
        int n, m;
        cin >> n >> m;
        long long a[m] = {0};
        int no;
        long long ans = (ll)nC2(n);
        for (int i = 0; i < n; i++)
        {
            cin >> no;
            a[no - 1]++;
        }
        // cout << ans << endl;
        for (int i = 0; i < m; i++)
        {
            ans -= (ll)nC2(a[i]);
        }
        cout << ans << endl;
    }
    return 0;
}


/*
* @Author: dnhirapara
*/
#include <bits/stdc++.h>

using namespace std;

/************defination************/

#define endl "\n"
#define log(x) cout << __LINE__ << ": " << #x << " -> " << (x) << endl;
#define ll long long int
#define ull unsigned long long int

int nC2(int n)
{
    return (n * (n - 1)) / 2;
}

//@time comp :
//@space comp :
int main()
{
    // ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    // cin.ignore(); must be there when using getline(cin, s)
    ll tc = 1;
    // cin>>tc;
    while (tc--)
    {
        int n, m;
        cin >> n >> m;
        long long a[m] = {0};
        int no;
        long long ans = (ll)nC2(n);
        for (int i = 0; i < n; i++)
        {
            cin >> no;
            a[no - 1]++;
        }
        // cout << ans << endl;
        for (int i = 0; i < m; i++)
        {
            ans -= (ll)nC2(a[i]);
        }
        cout << ans << endl;
    }
    return 0;
}


/*
* @Author: dnhirapara
*/
#include <bits/stdc++.h>

using namespace std;

/************defination************/

#define endl "\n"
#define log(x) cout << __LINE__ << ": " << #x << " -> " << (x) << endl;
#define ll long long int
#define ull unsigned long long int

long long int nC2(long long int n)
{
    return (n * (n - 1)) / 2;
}

//@time comp :
//@space comp :
int main()
{
    // ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    // cin.ignore(); must be there when using getline(cin, s)
    ll tc = 1;
    // cin>>tc;
    while (tc--)
    {
        int n, m;
        cin >> n >> m;
        long long a[m] = {0};
        int no;
        long long int ans = (ll)nC2(n);
        for (int i = 0; i < n; i++)
        {
            cin >> no;
            a[no - 1]++;
        }
        // cout << ans << endl;
        for (int i = 0; i < m; i++)
        {
            ans -= (ll)nC2(a[i]);
        }
        cout << ans << endl;
    }
    return 0;
}


/*
* @Author: dnhirapara
*/
#include <bits/stdc++.h>

using namespace std;

/************defination************/

#define endl "\n"
#define log(x) cout << __LINE__ << ": " << #x << " -> " << (x) << endl;
#define ll long long int
#define ull unsigned long long int

int nC2(long long int n)
{
    return (n * (n - 1)) / 2;
}

//@time comp :
//@space comp :
int main()
{
    // ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    // cin.ignore(); must be there when using getline(cin, s)
    ll tc = 1;
    // cin>>tc;
    while (tc--)
    {
        int n, m;
        cin >> n >> m;
        long long a[m] = {0};
        int no;
        long long int ans = (ll)nC2(n);
        for (int i = 0; i < n; i++)
        {
            cin >> no;
            a[no - 1]++;
        }
        // cout << ans << endl;
        for (int i = 0; i < m; i++)
        {
            ans -= (ll)nC2(a[i]);
        }
        cout << ans << endl;
    }
    return 0;
}


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

int main() {

     long long n,h,i,j=0,t,l=0,m;
     long long p=0,s,k,x=0,y,z;
     std::cin >> n >>m;
     int a[n];
     for(i=0;i<n;i++)
          cin>>a[i];
     p=0;
     for(i=0;i<n;i++)
     {
          for(j=i+1;j<n;j++)
          {
               if(a[i]!=a[j])
                    p++;
          }
     }
     std::cout << p << std::endl;
     return 0;
}


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

int main() {

     long long n,h,i,j=0,t,l=0,m;
     long long p=0,s,k,x=0,y,z;
     std::cin >> n >>m;
     int a[n];
     for(i=0;i<n;i++)
          cin>>a[i];
     p=0;int b[m];
     for(i=0;i<m;i++)
          b[i]=0;
     for(i=0;i<n;i++)
          b[a[i]-1]++;
     for(i=0;i<m-1;i++)
     {
          for(j=i+1;j<m;j++)
               p=p+b[i]*b[j];
     }
     std::cout << p << std::endl;
     return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N],b[N];

int main()
{
	int n,m;scanf("%d%d",&n,&m);
	memset(b,0,sizeof(b));
	for (int i=0;i<n;i++) {
	    scanf("%d",&a[i]);
	    b[a[i]]++;
	}
	int ans=0;
	for (int i=1;i<=m;i++)
	{
		for (int j=i+1;j<=m;j++)
		{
			ans=ans+b[i]*b[j];
		}
	}
	printf("%d\n",ans);
}


#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N];

int main()
{
	int n,m;scanf("%d%d",&n,&m);
	for (int i=0;i<n;i++) scanf("%d",&a[i]);
	int ans=0;
	for (int i=0;i<n;i++)
	{
		for (int j=i+1;j<n;j++)
		{
			if (a[i]!=a[j])
			{
				ans++;
			}
		}
	}
	printf("%d\n",ans);
}


#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N],b[N];

int main()
{
	int n,m;scanf("%d%d",&n,&m);
	memset(b,0,sizeof(b));
	for (int i=0;i<n;i++) {
	    scanf("%d",&a[i]);
	    b[a[i]]++;
	}
	int ans=(n*(n-1))/2,tmp=0;
	for (int i=1;i<=m;i++)
	{
		tmp+=(b[i]*(b[i]-1))/2;
	}
	printf("%d\n",ans-tmp);
}


#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N],b[N];

int main()
{
	int n,m;scanf("%d%d",&n,&m);
	memset(b,0,sizeof(b));
	for (int i=0;i<n;i++) {
	    scanf("%d",&a[i]);
	    b[a[i]]++;
	}
	int ans=n*(n-1)/2,tmp=0;
	for (int i=1;i<=m;i++)
	{
		tmp+=b[i]*(b[i]-1)/2;
	}
	printf("%d\n",ans-tmp);
}


#include<bits/stdc++.h>
#define ll long long int
#define bra string
#define fuck while
#define pi acos(-1)

using namespace std;

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

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

  ll t,i,j,k,m,n,sum=0,l=0,l1;
  vector<ll>v;
  cin>>n>>m;
  while(n--)
  {
    cin>>k;
    v.push_back(k);
  }
  l=v.size();
  for(i=1;i<l;i++)
  {
    sum+=i;
  }
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  l1=v.size();
  cout<<sum-(l-l1)<<endl;

}

  //rOkY
  //FuCk

  //######################### kOpAl ##########################


#include<bits/stdc++.h>
#define ll long long int
#define bra string
#define fuck while
#define pi acos(-1)

using namespace std;

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

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

  ll t,i,j,k,m,n,sum=0,l=0,l1;
  vector<ll>v;
  cin>>n>>m;
  while(n--)
  {
    cin>>k;
    v.push_back(k);
  }
  l=v.size();
  for(i=1;i<l;i++)
  {
    sum+=i;
  }
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  l1=v.size();
  cout<<sum-(l-l1)<<endl;

}

  //rOkY
  //FuCk

  //######################### kOpAl ##########################


#include<bits/stdc++.h>
#define ll long long int
#define bra string
#define fuck while
#define pi acos(-1)

using namespace std;

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

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

  ll t,i,j,k,m,n,sum=0,l=0,l1;
  vector<ll>v;
  cin>>n>>m;
  for(i=0;i<n;i++)
  {
    cin>>k;
    v.push_back(k);
  }
  l=v.size();
  for(i=1;i<l;i++)
  {
    sum+=i;
  }
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  l1=v.size();
  cout<<sum-(l-l1)<<endl;

}

  //rOkY
  //FuCk

  //######################### kOpAl ##########################


#include<bits/stdc++.h>
#define ll long long int
#define bra string
#define fuck while
#define pi acos(-1)

using namespace std;

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

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

  ll t,i,j,k,m,n,sum=0,l=0,l1=0;

  cin>>n>>m;
  vector<ll>v(m);
  for(i=0;i<n;i++)
  {
    cin>>k;
    v[k-1]++;
  }
  sum=n;
  for(i=0;i<m;i++)
  {
    if(!v[i])
    {
      continue;
    }
    l+= v[i]*(sum-v[i]);
    sum-=v[i];
  }

  cout<<l<<endl;
}

  //rOkY
  //FuCk

  //######################### kOpAl ##########################


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define lld long long int
#define ll long long
using namespace std;
#define rep(i,start,end) for(lld i = start;i<end;i++)
#define repr(i,start,end) for(lld i = start;i>=end;i--)
#define newline cout << endl
#define fastio ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define se second
#define fi first
const ll MOD=1e+9+7;
int main()
{
    lld n,m,a[200004],b[11]={0},sum[11]={0};
    cin >> n >> m;
    rep(i,0,n)
    {
        cin >> a[i];
        b[a[i]]++;
        sum[a[i]]++;
    }
    repr(i,m-1,2)
        sum[i] = sum[i] + sum[i+1];
    lld count = 0;
    rep(i,1,m)
        {
            count+=b[i]*sum[i+1];
        }
    cout << count << endl;

    return 1;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define lld long long int
#define ll long long
using namespace std;
#define rep(i,start,end) for(lld i = start;i<end;i++)
#define repr(i,start,end) for(lld i = start;i>=end;i--)
#define newline cout << endl
#define fastio ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define se second
#define fi first
const ll MOD=1e+9+7;
int main()
{
    fastio;
    lld n,m,a[200004],b[11]={0},sum[11]={0};
    cin >> n >> m;
    rep(i,0,n)
    {
        cin >> a[i];
        b[a[i]]++;
        sum[a[i]]++;
    }
    repr(i,m-1,2)
        sum[i] = sum[i] + sum[i+1];
    lld count = 0;
    rep(i,1,m)
        {
            count+=b[i]*sum[i+1];
        }
    cout << count << endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define lld long long int
#define ll long long
using namespace std;
#define rep(i,start,end) for(lld i = start;i<end;i++)
#define repr(i,start,end) for(lld i = start;i>=end;i--)
#define newline cout << endl
#define fastio ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define se second
#define fi first
const ll MOD=1e+9+7;
int main()
{
    lld n,m,a[200004],b[11]={0},sum[11]={0};
    cin >> n >> m;
    rep(i,0,n)
    {
        cin >> a[i];
        b[a[i]]++;
        sum[a[i]]++;
    }
    repr(i,m-1,2)
        sum[i] = sum[i] + sum[i+1];
    lld count = 0;
    rep(i,1,m)
        {
            count+=b[i]*sum[i+1];
        }
    cout << count << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n,m; cin>>n>>m;
	ll xp[m+1];
	for(int i = 1; i < m+1; i++) xp[i] = 0;
	ll arr[n]; for(int i = 0; i < n; i++) {cin>>arr[i]; xp[arr[i]]++;}
	ll co = 0;
	ll sum = 0;
	ll ans = 0;
	for(int i = 1; i < m+1; i++) sum += xp[i];
	for(int i = 1; i < m+1; i++){
		if(xp[i]){
			sum -= xp[i];
			ans += (xp[i]*sum);
		}
	}
	cout<<ans<<"\n";
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n,m; cin>>n>>m;
	ll arr[n]; for(int i = 0; i < n; i++) cin>>arr[i];
	ll co = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(i == j || arr[i] == arr[j]) continue;
			co++;
		}
	}
	cout<<co/2<<"\n";

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n,m; cin>>n>>m;
	ll xp[m+1];
	for(int i = 1; i < m+1; i++) xp[i] = 0;
	ll arr[n]; for(int i = 0; i < n; i++) {cin>>arr[i]; xp[arr[i]]++;}
	ll sum = 0;
	ll ans = 0;
	for(int i = 1; i < m+1; i++) sum += xp[i];
	for(int i = 1; i < m+1; i++){
		if(xp[i]){
			sum -= xp[i];
			ans += (xp[i]*sum);
		}
	}
	cout<<ans<<"\n";
}


#include<iostream>
#include<iomanip>
#include<ctype.h>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    long long int n,m,i,j,count=0,ans;
    cin>>n>>m;
    long long int a[n+2];
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=0;i<n;i++)
        for(j=i+1;j<n;j++)
            if(a[i]==a[j])
                count++;
    ans=((n*(n-1))/2)-count;
    cout<<ans;
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<iomanip>
#include<ctype.h>
#include<cstring>
#include<vector>
#include<set>
#include<cmath>
#include<map>
#include<algorithm>
using namespace std;

int main()
{
	long long int n,a,ans,count=0,i,m,h[30]={0};
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        cin>>a;
        h[a]++;
    }
    for(i=0;i<=m;i++)
    {
        count+=h[i]*(h[i]-1)/2;
    }
    ans=n*(n-1)/2-count;
    cout<<ans;
    return 0;
}


#include<iostream>
#include<iomanip>
#include<ctype.h>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    long long int n,m,i,j,count=0;
    cin>>n>>m;
    long long int a[n+2];
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=0;i<n;i++)
        for(j=i+1;j<n;j++)
            if(a[i]!=a[j])
                count++;
    cout<<count;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
map<ll,ll>mp;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll m,n,a,good,bad=0,sum=0,gen;
    cin>>m>>n;
    a=m;
    while(m--){
        cin>>gen;
        mp[gen]++;
    }
    good=a*(a-1)/2;
   // cout<<good<<endl;
    map<ll,ll>::iterator it;
    for(it=mp.begin();it!=mp.end();it++){
        if(it->second>1){
            sum=it->second;
            bad+=(sum*(sum-1)/2);
        }
    }
   // cout<<bad<<endl;
    cout<<good-bad<<endl;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
map<ll,ll>mp;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll m,n,a,good,bad,sum=0,gen;
    cin>>m>>n;
    a=m;
    while(m--){
        cin>>gen;
        mp[gen]++;
    }
   //good=a*(a-1)/2;
    cout<<good<<endl;
    map<ll,ll>::iterator it;
    for(it=mp.begin();it!=mp.end();it++){
        if(it->second>1){
            sum++;
        }
    }
   // cout<<sum<<endl;
    bad=sum*(sum-1)/2;
    cout<<good-bad<<endl;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
map<ll,ll>mp;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll m,n,a,good,bad=0,gen;
    cin>>m>>n;
    a=m;
    while(m--){
        cin>>gen;
        mp[gen]++;
    }
   // good=a*(a-1)/2;
    cout<<good<<endl;
    map<ll,ll>::iterator it;
    for(it=mp.begin();it!=mp.end();it++){
        if(it->second>1){
            bad++;
        }
    }
   // cout<<bad<<endl;
    cout<<good-bad<<endl;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
map<ll,ll>mp;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll m,n,a,good,bad=0,gen;
    cin>>m>>n;
    a=m;
    while(m--){
        cin>>gen;
        mp[gen]++;
    }
    good=a*(a-1)/2;
    //cout<<good<<endl;
    map<ll,ll>::iterator it;
    for(it=mp.begin();it!=mp.end();it++){
        if(it->second>1){
            bad++;
        }
    }
   // cout<<bad<<endl;
    cout<<good-bad<<endl;
    return 0;

}


#include <bits/stdc++.h>

using namespace std;

map <int , int > sumb;

int main()
{
	int m,a[200005];
	long long n;
	cin>>n>>m;

	long long ans = n*(n-1)/2;

	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sumb[a[i]]++;
	}
	for(int i = 1 ; i <= m ; i++)
	{

		ans -= (long long)sumb[i]*(sumb[i]-1)/2;

	}

	cout<<ans;

}


#include <bits/stdc++.h>

using namespace std;

int sumb[10];

int main()
{
	int n,m,a[200005];

	cin>>n>>m;
	long long ans = n*(n-1)/2;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sumb[a[i]]++;
	}
	for(int i = 1 ; i <= m ; i++)
	{

		ans-=sumb[i]*(sumb[i]-1)/2;

	}

	cout<<ans;
}


#include <bits/stdc++.h>

using namespace std;

map <int , int > sumb;

int main()
{
	int n,m,a[200005];

	cin>>n>>m;
	long long ans = n*(n-1)/2;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sumb[a[i]]++;
	}
	for(int i = 1 ; i <= m ; i++)
	{

		ans -= sumb[i]*(sumb[i]-1)/2;

	}

	cout<<ans;

}


#include <bits/stdc++.h>

using namespace std;

int sumb[11];

int main()
{
	int n,m,a[200005];

	cin>>n>>m;
	long long ans = n*(n-1)/2;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sumb[a[i]]++;
	}
	for(int i = 1 ; i <= m ; i++)
	{

		ans-=sumb[i]*(sumb[i]-1)/2;

	}

	cout<<ans;
}


#include <bits/stdc++.h>

using namespace std;

int sumb[11];

int main()
{
	int n,m,a[200005];

	cin>>n>>m;
	long long ans = n*(n-1)/2;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sumb[a[i]]++;
	}
	for(int i = 2 ; i <= m ; i++)
	{

		ans-=sumb[i]*(sumb[i]-1)/2;

	}

	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
int main()
{
     ll n,m,a[100001],i,o,j,k,l,s;
     cin>>n;
     cin>>m;
     for(i=0;i<n;i++)
     cin>>a[i];
     ll mp[100]={0};
     s=0;
     for(i=n-1;i>=0;i--)
     {
         k=n-1-i;
         s+=k-(mp[a[i]]);
         mp[a[i]]++;
     }
     cout<<s<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
int main()
{
     ll n,m,a[300001],i,o,j,k,l,s;
     cin>>n;
     cin>>m;
     for(i=0;i<n;i++)
     cin>>a[i];
     ll mp[100]={0};
     s=0;
     for(i=n-1;i>=0;i--)
     {
         k=n-1-i;
         s+=k-(mp[a[i]]);
         mp[a[i]]++;
     }
     cout<<s<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
int main()
{
     ll n,m,a[100001],i,o,j,k,l,s;
     cin>>n;
     cin>>m;
     for(i=0;i<n;i++)
     cin>>a[i];
     map<ll,ll> mp;
     s=0;
     for(i=n-1;i>=0;i--)
     {
         k=n-1-i;
         s+=k-(mp[a[i]]);
         mp[a[i]]++;
     }
     cout<<s<<endl;
    return 0;
}


#include <iostream>
#include<map>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,m,i,x,s,ans;
    s=0;ans=0;
    map<ll,ll> M;
cin>>n>>m;
for(i=0;i<n;i++)
{
    cin>>x;
    M[x]++;
}

for(map<ll,ll> :: iterator i=M.begin();i!=M.end();i++)
{
    ll temp=(*i).second;
    ll q=(temp*(temp+1))/2;
    s=s+q;

}

 ans=(n*(n+1))/2;
ans=ans-s;
cout<<ans;
}


#include <bits/stdc++.h>

#define fo(i, n) for (i = 0; i < n; i++)
#define PI 3.1415926535897932384626

// using namespace std;
using std::array;
using std::cin;
using std::cout;
using std::endl;
using std::map;
using std::multimap;
using std::multiset;
using std::set;
using std::string;
using std::vector;

int32_t randint(int32_t l, int32_t u)
{
    return l + (rand() % u);
}

template <typename T>
void readarray(T *arr, size_t l)
{
    int32_t i;
    fo(i, l)
    {
        std::cin >> arr[i];
    }
}
template <typename T>
vector<T> readvector(size_t l)
{
    vector<T> vec;
    size_t i;
    T a;
    for (i = 0; i < l; i++)
    {
        cin >> a;
        vec.push_back(a);
    }
    return vec;
}
template <typename T>
void readmatrix(int32_t rows, int32_t columns, std::vector<std::vector<T>> &matrix)
{
    int32_t num;
    int32_t i, j;
    int32_t arr[columns];
    fo(i, rows)
    {
        matrix[i] = std::vector<int32_t>(columns);
        fo(j, columns)
        {
            cin >> num;
            matrix[i][j] = num;
        }
    }
}

template <typename T>
void printarray(T *arr, size_t l, std::string sep = " ")
{
    size_t i;
    fo(i, l)
    {
        if (i == l - 1)
        {
            std::cout << arr[i];
        }
        else
        {
            std::cout << arr[i] << sep;
        }
    }
    std::cout << std::endl;
}

template <typename T>
void printvector(std::vector<T> vec, std::string sep = " ")
{
    size_t i;
    for (i = 0; i < vec.size(); i++)
    {
        if (i == vec.size() - 1)
        {
            std::cout << vec[i];
        }
        else
        {
            std::cout << vec[i] << sep;
        }
    }
    std::cout << std::endl;
}

std::string solve()
{
    return "0";
}

int main()
{
    int32_t n_test_cases = 1;
    // cin >> n_test_cases;
    while (n_test_cases--)
    {
        int32_t i, j, k, a, b, c, l, m, n;
        cin >> n >> m;
        map<int32_t, int32_t> counts;
        vector<int32_t> books = readvector<int32_t>(n);
        for (auto num : books)
        {
            counts[num]++;
        }
        int32_t total = 0;
        for (auto pr : counts)
        {
            total += pr.second * (n - pr.second);
        }
        cout << total / 2 << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

#define fo(i, n) for (i = 0; i < n; i++)
#define PI 3.1415926535897932384626

// using namespace std;
using std::array;
using std::cin;
using std::cout;
using std::endl;
using std::map;
using std::multimap;
using std::multiset;
using std::set;
using std::string;
using std::vector;

int32_t randint(int32_t l, int32_t u)
{
    return l + (rand() % u);
}

template <typename T>
void readarray(T *arr, size_t l)
{
    int32_t i;
    fo(i, l)
    {
        std::cin >> arr[i];
    }
}
template <typename T>
vector<T> readvector(size_t l)
{
    vector<T> vec;
    size_t i;
    T a;
    for (i = 0; i < l; i++)
    {
        cin >> a;
        vec.push_back(a);
    }
    return vec;
}
template <typename T>
void readmatrix(int32_t rows, int32_t columns, std::vector<std::vector<T>> &matrix)
{
    int32_t num;
    int32_t i, j;
    int32_t arr[columns];
    fo(i, rows)
    {
        matrix[i] = std::vector<int32_t>(columns);
        fo(j, columns)
        {
            cin >> num;
            matrix[i][j] = num;
        }
    }
}

template <typename T>
void printarray(T *arr, size_t l, std::string sep = " ")
{
    size_t i;
    fo(i, l)
    {
        if (i == l - 1)
        {
            std::cout << arr[i];
        }
        else
        {
            std::cout << arr[i] << sep;
        }
    }
    std::cout << std::endl;
}

template <typename T>
void printvector(std::vector<T> vec, std::string sep = " ")
{
    size_t i;
    for (i = 0; i < vec.size(); i++)
    {
        if (i == vec.size() - 1)
        {
            std::cout << vec[i];
        }
        else
        {
            std::cout << vec[i] << sep;
        }
    }
    std::cout << std::endl;
}

std::string solve()
{
    return "0";
}

int main()
{
    int32_t n_test_cases = 1;
    // cin >> n_test_cases;
    while (n_test_cases--)
    {
        int32_t i, j, k, a, b, c, l, m, n;
        cin >> n >> m;
        map<int32_t, int32_t> counts;
        vector<int32_t> books = readvector<int32_t>(n);
        for (auto num : books)
        {
            counts[num]++;
        }
        int64_t total = 0;
        for (auto pr : counts)
        {
            total += pr.second * (n - pr.second);
        }
        cout << total / 2 << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
 int c[100000];

int main(){
  int n,m;
  cin>>n>>m;
 int a[n+1];
  for(int i=1;i<=n;i++){
    int a[i];
    cin>>a[i];
    c[a[i]]++;

  }
  int ans=0;
  for(int i=1;i<=m;i++){
    ans+=(n-c[i])*c[i];
  }
  cout<<ans/2;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
 int c[100000];
int factorial(int k){
  int a=1;
  for(int i=1;i<=k;i++)
  a*=i;
  return a;
}
int comb(int n,int m){
  int a=factorial(n)/(factorial(m)*factorial(n-m));
  return a;
}
int main(){
  int n,m;
  cin>>n>>m;

  for(int i=1;i<=n;i++){
    int a;
    cin>>a;
    c[a]++;

  }
  int ans=comb(n,2);
  for(int i=1;i<=m;i++)
  ans-=comb(c[i],2);
  cout<<ans;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
 int c[11];

int main(){
  int n,m;
  cin>>n>>m;

  for(int i=1;i<=n;i++){
    int a;
    cin>>a;
    c[a]++;

  }
  int ans=0;
  for(int i=1;i<=m;i++){
    ans+=(n-c[i])*c[i];
  }
  cout<<ans/2;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
 int c[11];

int main(){
  int n,m;
  cin>>n>>m;
 int a[n+1];
  for(int i=1;i<=n;i++){

    cin>>a[i];
    c[a[i]]++;

  }
  int ans=0;
  for(int i=1;i<=m;i++){
    ans+=(n-c[i])*c[i];
  }
  cout<<ans/2;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
 long long c[11];

int main(){
  int n,m;
  cin>>n>>m;

  for(int i=1;i<=n;i++){
    int a;
    cin>>a;
    c[a]++;

  }
 long long ans=0;
  for(int i=1;i<=m;i++){
    ans+=(n-c[i])*c[i];
  }
  cout<<ans/2;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
 int c[100000];
int factorial(int k){
  int a=1;
  for(int i=1;i<=k;i++)
  a*=i;
  return a;
}
int comb(int n,int m){
  int a=factorial(n)/(factorial(m)*factorial(n-m));
  return a;
}
int main(){
  int n,m;
  cin>>n>>m;

  for(int i=1;i<=n;i++){
    int a;
    cin>>a;
    c[a]++;

  }
  unsigned long long ans=comb(n,2);
  for(int i=1;i<=m;i++)
  ans-=comb(c[i],2);
  cout<<ans;

  return 0;
}


/**
 *    Mosiur Rahman
 *    CSE, AUST
**/

//The fool didn’t know it was impossible, so he did it

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

int func(int y)
{
    return y*(y-1)/2;
}

int main()
{
    int n, m;
    cin >> n >> m;

    int arr[m+1];
    memset(arr, 0, sizeof(arr));

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

        arr[x]++;
    }

    int sum=0, ans=0;

    for(int i=1; i<=m; i++)
    {
        sum += func(arr[i]);
    }

    ans += func(n) - sum;

    cout << ans << endl;
}


/**
 *    Mosiur Rahman
 *    CSE, AUST
**/

//The fool didn’t know it was impossible, so he did it

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

ll func(ll y)
{
    return y*(y-1)/2;
}

int main()
{
    int n, m;
    cin >> n >> m;

    int arr[m+1];
    memset(arr, 0, sizeof(arr));

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

        arr[x]++;
    }

    ll sum=0, ans=0;

    for(int i=1; i<=m; i++)
    {
        sum += func(arr[i]);
    }

    ans += func(n) - sum;

    cout << ans << endl;
}


#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#define _CRT_DISABLE_PERFCRIT_LOCKS
#define FOR(i,s,e) for (int i=(s); (int)i<(e); i++)
#define TIMES(n) FOR(i, 0, (n))
#define eps 1e-11
#define MP make_pair
#define PB push_back
#define ERASE(vec, i) (vec).erase((vec).begin() + (i))

using namespace std;

typedef pair <int, int> ii;

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    int small = 100000;
    int big = 0;
    TIMES(n) {
        int t; cin >> t;
        if (t < small)
            small = t;
        if (t > big)
            big = t;
    }
    int bsmall=100000;
    TIMES(m) {
        int t; cin >> t;
        bsmall = min(t, bsmall);
    }
    int v = 1;
    while (true) {
        if (v >= big && v >= small*2 && v < bsmall) {
            cout << v; break;
        }
        else if (v > bsmall) {
            cout << -1; break;
        }
        v++;
    }

    return 0;
}


#include <cstdio>
#include <algorithm>
int main()
{
    int n,m,i =0,c[100],w[100];
    scanf("%d %d",&n,&m);
    for(i=0;i<n;i++)
    {
        scanf("%d",&c[i]);
    }
    for(i=0;i<m;i++)
    {
        scanf("%d",&w[i]);
    }
    int minC = *std::min_element(c,c+n);
    int maxC = *std::max_element(c,c+n);
    int minW = *std::min_element(w,w+m);
    int lowLimit = std::max(2*minC,maxC);
    if(lowLimit>=minW)
    {
        printf("-1\n");
    }
    else
    {
        printf("%d\n",lowLimit);
    }
    return 0;
}


#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <bitset>
#include <algorithm>
#include <cstring>

using namespace std;

#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i, a, b) for(int i = (a) - 1; i >= 0; --i)
#define trav(it, v) for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define all(v) (v).begin(), (v).end()

typedef double fl;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

template<typename T>
istream& operator>>(istream& in, vector<T> &v) {
    rep(i,0,v.size()) in >> v[i];
    return in;
}

template<typename A, typename B>
istream& operator>>(istream& in, pair<A, B> &p) {
    in >> p.first >> p.second;
    return in;
}

template<typename T>
ostream& operator<<(ostream& out, vector<T> &v) {
    out << v[0];
    rep(i,1,v.size()) out << ' ' << v[i];
    return out;
}

template<typename A, typename B>
ostream& operator<<(ostream& out, pair<A, B> &p){
    out << p.first << ' ' << p.second;
    return out;
}

int main(){
    int n, m;
    cin >> n >> m;
    vi a(n), b(m);
    cin >> a >> b;
    int tl = max( *max_element(all(a)), 2* *min_element(all(a)));
    if(tl >= *min_element(all(b))) cout << -1 << endl;
    else cout << tl << endl;
}


#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <bitset>
#include <algorithm>
#include <cstring>

using namespace std;

#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i, a, b) for(int i = (a) - 1; i >= 0; --i)
#define trav(it, v) for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define all(v) (v).begin(), (v).end()

typedef double fl;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

template<typename T>
istream& operator>>(istream& in, vector<T> &v) {
    rep(i,0,v.size()) in >> v[i];
    return in;
}

template<typename A, typename B>
istream& operator>>(istream& in, pair<A, B> &p) {
    in >> p.first >> p.second;
    return in;
}

template<typename T>
ostream& operator<<(ostream& out, vector<T> &v) {
    out << v[0];
    rep(i,1,v.size()) out << ' ' << v[i];
    return out;
}

template<typename A, typename B>
ostream& operator<<(ostream& out, pair<A, B> &p){
    out << p.first << ' ' << p.second;
    return out;
}

int main(){
    int n, k;
    cin >> n >> k;
    vi a(n);
    cin >> a;
    sort(all(a));
    a.push_back(a.back() + 1);
    if(k > n) cout << -1 << endl;
    else cout << a[a.size() - k - 1] <<  " 0" << endl;
}


#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <bitset>
#include <algorithm>
#include <cstring>

using namespace std;

#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i, a, b) for(int i = (a) - 1; i >= 0; --i)
#define trav(it, v) for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define all(v) (v).begin(), (v).end()

typedef double fl;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

template<typename T>
istream& operator>>(istream& in, vector<T> &v) {
    rep(i,0,v.size()) in >> v[i];
    return in;
}

template<typename A, typename B>
istream& operator>>(istream& in, pair<A, B> &p) {
    in >> p.first >> p.second;
    return in;
}

template<typename T>
ostream& operator<<(ostream& out, vector<T> &v) {
    out << v[0];
    rep(i,1,v.size()) out << ' ' << v[i];
    return out;
}

template<typename A, typename B>
ostream& operator<<(ostream& out, pair<A, B> &p){
    out << p.first << ' ' << p.second;
    return out;
}

int main(){
    int n, m;
    cin >> n >> m;
    vi a(n), b(m);
    cin >> a >> b;
    if(*max_element(all(a)) >= *min_element(all(b)) || *min_element(all(a))*2 >= *max_element(all(a))) cout << -1 << endl;
    else cout << *max_element(all(a)) << endl;
}


#include <iostream>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <sstream>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <string.h>
using namespace std;
#define PI 3.141592653
#define all(x) x.begin(),x.end()
#define set(a,b) memset(a,b,sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pii pair<int,int>
typedef long long ll;
typedef unsigned long long ull;
int gcd(int a, int b) {
    while (a %= b ^= a ^= b ^= a);
    return b;
}
int lcm(int a, int b) {
    return (a*b) / gcd(a, b);
}
ll power(ll a, ll b) {
    if (b == 0) {
        return 1;
    }
    if (b == 1) {
        return a;
    }
    if (b % 2 == 0) {
        return power(a*a, b / 2);
    }
    else {
        return (a * power(a*a, (b - 1) / 2));
    }
}
ull choose(ull n, ull k) {
    if (k > n) {
        return 0;
    }
    ull r = 1;
    for (ull d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}
int intlog(double base, double x) {
    return (int)(log(x) / log(base));
}
class matrix {
public:
    ll mat[4][4];
    matrix() {
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                mat[i][j] = (i == j ? 0 : 1);
            }
        }
    }
};
matrix mult(matrix a, matrix b) {
    matrix res;
    memset(res.mat, 0, sizeof res.mat);
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                res.mat[i][j] = (res.mat[i][j] + a.mat[i][k] * b.mat[k][j]) % 1000000007;
            }
        }
    }
    return res;
}
matrix power(matrix a, ll b) {
    if (b == 1) {
        return a;
    }
    if (b % 2 == 0) {
        return power(mult(a, a), b / 2);
    }
    else {
        return mult(a, power(a, (b - 1)));
    }
}
double dist(int x1, int y1, int x2, int y2) {
    return sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
}
int main() {
    int n, m;
    while (cin >> n >> m) {
        int correct[101];
        int incorrect[101];
        for (int i = 0; i < n; cin >> correct[i++]);
        for (int i = 0; i < m; cin >> incorrect[i++]);
        sort(incorrect, incorrect + m);
        sort(correct, correct + n);
        int res = -1;
        for (int i = 1; i < incorrect[0]; i++) {
            bool ok = true;
            bool a = false;
            for (int j = 0; j < n; j++) {
                if (correct[j]>i) {
                    ok = false;
                    break;
                }
                if (2 * correct[j] <= i) {
                    a = true;
                }
            }
            if (ok && a) {
                res = i;
                break;
            }
        }
        cout << res << endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    int minCorrectTime  =1000, maxCorrectTime = 0, minWrongTime = 1000,tmp;
    for(int i = 0 ; i < n; i ++){
        cin >> tmp;
        minCorrectTime = min(tmp,minCorrectTime);
        maxCorrectTime = max(tmp,maxCorrectTime);
    }
    for(int i = 0 ; i < m ; ++ i ){
        cin >> tmp;
        minWrongTime = min(minWrongTime,tmp);
    }
    if(maxCorrectTime < minWrongTime && 2*minCorrectTime < minWrongTime) cout<<max(maxCorrectTime,2*minCorrectTime)<<endl;
    else cout<<-1<<endl;
    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int a[100];
int b[100];
int main()
{
    int n;
    int m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<m;i++)
    cin>>b[i];
    int mini=a[0];
    int maxi=b[0];;
    for(int i=0;i<m;i++)
    {
            if(b[i]<=maxi)
            maxi=b[i];
            }
            for(int i=0;i<n;i++)
            {
                    if(a[i]<=mini)
                    mini=a[i];
                    }
    if(mini*2>=maxi)
    {
                    cout<<-1;
                    return 0;
                    }
    int ans=a[0];
    int res=a[0];
    for(int i=0;i<n;i++)
    {
            if(a[i]<=res)
            res=a[i];
            if(a[i]>=ans)
            ans=a[i];
            }
    if(res*2<=ans)
            cout<<ans;
    else
            cout<<res*2;
            return 0;

            }


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int a[100];
int b[100];
int main()
{
    int n;
    int m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<m;i++)
    cin>>b[i];
    int mini=a[0];
    int maxi=b[0];;
    for(int i=0;i<m;i++)
    {
            if(b[i]<=maxi)
            maxi=b[i];
            }
            for(int i=0;i<n;i++)
            {
                    if(a[i]<=mini)
                    mini=a[i];
                    }
    if(mini*2>=maxi)
    {
                    cout<<-1;
                    return 0;
                    }
    int ans=a[0];
    int res=a[0];
    for(int i=0;i<n;i++)
    {
            if(a[i]<=res)
            res=a[i];
            if(a[i]>=ans)
            ans=a[i];
            }
    if(res*2>=ans)
            ans=res*2;
    if(ans>=maxi)
    cout<<-1;
    else
    cout<<ans;
            return 0;

            }


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int a[100];
int b[100];
int main()
{
    int n;
    int m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<m;i++)
    cin>>b[i];
    int mini=a[0];
    int maxi=b[0];;
    for(int i=0;i<m;i++)
    {
            if(b[i]<=maxi)
            maxi=b[i];
            }
            for(int i=0;i<n;i++)
            {
                    if(a[i]<=mini)
                    mini=a[i];
                    }
    if(mini*2>=maxi)
    {
                    cout<<-1;
                    return 0;
                    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
            if(a[i]>=ans)
            ans=a[i];
            }
            cout<<ans;
            return 0;
            }


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int a[100];
int b[100];
int main()
{
    int n;
    int m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<m;i++)
    cin>>b[i];
    int mini=a[0];
    int maxi=b[0];;
    for(int i=0;i<m;i++)
    {
            if(b[i]<=maxi)
            maxi=b[i];
            }
            for(int i=0;i<n;i++)
            {
                    if(a[i]<=mini)
                    mini=a[i];
                    }
    if(mini*2>=maxi)
    {
                    cout<<-1;
                    return 0;
                    }
    int ans=a[0];
    int res=a[0];
    for(int i=0;i<n;i++)
    {
            if(a[i]<=res)
            res=a[i];
            if(a[i]>=ans)
            ans=a[i];
            }
    if(res*2>=ans)
            ans=res*2;
    if(ans>maxi)
    cout<<-1;
    else
    cout<<ans;
            return 0;

            }


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int a[100];
int b[100];
int main()
{
    int n;
    int m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<m;i++)
    cin>>b[i];
    int mini=a[0];
    int maxi=b[0];;
    for(int i=0;i<m;i++)
    {
            if(b[i]<=maxi)
            maxi=b[i];
            }
            for(int i=0;i<n;i++)
            {
                    if(a[i]<=mini)
                    mini=a[i];
                    }
    if(mini*2>=maxi)
    {
                    cout<<-1;
                    return 0;
                    }
    int ans=a[0];
    int res=a[0];
    for(int i=0;i<n;i++)
    {
            if(a[i]<=res)
            res=a[i];
            if(a[i]>=ans)
            ans=a[i];
            }
    if(res*2>=ans)
            ans=res*2;
    if(ans>maxi)
    cout<<ans;
    else
    cout<<-1;
            return 0;

            }


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int a[100];
int b[100];
int main()
{
    int n;
    int m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<m;i++)
    cin>>b[i];
    int mini=a[0];
    int maxi=b[0];;
    for(int i=0;i<m;i++)
    {
            if(b[i]<=maxi)
            maxi=b[i];
            }
            for(int i=0;i<n;i++)
            {
                    if(a[i]<=mini)
                    mini=a[i];
                    }
    if(mini*2>=maxi)
    {
                    cout<<-1;
                    return 0;
                    }
    int ans=a[0];
    int res=a[0];
    for(int i=0;i<n;i++)
    {
            if(a[i]<=res)
            res=a[i];
            if(a[i]>=ans)
            ans=a[i];
            }
    return 0;
    if(res*2>=ans)
            ans=res*2;
    if(ans>maxi)
    cout<<-1;
    else
    cout<<ans;
            return 0;

            }


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int a[100];
int b[100];
int main()
{
    int n;
    int m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<m;i++)
    cin>>b[i];
    int mini=a[0];
    int maxi=b[0];;
    for(int i=0;i<m;i++)
    {
            if(b[i]<=maxi)
            maxi=b[i];
            }
            for(int i=0;i<n;i++)
            {
                    if(a[i]<=mini)
                    mini=a[i];
                    }
    if(mini*2>=maxi)
    {
                    cout<<-1;
                    return 0;
                    }
    int ans=a[0];
    int res=a[0];
    for(int i=0;i<n;i++)
    {
            if(a[i]<=res)
            res=a[i];
            if(a[i]>=ans)
            ans=a[i];
            }
    if(res<=ans)
            cout<<ans;
    else
            cout<<res*2;
            return 0;

            }


#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

using PII = pair<int,int>;
using LL = long long;
const int INF = 1000000007;

int main(){
    int n,m,a[100],b[100];
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++) scanf("%d",a+i);
    for(int i=0;i<m;i++) scanf("%d",b+i);
    int lo=*min_element(a,a+n);
    int hi=*max_element(a,a+n);
    int tl=max(lo*2,hi);
    if(*min_element(b,b+m)<=tl) return puts("-1"),0;
    printf("%d\n",tl);
}


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

int main ()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, m;
	vector<int> pass, nopass;

	while(cin >> n >> m )
	{
		pass.resize(n);
		nopass.resize(m);

		for (int i = 0; i < n; ++i) cin >> pass[i];
		for (int i = 0; i < m; ++i) cin >> nopass[i];

		sort(pass.begin(),pass.end());
		sort(nopass.begin(),nopass.end());

		if ((pass.back() < nopass.front()) && (2*pass.front() < nopass.front()))
		{
			cout << max(pass.back(), 2*pass.front() )<< endl;
		}
		else cout << -1 << endl;

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int N, M, A[101], B[101];
int main()
{
  cin >> N >> M;
  for(int i=0; i<N;i++) cin >> A[i];
  for(int i=0; i<M; i++) cin >> B[i];
  sort(A,A+N);
  sort(B,B+M);
  int res = max(A[0]*2, A[N-1]);
  if(res >= B[0])
  cout << -1 << endl;
  else cout<<res;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;
const int inf=0x3f3f3f3f,N=100005;
int n,m,a,b,ans;

int main()
{
    //freopen("in.txt","r",stdin);
    while(scanf("%d%d",&n,&m)!=EOF)
    {
    	int amin=inf,amax=-1;
    	int bmin=inf;
    	for(int i=0;i<n;i++)
    	{
    		scanf("%d",&a);
    		if(a<amin)
    				amin=a;
    		if(a>amax)
    			amax=a;
    	}
    	for(int j=0;j<m;j++)
    	{
    		scanf("%d",&b);
    		if(b<bmin)
    			bmin=b;
    	}
    	//cout<<amax<<" "<<amin<<" "<<bmin<<endl;
    	ans=max(amin*2,amax);
    	if(bmin>ans)
    		printf("%d\n",ans);
    	else printf("-1\n");

    }
 return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;
const int inf=0x3f3f3f3f,N=100005;
int n,m,a,b,ans;

int main()
{
    //freopen("in.txt","r",stdin);
    while(scanf("%d%d",&n,&m)!=EOF)
    {
    	int amin=inf,amax=-1;
    	int bmin=inf;
    	for(int i=0;i<n;i++)
    	{
    		scanf("%d",&a);
    		if(a<amin)
    				amin=a;
    		if(a>amax)
    			amax=a;
    	}
    	for(int j=0;j<m;j++)
    	{
    		scanf("%d",&b);
    		if(b<bmin)
    			bmin=b;
    	}
    	//cout<<amax<<" "<<amin<<" "<<bmin<<endl;
    	ans=bmin-1;
    	if(2*amin<=ans )
    		printf("%d\n",ans);
    	else printf("-1\n");

    }
 return 0;
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;

const int MAXN = 200;
int a[MAXN], b[MAXN];

int main()
{
    int t, n, m, i, j, k, p;
    while(~scanf("%d%d", &n, &m))
    {
        for(i=0; i<n; ++i)
        {
            scanf("%d", &a[i]);
        }
        p = *max_element(a, a+n);
        k = p + p/2;
        j = 0;
        for(i=0; i<m; ++i)
        {
            scanf("%d", &b[i]);
            if(b[i] >= k) j++;
        }
        printf("%d\n", j == 0 ? -1 : p);
    }
    return 0;
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;

const int MAXN = 200;
int a[MAXN], b[MAXN];

int main()
{
    int t, n, m, i, j, k, p, q;
    while(~scanf("%d%d", &n, &m))
    {
        for(i=0; i<n; ++i)
        {
            scanf("%d", &a[i]);
        }
        p = *max_element(a, a+n);
        q = *min_element(a, a+n);
        k = max(p, q*2);
        for(i=0; i<m; ++i)
        {
            scanf("%d", &b[i]);
        }
        j = *min_element(b, b+m);
        if(j <= k) puts("-1");
        else printf("%d\n", k);
    }
    return 0;
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;

const int MAXN = 200;
int a[MAXN], b[MAXN];

int main()
{
    int t, n, m, i, j, k, p, q;
    while(~scanf("%d%d", &n, &m))
    {
        for(i=0; i<n; ++i)
        {
            scanf("%d", &a[i]);
        }
        p = *max_element(a, a+n);
        q = *min_element(a, a+n);
        k = max(p, q*2);
        for(i=0; i<m; ++i)
        {
            scanf("%d", &b[i]);
        }
        j = *min_element(b, b+m);
        if(j < k) puts("-1");
        else printf("%d\n", k);
    }
    return 0;
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;

const int MAXN = 200;
int a[MAXN], b[MAXN];

int main()
{
    int t, n, m, i, j, k, p;
    while(~scanf("%d%d", &n, &m))
    {
        for(i=0; i<n; ++i)
        {
            scanf("%d", &a[i]);
        }
        p = *max_element(a, a+n);
        k = p + p/2;
        j = 0;
        for(i=0; i<m; ++i)
        {
            scanf("%d", &b[i]);
            if(b[i] >= k) j++;
        }
        printf("%d\n", j == 0 ? -1 : j);
    }
    return 0;
}


//
//  by Emil Balashov

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <set>
#include <map>
#include <queue>
using namespace std;

typedef long long lint;
typedef vector<int> vec;
typedef pair<int,int> pii;
typedef pair<int, pii> ipii;
typedef vector<pii> vpii;
typedef vector<pii> vipii;
typedef vector<vector<int> > vvec;
typedef set<int,vec> sv;

typedef vector<int> vint;

//v — целое положительное число;
//все верные решения пройдут системное тестирование;
//хотя бы одно верное решение пройдет системное тестирование с «запасом»;
//все неверные решения не пройдут системное тестирование;
//значение v минимально среди всех TL, для которых верны условия 1, 2, 3, 4.
//3 6
//4 5 2
//8 9 6 10 7 11

int main()
{
    int n, m;
    cin >> n >> m;
    int mna = -1, mxa = -1, mnb = -1;
    for (int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        if (i == 0)
        {
            mna = x;
            mxa = x;
        }
        mna = min(x, mna);
        mxa = max(x, mxa);
    }
    for (int j = 0; j < m; ++j)
    {
        int x;
        cin >> x;
        if (j == 0)
            mnb = x;
        mnb = min(mnb, x);
    }
    int r = -1;
    for (int i = mxa; i < mnb; ++i)
    {
        if (i >= 2 * mna)
        {
            r = i;
            continue;
        }

    }
    cout << r;
    return 0;
}


//
//  by Emil Balashov

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <set>
#include <map>
#include <queue>
using namespace std;

typedef long long lint;
typedef vector<int> vec;
typedef pair<int,int> pii;
typedef pair<int, pii> ipii;
typedef vector<pii> vpii;
typedef vector<pii> vipii;
typedef vector<vector<int> > vvec;
typedef set<int,vec> sv;

typedef vector<int> vint;

//3
//5 0
//0 5
//1 0
//выходные данные
//12
//1 1 R
//2
//1 1 L
//3
//1 5 R
//2
//1 5 L
//3
//1 5 U
//2
//1 5 D
//3

//v — целое положительное число;
//все верные решения пройдут системное тестирование;
//хотя бы одно верное решение пройдет системное тестирование с «запасом»;
//все неверные решения не пройдут системное тестирование;
//значение v минимально среди всех TL, для которых верны условия 1, 2, 3, 4.
//3 6
//4 5 2
//8 9 6 10 7 11

int main()
{
    int n, m;
    cin >> n >> m;
    int mna = -1, mxa = -1, mnb = -1;
    for (int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        if (i == 0)
        {
            mna = x;
            mxa = x;
        }
        mna = min(x, mna);
        mxa = max(x, mxa);
    }
    for (int j = 0; j < m; ++j)
    {
        int x;
        cin >> x;
        if (j == 0)
            mnb = x;
        mnb = min(mnb, x);
    }
    int r = -1;
    for (int i = mxa; i < mnb; ++i)
    {
        if (i >= 2 * mna)
        {
            r = i;
            break;
        }

    }
    cout << r;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main() {
    ll n,m;
    cin>>n>>m;
    vector<ll> a(n);
    vector<ll> b(m);
    for(ll i=0; i<n; ++i) cin>>a[i];
    for(ll i=0; i<m; ++i) cin>>b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for(ll i=1; i<1000; ++i) {
        if(a.back()<=i && b.back()>i+i/2) {// && a.back()<=i+i/2) {
            cout<<i<<'\n';
            return 0;
        }
    }
    cout<<-1<<'\n';

}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main() {
    ll n,m;
    cin>>n>>m;
    vector<ll> a(n);
    vector<ll> b(m);
    for(ll i=0; i<n; ++i) cin>>a[i];
    for(ll i=0; i<m; ++i) cin>>b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for(ll i=1; i<1000000; ++i) {
        if(a.back()<=i && b.back()>i && a[0]*2<=i) {
            cout<<i<<'\n';
            return 0;
        }
    }
    cout<<-1<<'\n';

}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main() {
    ll n,m;
    cin>>n>>m;
    vector<ll> a(n);
    vector<ll> b(m);
    for(ll i=0; i<n; ++i) cin>>a[i];
    for(ll i=0; i<m; ++i) cin>>b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for(ll i=1; i<1000000; ++i) {
        if(a.back()<=i && b[0]>i && a[0]*2<=i) {
            cout<<i<<'\n';
            return 0;
        }
    }
    cout<<-1<<'\n';

}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main() {
    ll n,m;
    cin>>n>>m;
    vector<ll> a(n);
    vector<ll> b(m);
    for(ll i=0; i<n; ++i) cin>>a[i];
    for(ll i=0; i<m; ++i) cin>>b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for(ll i=1; i<1000; ++i) {
        if(a.back()<=i && b.back()>i && a[0]*2<=i) {// && a.back()<=i+i/2) {
            cout<<i<<'\n';
            return 0;
        }
    }
    cout<<-1<<'\n';

}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main() {
    ll n,m;
    cin>>n>>m;
    vector<ll> a(n);
    vector<ll> b(m);
    for(ll i=0; i<n; ++i) cin>>a[i];
    for(ll i=0; i<m; ++i) cin>>b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    cout<<b.back()<<' '<<a.back()<<'\n';
    for(ll i=1; i<1000000; ++i) {
        if(a.back()<=i && b.back()>i && a[0]*2<=i) {
            cout<<i<<'\n';
            return 0;
        }
    }
    cout<<-1<<'\n';

}


#include <cstdio>

int main(){

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

    int correctMax(0), correctMin(100), temp(0);
    bool possible(1);

    while(n--){
        scanf("%d", &temp);
        if(temp > correctMax){correctMax = temp;}
        else if(temp < correctMin){correctMin = temp;}
    }

    if(2 * correctMin > correctMax){possible = 0;}
    while(possible && (m--)){scanf("%d", &temp); if(temp < correctMax){possible = 0; break;}}

    if(possible){printf("%d\n", correctMax);}
    else{puts("-1");}

    return 0;
}


#include <cstdio>

int main(){

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

    int correctMax(0), correctMin(100), wrongMin(100), temp(0);
    bool possible(1);

    while(n--){
        scanf("%d", &temp);
        if(temp > correctMax){correctMax = temp;}
        if(temp < correctMin){correctMin = temp;}
    }

    while(m--){
        scanf("%d", &temp);
        if(temp < correctMax || temp < 2 * correctMin){possible = 0; break;}
        if(temp < wrongMin){wrongMin = temp;}
    }

    if(correctMax < 2 * correctMin){temp = 2 * correctMin;}
    else{temp = correctMax;}

    if(possible){printf("%d\n", temp);}
    else{puts("-1");}

    return 0;
}


#include <cstdio>

int main(){

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

    int correctMax(0), correctMin(100), temp(0);
    bool possible(1);

    while(n--){
        scanf("%d", &temp);
        if(temp > correctMax){correctMax = temp;}
        if(temp < correctMin){correctMin = temp;}
    }

    while(m--){scanf("%d", &temp); if(temp <= correctMax || temp <= 2 * correctMin){possible = 0; break;}}

    if(correctMax < 2 * correctMin){temp = 2 * correctMin;}
    else{temp = correctMax;}

    if(possible){printf("%d\n", temp);}
    else{puts("-1");}

    return 0;
}


#include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <cassert>
#include <numeric>
#include <sstream>
#include <limits>
using namespace std;

#define REQUIRE(cond, message) \
    do { \
        if (!(cond)) { \
            std::cerr << message << std::endl; \
            assert(false); \
        } \
    } while (false)

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define forv(i, v) forn(i, (v).size())
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef vector<string> vs;
typedef long double ld;

template<typename T>
inline int popcount(T t) {
    if (std::numeric_limits<T>::digits <=
                            std::numeric_limits<unsigned int>::digits) {
        return __builtin_popcount(t);
    } else {
        return __builtin_popcountll(t);
    }
}

const ld EPS = 1e-8;
const ld PI = acosl(0.0) * 2;

void solve()
{
    int n, m;
    cin >> n >> m;
    vi a(n);
    forn(i, n) cin >> a[i];
    vi b(m);
    forn(i, m) cin >> b[i];
    sort(all(b));
    sort(all(a));
    int x = max(a.back(), a[0] * 2);
    if (x >= b[0]) cout << -1 << endl;
    else cout << x << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}


#include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <cassert>
#include <numeric>
#include <sstream>
#include <limits>
using namespace std;

#define REQUIRE(cond, message) \
    do { \
        if (!(cond)) { \
            std::cerr << message << std::endl; \
            assert(false); \
        } \
    } while (false)

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define forv(i, v) forn(i, (v).size())
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef vector<string> vs;
typedef long double ld;

template<typename T>
inline int popcount(T t) {
    if (std::numeric_limits<T>::digits <=
                            std::numeric_limits<unsigned int>::digits) {
        return __builtin_popcount(t);
    } else {
        return __builtin_popcountll(t);
    }
}

const ld EPS = 1e-8;
const ld PI = acosl(0.0) * 2;

void solve()
{
    int n, m;
    cin >> n >> m;
    vi a(n);
    forn(i, n) cin >> a[i];
    vi b(m);
    forn(i, m) cin >> b[i];
    sort(all(b));
    sort(all(a));
    int x = max(a.back(), a[0] * 2);
    if (x > b[0]) cout << -1 << endl;
    else cout << x << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}


#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <fstream>
#include <string>
#include <algorithm>
#include <queue>

#define ALL(x) (x).begin(), (x).end()
#define mp make_pair
#define vec vector

typedef long long LL;
typedef unsigned long long ull;
typedef long double LD;

const LL inf = 1000000000ll;
const LL inf64 = inf * inf;
const LL base = inf + 7;
const double pi = acos(-1.0);

using namespace std;

int Abs(int x) {return (x >= 0?x : -x);}

bool solve()
{
    int n, m;

    cin >> n >> m;

    vec<int> a(n), b(m);

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

    sort(ALL(a));
    sort(ALL(b));

    if(b[0] <= a[n - 1]) {cout << -1 << '\n'; return true;}
    if(b[0] <= a[0] * 2) {cout << -1 << '\n'; return true;}

    cout << max(a[0] * 2, a[n - 1]) << '\n';

    return true;
}

int main()
{
    //while(solve());
    solve();

    return 0;
}


#include <cstdio>

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

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	int min_a = 1000000, max_a = 0, min_b = 1000000;
	for(int i = 0; i < n; i++) {
		int t;
		scanf("%d", &t);
		if(t < min_a)
			min_a = t;
		if(t > max_a)
			max_a = t;
	}
	for(int i = 0; i < m; i++) {
		int t;
		scanf("%d", &t);
		if(t < min_b)
			min_b = t;
	}
	if(max(min_a*2, max_a) < min_b)
		printf("%d\n", max(min_a*2, max_a));
	else
		printf("-1\n");
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <map>
#include <fstream>
#include <unordered_map>
#include <cstring>
#include <cctype>

using namespace std;

int main(void){

  int n,m;
  cin>>n>>m;

  vector<int> a(n);
  vector<int> b(m);

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

  for(int i = 0 ; i < m ; i ++) cin>>b[i];

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  int time = b[0]-1;

  bool ok = true;

  if(2*a[0] < time && a[n-1]<b[0]){
    while(ok){
      if(2*a[0] < time && time>=a[n-1]) time--;
      else{
	time++;
	ok = false;
      }
    }

    cout<<time<<endl;
  }
  else cout<<-1<<endl;

return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <map>
#include <fstream>
#include <unordered_map>
#include <cstring>
#include <cctype>

using namespace std;

int main(void){

  int n,m;
  cin>>n>>m;

  vector<int> a(n);
  vector<int> b(m);

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

  for(int i = 0 ; i < m ; i ++) cin>>b[i];

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  int time = b[0]-1;

  bool ok = true;

  if(2*a[0] <= time && a[n-1]<=time){
    while(ok){
      if(2*a[0] < time && time>=a[n-1]) time--;
      else{
	time++;
	ok = false;
      }
    }

    cout<<time<<endl;
  }
  else cout<<-1<<endl;

return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <map>
#include <fstream>
#include <unordered_map>
#include <cstring>
#include <cctype>

using namespace std;

int main(void){

  int n,m;
  cin>>n>>m;

  vector<int> a(n);
  vector<int> b(m);

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

  for(int i = 0 ; i < m ; i ++) cin>>b[i];

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  int time = b[0]-1;

  bool ok = true;

  if(2*a[0] <= time && a[n-1]<=time){
    while(ok){
      if(2*a[0] <= time && time>=a[n-1]) time--;
      else{
	time++;
	ok = false;
      }
    }

    cout<<time<<endl;
  }
  else cout<<-1<<endl;

return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <map>
#include <fstream>
#include <unordered_map>
#include <cstring>
#include <cctype>

using namespace std;

int main(void){

  int n,m;
  cin>>n>>m;

  vector<int> a(n);
  vector<int> b(m);

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

  for(int i = 0 ; i < m ; i ++) cin>>b[i];

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  int time = b[0]-1;

  bool ok = true;

  if(2*a[0] < time && a[n-1]<=time){
    while(ok){
      if(2*a[0] < time && time>=a[n-1]) time--;
      else{
	time++;
	ok = false;
      }
    }

    cout<<time<<endl;
  }
  else cout<<-1<<endl;

return 0;
}


#include <iostream>
#include <cstring>
#include <queue>
#include <stdio.h>
#include <cmath>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <cstdio>
#include <set>
#include <cstdlib>
#include <vector>
#include <cctype>
#include <utility>
#include <map>
#include <string>
using namespace std;
int conversion(string p)
{
    int o;
    o=atoi(p.c_str());
    return o;
}
string toString(int h)
{
    stringstream ss;
    ss<<h;
    return ss.str();
}
long long gcd(long long a,long long b)
{
    return (b==0 ? a : gcd(b,a%b));
}
int lcm(int a,int b)
{
    return (a*(b/gcd(a,b)));
}
bool verMayor(vector<int> f,int x)
{
    int cnt=0;
    for(int i=0; i<f.size(); i++)
    {
        if(x>=f[i])
        {
            cnt++;
        }
    }
    if(cnt==f.size())
    {
        return true;
    }
    return false;
}
bool verMenor(vector<int> f,int x)
{
    int cnt=0;
    for(int i=0; i<f.size(); i++)
    {
        if(x<f[i])
        {
            cnt++;
        }
    }
    if(cnt==f.size())
    {
        return true;
    }
    return false;
}

int main()
{
    int n,m;
    cin>>n>>m;
    vector<int> fn;
    vector<int> fm;
    for(int i=0; i<n; i++)
    {
        int a;
        cin>>a;
        fn.push_back(a);
    }
    for(int i=0; i<m; i++)
    {
        int a;
        cin>>a;
        fm.push_back(a);
    }
    sort(fn.begin(),fn.end());
    int v=fn[0]*2, i=0;
    while(true)
    {
        if(verMayor(fn,v))
        {
            break;
        }
        v++;
    }
    if(verMenor(fm,v))
    {
        cout<<v<<endl;
    }
    else
    {
        cout<<-1<<endl;
    }
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>

#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

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

#define rep(i, n) for (int i=0; i<(n); ++i)
#define repf(i, a, b) for (int i=(a); i<=(b); ++i)
#define repd(i, a, b) for (int i=(a); i>=(b); --i)
#define clr(a, b) memset(a, b, sizeof(a))
#define sz(a) ((int)(a).size())
#define pb push_back
#define N 100

int i,j,k,m,n,l;
int a[N+10], b[N+10];

int main(){
	while (~scanf("%d%d", &n, &m)){
		rep(i, n) scanf("%d", &a[i]);
		rep(i, m) scanf("%d", &b[i]);
		sort(a, a+n), sort(b, b+m);
		int x=max(a[n-1], a[0]*2);
		int y=b[0]-1;
		cout<<x<<' '<<y<<endl;
		if (x<=y)
			cout<<x<<endl;
		else
			cout<<-1<<endl;
	}
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>

#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

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

#define rep(i, n) for (int i=0; i<(n); ++i)
#define repf(i, a, b) for (int i=(a); i<=(b); ++i)
#define repd(i, a, b) for (int i=(a); i>=(b); --i)
#define clr(a, b) memset(a, b, sizeof(a))
#define sz(a) ((int)(a).size())
#define pb push_back
#define N 100

int i,j,k,m,n,l;
int a[N+10], b[N+10];

int main(){
	while (~scanf("%d%d", &n, &m)){
		rep(i, n) scanf("%d", &a[i]);
		rep(i, m) scanf("%d", &b[i]);
		sort(a, a+n), sort(b, b+m);
		int x=max(a[n-1], a[0]*2);
		int y=b[0]-1;
		if (x<=y)
			cout<<x<<endl;
		else
			cout<<-1<<endl;
	}
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>

#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

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

#define rep(i, n) for (int i=0; i<(n); ++i)
#define repf(i, a, b) for (int i=(a); i<=(b); ++i)
#define repd(i, a, b) for (int i=(a); i>=(b); --i)
#define clr(a, b) memset(a, b, sizeof(a))
#define sz(a) ((int)(a).size())
#define pb push_back
#define N 100

int i,j,k,m,n,l;
int a[N+10], b[N+10];

int main(){
    while (~scanf("%d%d", &n, &m)){
        rep(i, n) scanf("%d", &a[i]);
        rep(i, m) scanf("%d", &b[i]);
        sort(a, a+n), sort(b, b+m);
        int x=max(a[n-1], a[0]*2);
        int y=b[0]-1;
        cout<<x<<' '<<y<<endl;
        if (x<=y)
            cout<<x<<endl;
        else
            cout<<-1<<endl;
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>

#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

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

#define rep(i, n) for (int i=0; i<(n); ++i)
#define repf(i, a, b) for (int i=(a); i<=(b); ++i)
#define repd(i, a, b) for (int i=(a); i>=(b); --i)
#define clr(a, b) memset(a, b, sizeof(a))
#define sz(a) ((int)(a).size())
#define pb push_back
#define N 100

int i,j,k,m,n,l;
int a[N+10], b[N+10];

int main(){
	while (~scanf("%d%d", &n, &m)){
		rep(i, n) scanf("%d", &a[i]);
		rep(i, m) scanf("%d", &b[i]);
		sort(a, a+n), sort(b, b+n);
		int x=max(a[n-1], a[0]*2);
		int y=b[0]-1;
		if (x<=y)
			cout<<x<<endl;
		else
			cout<<-1<<endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int max(int a, int b)
{
	if (a > b)
		return a;
	return b;
}
int main(){
	ios_base::sync_with_stdio(0);
	int n, m; cin >> n >> m;
	int *ac = new int[n];
	int *w = new int[m];
	for (int i = 0; i < n; i++){
		cin >> ac[i];
	}
	for (int i = 0; i < m; i++){
		cin >> w[i];
	}
	sort(ac, ac + n);
	sort(w, w + m);
	if (w[0]>max(ac[n - 1], ac[0] * 2)){
		cout << max(ac[n - 1], ac[0] * 2);
		return 0;
	}
	cout << -1;
}


#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;
int main(){
  vector<int>v,w;
  int n, m;
  cin>>n>>m;
  v.resize(n);
  w.resize(m);
  for_each(v.begin(),v.end(),[](int&x){cin>>x;});
  for_each(w.begin(),w.end(),[](int&x){cin>>x;});
  sort(v.begin(),v.end());
  sort(w.begin(),w.end());
  int cnt, mn;
  mn=v[n-1];
  for(int i=0;i<=100;++i){
    if(mn+i>=2*v[0]){
      mn = mn + i;
      break;
    }
  }
  if(mn >= w[0]){
    cout<<-1<<endl;return 0;
  }
  else{
    cout<<mn<<endl;
  }
  return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int a[100000];
int b[100000];
int main()
{
	int n , m;
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int j = 0; j < m; j++)
		cin >> b[j];
	sort(b , b + m);
	sort(a , a + n);
	int v = 0;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			if(a[i] > b[j]) {
				cout << "-1" << endl;
				return 0;
			}
	int ans = max(a[0] * 2 , a[n - 1]);
	if(ans >= b[0])
		cout << "-1" << endl;
	else
		cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 101;
int arr[MAXN];
int barr[MAXN];
int main () {
    int n, m;
    cin >> n >> m;
    int tl;
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    for(int i = 0; i < m; i++)
        cin >> barr[i];
    sort(arr, arr + n);
    sort(barr, barr + n);
    tl = arr[n - 1];
    if(arr[0] * 2 <= tl){
        cout << tl << " " << '\n';
        return 0;
    }
    while(tl < barr[0]){
        tl++;
        if(arr[0] * 2 <= tl)
            cout << tl << " " << '\n';
        return 0;
    }
    cout << "-1" << " " << '\n';
    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 101;
int arr[MAXN];
int barr[MAXN];
int main () {
    int n, m;
    cin >> n >> m;
    int tl;
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    for(int i = 0; i < m; i++)
        cin >> barr[i];
    sort(arr, arr + n);
    sort(barr, barr + n);
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            if(arr[i] == barr[j]){
                cout << "-1" << " " << '\n';
                return 0;
            }
    tl = arr[n - 1];
    if(arr[0] * 2 <= tl){
        cout << tl << " " << '\n';
        return 0;
    }
    while(tl < barr[0]){
        tl++;
        if(arr[0] * 2 <= tl)
            cout << tl << " " << '\n';
        return 0;
    }
    cout << "-1" << " " << '\n';
    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 101;
int arr[MAXN];
int barr[MAXN];
int main () {
    int n, m;
    cin >> n >> m;
    int tl;
    int cnt = 0;
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    for(int i = 0; i < m; i++)
        cin >> barr[i];
    sort(arr, arr + n);
    sort(barr, barr + n);
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            if(arr[i] == barr[j]){
                cout << "-1" << " " << '\n';
                return 0;
            }
    tl = arr[n - 1];
    if(arr[0] * 2 <= tl){
        cout << tl << " " << '\n';
        return 0;
    }
    while(tl < barr[0]){
        tl++;
        if(arr[0] * 2 <= tl){
            for(int i = 0; i < m; i++)
                if(barr[i] <= tl)
                    cnt++;
            if(cnt == 0){
            cout << tl << " " << '\n';
            return 0;
            }
            else {
                cout << "-1" << " " << '\n';
                return 0;
            }
        }
    }
    for(int i = 0; i < m; i++)
        if(barr[i] <= tl){
            cout << "-1" << " " << '\n';
            return 0;
        }
    cout << "-1" << " " << '\n';
    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 101;
int arr[MAXN];
int barr[MAXN];
int main () {
    int n, m;
    cin >> n >> m;
    int tl;
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    for(int i = 0; i < m; i++)
        cin >> barr[i];
    sort(arr, arr + n);
    sort(barr, barr + n);
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            if(arr[i] == barr[j]){
                cout << "-1" << " " << '\n';
                return 0;
            }
    tl = arr[n - 1];
    if(arr[0] * 2 <= tl){
        cout << tl << " " << '\n';
        return 0;
    }
    while(tl < barr[0]){
        tl++;
        if(arr[0] * 2 <= tl){
            cout << tl << " " << '\n';
            return 0;
        }
    }
    for(int i = 0; i < m; i++)
        if(barr[i] <= tl){
            cout << "-1" << " " << '\n';
            return 0;
        }
    cout << "-1" << " " << '\n';
    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 101;
int arr[MAXN];
int barr[MAXN];
int main () {
    int n, m;
    cin >> n >> m;
    int tl;
    int cnt = 0;
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    for(int i = 0; i < m; i++)
        cin >> barr[i];
    sort(arr, arr + n);
    sort(barr, barr + m);
        tl = arr[n - 1];
    if(arr[0] * 2 <= tl && tl < barr[0]){
        cout << tl << " " << '\n';
        return 0;
    }
    while(tl < barr[0]){
        tl++;
        if(arr[0] * 2 <= tl){
            for(int i = 0; i < m; i++){
                if(barr[i] <= tl){
                    cnt++;
                }
            }
            if(cnt == 0){
            cout << tl << " " << '\n';
            return 0;
            }
            else {
                cout << "-1" << " " << '\n';
                return 0;
            }
        }
    }
    for(int i = 0; i < m; i++)
        if(barr[i] <= tl){
            cout << "-1" << " " << '\n';
            return 0;
        }
    cout << "-1" << " " << '\n';
    return 0;
}


#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>

#define oo 1e9
#define pi 3.1415926536
#define all(x) x.begin(),x.end()
#define sorta(x) sort(all(x))
#define sortam(x,comp) sort(all(x),comp)
#define sortd(x) sort(x.rbegin(),x.rend())
#define pb push_back
#define mp make_pair

typedef long long ll;
using namespace std;

int main() {
    int n, m;
    while(cin >> n>>m) {
        vector<int>corr(n), w(m);
        for(int i = 0; i < n; cin >> corr[i++]);
        for(int i = 0; i < m; cin >> w[i++]);
        sorta(corr);
        sorta(w);
        int res = max(2 * corr[0], corr.back());
        if(res>=w[0]) cout << -1 << endl;
        else cout << res << endl;
    }
    return 0;
}


#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include<queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

#define pi 2*acos(0)
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
#define m_p make_pair
#define p_b push_back
#define sortv(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define mem(a,k) memset(a,k,sizeof a)
#define F(i,n) for(int i=0;i<n;i++)
#define u_b(X,V) upper_bound(X.begin(),X.end(),V)
#define l_b(X,V) lower_bound(X.begin(),X.end(),V)

using namespace std;

ll n,m,i,j,k,t,ans,a;
vector<ll> v1,v2;
int main(){
ios_base::sync_with_stdio(0);

cin>>n>>m;

for(i=1;i<=n;i++)
{
    cin>>a;
    v1.p_b(a);

}
for(i=1;i<=m;i++)
{
    cin>>a;
    v2.p_b(a);

}

sortv(v1);sortv(v2);
 ll x=v1.size();
 if (2*v1[0] <= v1[x-1] && v1[x-1] < v2[0] ) {
        cout<<v1[x-1]; return 0 ; }
  else if (v2[0] > 2*v1[0] )
  {
      for (int i = v2[0]-1 ; i>v1[x-1] ; i--)
      {
          if ( i <= 2* v1[0])
          {
             cout<<i;
             return 0 ;
          }
      }
  }
  cout<<-1<<endl;

return 0;
}


#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include<queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

#define pi 2*acos(0)
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
#define m_p make_pair
#define p_b push_back
#define sortv(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define mem(a,k) memset(a,k,sizeof a)
#define F(i,n) for(int i=0;i<n;i++)
#define u_b(X,V) upper_bound(X.begin(),X.end(),V)
#define l_b(X,V) lower_bound(X.begin(),X.end(),V)

using namespace std;

ll n,m,i,j,k,t,ans,a;
vector<ll> v1,v2;
int main(){
ios_base::sync_with_stdio(0);

cin>>n>>m;

for(i=1;i<=n;i++)
{
    cin>>a;
    v1.p_b(a);

}
for(i=1;i<=m;i++)
{
    cin>>a;
    v2.p_b(a);

}

sortv(v1);sortv(v2);
if((v2[0]-v1[v1.size()-1]<=0)||(2*v1[0]>v1[v1.size()-1]&&2*v1[0]>=v2[0])){
    cout<<-1<<endl;
    return 0;
}

cout<<2*v1[0]<<endl;

return 0;
}


#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include<queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

#define pi 2*acos(0)
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
#define m_p make_pair
#define p_b push_back
#define sortv(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define mem(a,k) memset(a,k,sizeof a)
#define F(i,n) for(int i=0;i<n;i++)
#define u_b(X,V) upper_bound(X.begin(),X.end(),V)
#define l_b(X,V) lower_bound(X.begin(),X.end(),V)

using namespace std;

ll n,m,i,j,k,t,ans,a;
vector<ll> v1,v2;
int main(){
ios_base::sync_with_stdio(0);

cin>>n>>m;

for(i=1;i<=n;i++)
{
    cin>>a;
    v1.p_b(a);

}
for(i=1;i<=m;i++)
{
    cin>>a;
    v2.p_b(a);

}

sortv(v1);sortv(v2);
if((v2[0]-v1[v1.size()-1]<=0)||(2*v1[0]>v1[v1.size()-1]&&2*v1[0]>=v2[0])){
    cout<<-1<<endl;
    return 0;
}

cout<<v2[0]-1<<endl;

return 0;
}


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

int main() {
    int n, m, t;
    cin >> n >> m;
    vector<int> a, b;
    for (int i(0); i < n; ++i) {
        cin >> t;
        a.push_back(t);
    }
    for (int i(0); i < m; ++i) {
        cin >> t;
        b.push_back(t);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for (int i(max(a.front() * 2, a.back())); i < b.front(); ++i) {
        cout << i;
        return 0;
    }
    cout << -1;
    return 0;
}


//blaster dragon ruler, rank up magic astral force, evo-singulary, wiretap,
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#define inf 2000000000

using namespace std;

int main ()
{
    int n, m;
    scanf ("%d %d", &n, &m);
    int maxa = 0;
    int mina = inf;
    int tmp;
    for (int i = 0; i < n; i++)
    {
        scanf ("%d", &tmp);
        if (tmp < mina)
            mina = tmp;
        if (tmp > maxa)
            maxa = tmp;
    }
    int minb = inf;
    for (int i = 0; i < m; i++)
    {
        scanf ("%d", &tmp);
        if (tmp < minb)
            minb = tmp;
    }
    if (max(2 * mina, maxa) < minb)
        cout << max (2 * mina, maxa);
    else
        cout << "-1";
    return 0;
}


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

using namespace std;

auto main() -> int
{
    int n, m;
    cin >> n >> m;
    vector<int> A(n);
    vector<int> B(m);
    for(int i = 0; i < n; i++) cin >> A[i];
    for(int i = 0; i < m; i++) cin >> B[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    if(2 * A[0] > A[n - 1] || A[n - 1] >= B[0]) {
        if((A[0] == A[n - 1] && 2 * A[0] < B[0]) || (2 * A[0] > A[n - 1] && 2 * A[0] < B[0])) {
            cout << 2 * A[0] << endl;
            return 0;
        }
        cout << -1 << endl;
        return 0;
    }
    cout << A[n - 1] << endl;

    return 0;
}