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

#define fill(x,y) memset(x,y,sizeof(x))
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define pb push_back
#define smp(x,y,z) mp(x,mp(y,z))
#define reads(x) scanf("%s",&x)
#define read(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define read3(x,y,z) scanf("%d%d%d",&x,&y,&z)

typedef long long ll;
typedef string s;
typedef pair<ll,ll> pii;
typedef pair<int,string> pis;
typedef pair<string,int> psi;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vector<int> > matrix;

const ll oo = 1e16;
const int maxSize = 100100;
const int mod = 1e9+7;

const double EPS = (1e-9);

int dcmp(double x, double y){return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;}

int n,arr[maxSize],coun[100100]={0} ;
multiset<int> ones;
vi twos;

int main(){
    cin >> n ;
    for(int i=0 ;i<n ;i++){
        int num ; cin>>arr[i] ; coun[arr[i]]++;
    }
    n=0;
    for(int i=1;i<=100100;i++){
        if( coun[i]%2 !=0)coun[i]%=2;
        else if(coun[i]!=0) coun[i]=2 ;
        if(coun[i]==1)ones.insert(i);
        if(coun[i]==2)twos.pb(i);
        if(coun[i]!=0)n++;
    }
    if(sz(twos)==1){
        cout << n-1 ; return 0;
    }else if(sz(twos)==2){
        for(int i=twos[0]+1 ; i<twos[1] ; i++)
            if(ones.count(i) > 0 ){
                cout << n ; return 0;
            }
        cout << n-1 ;
    }else if(sz(twos)%2==0){
        for(int i=twos[sz(twos)/2-1]+1 ; i<twos[n/2] ; i++)
            if(ones.count(i) > 0 ){
                cout << n ; return 0;
            }
        cout << n-1 ;
    }else {
        cout << n-1 ;
    }

}
