#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<map>
#include<cmath>
#include<iostream>
#include<vector>
#include<ctime>
#include<algorithm>
#include<string>
using namespace std;
#define MAXN 500010
int a[MAXN];
int b[MAXN];
int main() {
    int n;
    while (~scanf("%d", &n)) {
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }
        bool flag = false;
        int cnt = 0;
        for (int t = 64; !flag && t > 0; t--) {
            b[0] = a[0];
            b[n - 1] = a[n - 1];
            for (int i = 1; i < n - 1; ++i) {
                int x = 0;
                int y = 0;
                for (int j = i - 1; j <= i + 1; ++j) {
                    if (a[j] == 0) {
                        ++x;
                    } else {
                        ++y;
                    }
                }
                if (x > y) {
                    b[i] = 0;
                } else {
                    b[i] = 1;
                }
            }
            flag = true;
            for (int i = 0; i < n; ++i) {
                if (a[i] != b[i]) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                break;
            }
            for (int i = 0; i < n; i++) {
                a[i] = b[i];
            }
            ++cnt;
        }
        if (flag) {
            printf("%d\n", cnt);
            for (int i = 0; i < n; i++) {
                printf("%d ", b[i]);
            }
            puts("");
        } else {
            puts("-1");
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "delete_this.hpp"
#define t(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define t(...)
#endif

int n;
int a[500000 + 100];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    bool ada = false;
    vector<pair<int, int> > id;
    int indeks = -1;
    int inc = 1;
    int len = 0;
    a[0] = 123123;
    a[n + 1] = 123123;
    for (int i = 1; i <= n - 1; i += inc) {
        if (a[i] == 1 && a[i + 1] == 0 && !ada) {
            assert(len == 0);
            ada = true;
            indeks = i;
            inc = 2;
            len++;
            continue;
        }
        if (a[i] == 1 && a[i + 1] == 0 && ada) {
            assert(inc == 2);
            len++;
            continue;
        }
        if ((a[i] != 1 || a[i + 1] != 0) && ada) {
            assert(inc == 2);
            ada = false;
            inc = 1;
            id.emplace_back(indeks, len);
            len = 0;
            indeks = -1;
        }
    }
    if (indeks != -1 && len != 0) {
        id.emplace_back(indeks, len);
    }
    if (id.size() == 0) {
        puts("0");
        for (int i = 1; i <= n; i++) {
            printf("%d ", a[i]);
        }
        return 0;
    }

    int sz = id.size();
    t(id);
    int ans = 0;
    for (int i = 0; i <= sz - 1; i++) {
        int idx = id[i].first;
        int len = id[i].second;
        int pfft = len;
        if ( (idx == 1 || a[idx - 1] == 1) && (a[idx + 2 * len] == 0 || idx + 2 * len - 1 == n) ) {
            pfft--;
        }
        ans = max(ans, pfft);
        int kiri = -1;
        int kanan = -1;
        if (a[idx + 2 * len] == 1) {
            kanan = 1;
        } else {
            kanan = 0;
        }
        if (idx == 1 || a[idx - 1] == 1) {
            kiri = 1;
        } else {
            kiri = 0;
        }
        for (int j = idx; j <= idx + len - 1; j++) {
            a[j] = kiri;
        }
        for (int j = idx + len; j <= idx + 2 * len - 1; j++) {
            a[j] = kanan;
        }
    }
    cout << ans << "\n";
    for (int i = 1; i <= n; i++) {
        printf("%d ", a[i]);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "delete_this.hpp"
#define t(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define t(...)
#endif

int n;
int a[500000 + 100];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    bool ada = false;
    vector<pair<int, int> > id;
    int indeks = -1;
    int inc = 1;
    int len = 0;
    a[0] = 123123;
    a[n + 1] = 123123;
    for (int i = 1; i <= n - 1; i += inc) {
        if (a[i] == 1 && a[i + 1] == 0 && !ada) {
            assert(len == 0);
            ada = true;
            indeks = i;
            inc = 2;
            len++;
            continue;
        }
        if (a[i] == 1 && a[i + 1] == 0 && ada) {
            assert(inc == 2);
            len++;
            continue;
        }
        if ((a[i] != 1 && a[i + 1] == 0) && ada) {
            assert(inc == 2);
            ada = false;
            i = i + 1;
            inc = 1;
            id.emplace_back(indeks, len);
            len = 0;
            indeks = -1;
        }
    }
    if (indeks != -1 && len != 0) {
        id.emplace_back(indeks, len);
    }
    if (id.size() == 0) {
        puts("0");
        for (int i = 1; i <= n; i++) {
            printf("%d ", a[i]);
        }
        return 0;
    }
    int sz = id.size();
    t(id);
    int ans = 0;
    for (int i = 0; i <= sz - 1; i++) {
        int idx = id[i].first;
        int len = id[i].second;
        int pfft = len;
        if (idx == 1 || a[idx - 1]  == 1) {
            pfft--;
        }
        if (a[idx + len * 2] == 1) {
            pfft++;
        }
        ans = max(ans, pfft);
        int kiri = -1;
        int kanan = -1;
        if (a[idx + 2 * len] == 1) {
            kanan = 1;
        } else {
            kanan = 0;
        }
        if (idx == 1 || a[idx - 1] == 1) {
            kiri = 1;
        } else {
            kiri = 0;
        }
        for (int j = idx; j <= idx + len - 1; j++) {
            a[j] = kiri;
        }
        for (int j = idx + len; j <= idx + 2 * len - 1; j++) {
            a[j] = kanan;
        }
    }
    cout << ans << "\n";
    for (int i = 1; i <= n; i++) {
        printf("%d ", a[i]);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "delete_this.hpp"
#define t(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define t(...)
#endif

int n;
int a[500000 + 100];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    bool ada = false;
    vector<pair<int, int> > id;
    int indeks = -1;
    int inc = 1;
    int len = 0;
    a[0] = 123123;
    a[n + 1] = 123123;
    for (int i = 1; i <= n - 1; i += inc) {
        if (a[i] == 1 && a[i + 1] == 0 && !ada) {
            assert(len == 0);
            ada = true;
            indeks = i;
            inc = 2;
            len++;
            continue;
        }
        if (a[i] == 1 && a[i + 1] == 0 && ada) {
            assert(inc == 2);
            len++;
            continue;
        }
        if ((a[i] != 1 && a[i + 1] == 0) && ada) {
            assert(inc == 2);
            ada = false;
            i = i + 1;
            inc = 1;
            id.emplace_back(indeks, len);
            len = 0;
            indeks = -1;
        }
    }
    if (indeks != -1 && len != 0) {
        id.emplace_back(indeks, len);
    }
    if (id.size() == 0) {
        puts("0");
        for (int i = 1; i <= n; i++) {
            printf("%d ", a[i]);
        }
        return 0;
    }
    int sz = id.size();
    t(id);
    int ans = 0;
    for (int i = 0; i <= sz - 1; i++) {
        int idx = id[i].first;
        int len = id[i].second;
        if (idx + len * 2 == 1) {
            ans = max(len + 1, ans);
        } else {
            ans = max(len, ans);
        }
        int kiri = -1;
        int kanan = -1;
        if (a[idx + 2 * len] == 1) {
            kanan = 1;
        } else {
            kanan = 0;
        }
        if (idx == 1 || a[idx - 1] == 1) {
            kiri = 1;
        } else {
            kiri = 0;
        }
        for (int j = idx; j <= idx + len - 1; j++) {
            a[j] = kiri;
        }
        for (int j = idx + len; j <= idx + 2 * len - 1; j++) {
            a[j] = kanan;
        }
    }
    cout << ans << "\n";
    for (int i = 1; i <= n; i++) {
        printf("%d ", a[i]);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "delete_this.hpp"
#define t(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define t(...)
#endif

int n;
int a[500000 + 100];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    bool ada = false;
    vector<pair<int, int> > id;
    int indeks = -1;
    int inc = 1;
    int len = 0;
    a[0] = 123123;
    a[n + 1] = 123123;
    for (int i = 1; i <= n - 1; i += inc) {
        if (a[i] == 1 && a[i + 1] == 0 && !ada) {
            assert(len == 0);
            ada = true;
            indeks = i;
            inc = 2;
            len++;
            continue;
        }
        if (a[i] == 1 && a[i + 1] == 0 && ada) {
            assert(inc == 2);
            len++;
            continue;
        }
        if ((a[i] != 1 && a[i + 1] != 0) && ada) {
            assert(inc == 2);
            ada = false;
            i = i + 1;
            inc = 1;
            id.emplace_back(indeks, len);
            len = 0;
            indeks = -1;
        }
    }
    if (indeks != -1 && len != 0) {
        id.emplace_back(indeks, len);
    }
    if (id.size() == 0) {
        puts("0");
        for (int i = 1; i <= n; i++) {
            printf("%d ", a[i]);
        }
        return 0;
    }
    int sz = id.size();
    t(id);
    int ans = 0;
    for (int i = 0; i <= sz - 1; i++) {
        int idx = id[i].first;
        int len = id[i].second;
        int pfft = len;
        // if (len == 1 && a[idx - 1] != 0 && a[len * 2 + idx] == 0) {
        //     continue;
        // }
        if (idx == 1 || a[idx - 1]  == 1) {
            pfft--;
        }
        if (a[idx + len * 2] == 1) {
            pfft++;
        }
        ans = max(ans, pfft);
        int kiri = -1;
        int kanan = -1;
        if (a[idx + 2 * len] == 1) {
            kanan = 1;
        } else {
            kanan = 0;
        }
        if (idx == 1 || a[idx - 1] == 1) {
            kiri = 1;
        } else {
            kiri = 0;
        }
        for (int j = idx; j <= idx + len - 1; j++) {
            a[j] = kiri;
        }
        for (int j = idx + len; j <= idx + 2 * len - 1; j++) {
            a[j] = kanan;
        }
    }
    cout << ans << "\n";
    for (int i = 1; i <= n; i++) {
        printf("%d ", a[i]);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "delete_this.hpp"
#define t(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define t(...)
#endif

int n;
int a[500000 + 100];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    bool ada = false;
    vector<pair<int, int> > id;
    int indeks = -1;
    int inc = 1;
    int len = 0;
    a[0] = 123123;
    a[n + 1] = 123123;
    for (int i = 1; i <= n - 1; i += inc) {
        if (a[i] == 1 && a[i + 1] == 0 && !ada) {
            assert(len == 0);
            ada = true;
            indeks = i;
            inc = 2;
            len++;
            continue;
        }
        if (a[i] == 1 && a[i + 1] == 0 && ada) {
            assert(inc == 2);
            len++;
            continue;
        }
        if ((a[i] != 1 && a[i + 1] == 0) && ada) {
            assert(inc == 2);
            ada = false;
            i = i + 1;
            inc = 1;
            id.emplace_back(indeks, len);
            len = 0;
            indeks = -1;
        }
    }
    if (indeks != -1 && len != 0) {
        id.emplace_back(indeks, len);
    }
    if (id.size() == 0) {
        puts("0");
        for (int i = 1; i <= n; i++) {
            printf("%d ", a[i]);
        }
        return 0;
    }
    int sz = id.size();
    t(id);
    int ans = 0;
    for (int i = 0; i <= sz - 1; i++) {
        int idx = id[i].first;
        int len = id[i].second;
        if (a[idx + len * 2] == 1) {
            ans = max(len, ans);
        } else {
            ans = max(len - 1, ans);
        }
        int kiri = -1;
        int kanan = -1;
        if (a[idx + 2 * len] == 1) {
            kanan = 1;
        } else {
            kanan = 0;
        }
        if (idx == 1 || a[idx - 1] == 1) {
            kiri = 1;
        } else {
            kiri = 0;
        }
        for (int j = idx; j <= idx + len - 1; j++) {
            a[j] = kiri;
        }
        for (int j = idx + len; j <= idx + 2 * len - 1; j++) {
            a[j] = kanan;
        }
    }
    cout << ans << "\n";
    for (int i = 1; i <= n; i++) {
        printf("%d ", a[i]);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "delete_this.hpp"
#define t(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define t(...)
#endif

int n;
int a[500000 + 100];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    bool ada = false;
    vector<pair<int, int> > id;
    int indeks = -1;
    int inc = 1;
    int len = 0;
    a[0] = 123123;
    a[n + 1] = 123123;
    for (int i = 1; i <= n - 1; i += inc) {
        if (a[i] == 1 && a[i + 1] == 0 && !ada) {
            assert(len == 0);
            ada = true;
            indeks = i;
            inc = 2;
            len++;
            continue;
        }
        if (a[i] == 1 && a[i + 1] == 0 && ada) {
            assert(inc == 2);
            len++;
            continue;
        }
        if ((a[i] != 1 || a[i + 1] != 0) && ada) {
            assert(inc == 2);
            ada = false;
            i = i + 1;
            inc = 1;
            id.emplace_back(indeks, len);
            len = 0;
            indeks = -1;
        }
    }
    if (indeks != -1 && len != 0) {
        id.emplace_back(indeks, len);
    }
    if (id.size() == 0) {
        puts("0");
        for (int i = 1; i <= n; i++) {
            printf("%d ", a[i]);
        }
        return 0;
    }
    int sz = id.size();
    t(id);
    int ans = 0;
    for (int i = 0; i <= sz - 1; i++) {
        int idx = id[i].first;
        int len = id[i].second;
        int pfft = len;
        // if (len == 1 && a[idx - 1] != 0 && a[len * 2 + idx] == 0) {
        //     continue;
        // }
        if (idx == 1 || a[idx - 1]  == 1) {
            pfft--;
        }
        if (a[idx + len * 2] == 1) {
            pfft++;
        }
        ans = max(ans, pfft);
        int kiri = -1;
        int kanan = -1;
        if (a[idx + 2 * len] == 1) {
            kanan = 1;
        } else {
            kanan = 0;
        }
        if (idx == 1 || a[idx - 1] == 1) {
            kiri = 1;
        } else {
            kiri = 0;
        }
        for (int j = idx; j <= idx + len - 1; j++) {
            a[j] = kiri;
        }
        for (int j = idx + len; j <= idx + 2 * len - 1; j++) {
            a[j] = kanan;
        }
    }
    cout << ans << "\n";
    for (int i = 1; i <= n; i++) {
        printf("%d ", a[i]);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "delete_this.hpp"
#define t(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define t(...)
#endif

int n;
int a[500000 + 100];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    bool ada = false;
    vector<pair<int, int> > id;
    int indeks = -1;
    int inc = 1;
    int len = 0;
    a[0] = 123123;
    a[n + 1] = 123123;
    for (int i = 1; i <= n - 1; i += inc) {
        if (a[i] == 1 && a[i + 1] == 0 && !ada) {
            assert(len == 0);
            ada = true;
            indeks = i;
            inc = 2;
            len++;
            continue;
        }
        if (a[i] == 1 && a[i + 1] == 0 && ada) {
            assert(inc == 2);
            len++;
            continue;
        }
        if ((a[i] != 1 || a[i + 1] != 0) && ada) {
            assert(inc == 2);
            ada = false;
            i = i + 1;
            inc = 1;
            id.emplace_back(indeks, len);
            len = 0;
            indeks = -1;
        }
    }
    if (indeks != -1 && len != 0) {
        id.emplace_back(indeks, len);
    }
    if (id.size() == 0) {
        puts("0");
        for (int i = 1; i <= n; i++) {
            printf("%d ", a[i]);
        }
        return 0;
    }
    int sz = id.size();
    t(id);
    int ans = 0;
    for (int i = 0; i <= sz - 1; i++) {
        int idx = id[i].first;
        int len = id[i].second;
        int pfft = len;
        if (len == 1 && a[idx - 1] != 0 && a[len * 2 + idx] == 0) {
            continue;
        }
        if ( (idx == 1 || a[idx - 1]  == 1) && (a[idx + 2 * len] == 0) || idx + 2 * len - 1 == 0) {
            pfft--;
        }
        ans = max(ans, pfft);
        int kiri = -1;
        int kanan = -1;
        if (a[idx + 2 * len] == 1) {
            kanan = 1;
        } else {
            kanan = 0;
        }
        if (idx == 1 || a[idx - 1] == 1) {
            kiri = 1;
        } else {
            kiri = 0;
        }
        for (int j = idx; j <= idx + len - 1; j++) {
            a[j] = kiri;
        }
        for (int j = idx + len; j <= idx + 2 * len - 1; j++) {
            a[j] = kanan;
        }
    }
    cout << ans << "\n";
    for (int i = 1; i <= n; i++) {
        printf("%d ", a[i]);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "delete_this.hpp"
#define t(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define t(...)
#endif

int n;
int a[500000 + 100];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    bool ada = false;
    vector<pair<int, int> > id;
    int indeks = -1;
    int inc = 1;
    int len = 0;
    a[0] = 123123;
    a[n + 1] = 123123;
    for (int i = 1; i <= n - 1; i += inc) {
        if (a[i] == 1 && a[i + 1] == 0 && !ada) {
            assert(len == 0);
            ada = true;
            indeks = i;
            inc = 2;
            len++;
            continue;
        }
        if (a[i] == 1 && a[i + 1] == 0 && ada) {
            assert(inc == 2);
            len++;
            continue;
        }
        if ((a[i] != 1 || a[i + 1] != 0) && ada) {
            assert(inc == 2);
            ada = false;
            i = i + 1;
            inc = 1;
            id.emplace_back(indeks, len);
            len = 0;
            indeks = -1;
        }
    }
    if (indeks != -1 && len != 0) {
        id.emplace_back(indeks, len);
    }
    if (id.size() == 0) {
        puts("0");
        for (int i = 1; i <= n; i++) {
            printf("%d ", a[i]);
        }
        return 0;
    }

    int sz = id.size();
    t(id);
    int ans = 0;
    for (int i = 0; i <= sz - 1; i++) {
        int idx = id[i].first;
        int len = id[i].second;
        int pfft = len;
        if ( (idx == 1 || a[idx - 1] == 1)) {
            pfft--;
        }
        ans = max(ans, pfft);
        int kiri = -1;
        int kanan = -1;
        if (a[idx + 2 * len] == 1) {
            kanan = 1;
        } else {
            kanan = 0;
        }
        if (idx == 1 || a[idx - 1] == 1) {
            kiri = 1;
        } else {
            kiri = 0;
        }
        for (int j = idx; j <= idx + len - 1; j++) {
            a[j] = kiri;
        }
        for (int j = idx + len; j <= idx + 2 * len - 1; j++) {
            a[j] = kanan;
        }
    }
    cout << ans << "\n";
    for (int i = 1; i <= n; i++) {
        printf("%d ", a[i]);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "delete_this.hpp"
#define t(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define t(...)
#endif

int n;
int a[500000 + 100];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    bool ada = false;
    vector<pair<int, int> > id;
    int indeks = -1;
    int inc = 1;
    int len = 0;
    a[0] = 123123;
    a[n + 1] = 123123;
    for (int i = 1; i <= n - 1; i += inc) {
        if (a[i] == 1 && a[i + 1] == 0 && !ada) {
            assert(len == 0);
            ada = true;
            indeks = i;
            inc = 2;
            len++;
            continue;
        }
        if (a[i] == 1 && a[i + 1] == 0 && ada) {
            assert(inc == 2);
            len++;
            continue;
        }
        if ((a[i] != 1 || a[i + 1] != 0) && ada) {
            assert(inc == 2);
            ada = false;
            i = i + 1;
            inc = 1;
            id.emplace_back(indeks, len);
            len = 0;
            indeks = -1;
        }
    }
    if (indeks != -1 && len != 0) {
        id.emplace_back(indeks, len);
    }
    if (id.size() == 0) {
        puts("0");
        for (int i = 1; i <= n; i++) {
            printf("%d ", a[i]);
        }
        return 0;
    }
    int sz = id.size();
    t(id);
    int ans = 0;
    for (int i = 0; i <= sz - 1; i++) {
        int idx = id[i].first;
        int len = id[i].second;
        int pfft = len;
        if (len == 1 && a[idx - 1] != 0 && a[len * 2 + idx] == 0) {
            continue;
        }
        if ( (idx == 1 || a[idx - 1]  == 1) && (a[idx + 2 * len] == 0 || idx + 2 * len - 1 == n) ) {
            pfft--;
        }
        ans = max(ans, pfft);
        int kiri = -1;
        int kanan = -1;
        if (a[idx + 2 * len] == 1) {
            kanan = 1;
        } else {
            kanan = 0;
        }
        if (idx == 1 || a[idx - 1] == 1) {
            kiri = 1;
        } else {
            kiri = 0;
        }
        for (int j = idx; j <= idx + len - 1; j++) {
            a[j] = kiri;
        }
        for (int j = idx + len; j <= idx + 2 * len - 1; j++) {
            a[j] = kanan;
        }
    }
    cout << ans << "\n";
    for (int i = 1; i <= n; i++) {
        printf("%d ", a[i]);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x = 0, f = 1; char ch = getchar();
	while(!isdigit(ch)) (ch == '-') && (f = -1), ch = getchar();
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return x * f;
}
#define N 500005
int n, a[N], g, ans;
int main(){
//	freopen("median.in", "r", stdin);
//	freopen("median.out", "w", stdout);
	n = read();
	for(int i = 1; i <= n; i++){
		a[i] = read();
	}
	a[0] = a[1], a[n + 1] = a[n];
	for(int i = 1; i <= n; i++){
		if(a[i - 1] != a[i] && a[i] != a[i + 1]) g++;
		else {
			ans = max(ans, (g + 1) / 2);
			if(g & 1){
				while(g){
					a[i - g] = a[i];
					g--;
				}
			}
			else {
				int t = i - g - 1;
				while(g){
					if(g > (i - t - 1) / 2)a[i - g] = a[t];
					else a[i - g] = a[i];
					g--;
				}
			}
			g = 0;
		}
	}
	printf("%d\n", ans);
	for(int i = 1; i <= n; i++) printf("%d ", a[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x = 0, f = 1; char ch = getchar();
	while(!isdigit(ch)) (ch == '-') && (f = -1), ch = getchar();
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return x * f;
}
#define N 500005
int n, a[N], g, ans;
int main(){
	//freopen("median.in", "r", stdin);
	//freopen("median.out", "w", stdout);
	n = read();
	for(int i = 1; i <= n; i++){
		a[i] = read();
	}
	a[0] = a[1], a[n + 1] = a[n];
	for(int i = 1; i <= n; i++){
		if(a[i - 1] != a[i] && a[i] != a[i + 1]) g++;
		else {
			ans = max(ans, (g + 1) / 2);
			if(g & 1){
				while(g){
					a[i - g] = a[i];
					g--;
				}
			}
			else {
				int t = i - g - 1;
				while(g){
					if(g > (i - t - 1) / 2)a[i - g] = a[t];
					else a[i - g] = a[i];
					g--;
				}
			}
			g = 0;
		}
	}
	printf("%d\n", ans);
	for(int i = 1; i <= n; i++) printf("%d ", a[i]);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<ctime>
#include<cstdlib>
using namespace std;
#define MAXN 500001
clock_t st,ed;
int n;
int a[MAXN];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	int ans=0;
	int ansm=0;
	int combo=0;
	for(int i=2;i<n;i++){
		if(a[i]!=a[i-1]&&a[i]!=a[i+1]){
			int l=i;
			bool ll=a[i-1];
			int r=i;
			bool rr=a[i+1];
			for(r;r<=n;r++){
				if(a[r]==a[r+1]||r==n)break;
			}
			rr=a[r];
			if(r-l==1)ansm=max(ansm,1);
			else if(rr==ll)ansm=max(ansm,(r-l+1)/2);
			else
			ansm=max(ansm,(r-l)/2);
			r--;
			if((r-l)%2==0){
				for(int j=l;j<=r;j++){
					a[j]=ll;
				}
			}
			else{
				for(int j=0;l+j<=r-j;j++){
					a[l+j]=ll;
					a[r-j]=rr;
				}
			}
			i=r;
		}
	}
	printf("%d\n",ansm);
	for(int i=1;i<=n;i++){
		printf("%d ",a[i]);
	}
}


#include<bits/stdc++.h>
using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
template<class T> void read(T&num) {
    char CH; bool F=false;
    for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
    for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
    F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
    if(!p) { puts("0"); return; }
    while(p) stk[++ tp] = p%10, p/=10;
    while(tp) putchar(stk[tp--] + '0');
    putchar('\n');
}

const LL mod=1e9+7;
const double PI=acos(-1.0);
const LL inf=1e14;
const int N=5e5+15;
int n,a[N],p[N],nex[N];
int fun(int l,int r)
{
    if(a[r]==a[l])
    {
        for(int i=l;i<=r;i++)a[i]=a[l];
    }
    else
    {
        for(int i=l;i<=l+(r-l)/2;i++)a[i]=a[l];
        for(int i=l+(r-l)/2+1;i<=r;i++)a[i]=a[r];
    }
        return (r-l)/2;
}
int main()
{
    read(n);
    Riep(n)read(a[i]),p[i]=nex[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(a[i]==a[i-1])p[i]=p[i-1],nex[p[i]]=i;
    }
    int l=nex[1],r=n;
    int ans=0;
    for(int i=nex[1]+1;i<n;i++)
    {
        if(nex[i]!=i)
        {
            r=i;
            ans=max(ans,fun(l,r));
            i=nex[i];
            l=i;
        }
    }
    r=p[n];
    ans=max(ans,fun(l,r));
    cout<<ans<<"\n";
    Riep(n)printf("%d ",a[i]);
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,k,ans,maxn,a[500001],b,c;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
	    cin>>a[i];
	    if(i>2&&(a[i-1]<a[i-2]&&a[i-1]<a[i]||a[i-1]>a[i-2]&&a[i-1]>a[i]))
		ans++;
	    else ans=0;
	    maxn=max(maxn,ans);
	}
    maxn=ceil(maxn/2.0);
    cout<<maxn<<endl;
    for(int i=1;i<=maxn;i++)
    {
    	b=a[1];
    	for(int j=2;j<n;j++)
    	{
    		c=a[j];
    		if(a[j]<b&&a[j]<a[j+1])
    		a[j]=min(a[j+1],b);
    		else if(a[j]>b&&a[j]>a[j+1])
    		a[j]=max(a[j+1],b);
    		b=c;
		}
	}
	for(int i=1;i<=n;i++)
	cout<<a[i]<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[500001],b[500001],c[500001],d,m,n,ans=0,p=0;
#define reg register
inline int read() {
	reg int s = 0, t = 0; reg char ch = getchar();
	while(ch > '9' || ch < '0') t |= ch == '-', ch = getchar();
	while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
	return t ? -s : s;
}

inline void print(reg long long x) {
	if(x < 0) putchar('-'), x = -x;
	if(x > 9) print(x / 10);
	putchar(x % 10 + 48);
}

int main()
{
	m=read();
	for(int i=1;i<=m;i++)
	a[i]=read();
	a[m+1]=a[m];a[0]=a[1];
	for(int i=m;i>=0;i--)
	{
	   if(a[i]!=a[i+1])p++;
	   else
	   {
	      p--;
	   	  if(p<0)p=0;
	   	  ans=max(ans,(p+1)/2);
		  b[i+2]=p;
		  p=0;

	   }

	}
	printf("%d\n",ans);
	for(int i=1;i<=m;)
	{
		if(b[i]==0){printf("%d ",a[i]);i++;}
		else
		{
			  for(int j=i,k=1;j<i+b[i],k<=b[i];j--,k++)
			  {
			  	 if(b[i]%2==1)printf("%d ",a[i-1]);
			  	 else
			  	 {
			  	 	if(k<=b[i]/2)printf("%d ",a[i-1]);
			  	 	else printf("%d ",a[i+b[i]]);
			  	 }
			  }
			  i+=b[i];
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll read(){
    ll sum=0;char ch=getchar();
    while(!(ch>='0'&&ch<='9'))ch=getchar();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=getchar();
    return sum;
}
ll n,a[500010],t,each,tot,l,maxn,res,k,book[500010],len[500010];
int main(){
	n=read();
	book[1]=1;book[n]=1;
	for(ll i=1;i<=n;i++) a[i]=read();
	for(ll i=2;i<n;i++)
		if(a[i]==a[i-1]||a[i]==a[i+1])
			book[i]++;
	for(ll i=1;i<=n;i++)
		if(book[i]==0) tot++;
		else{
			len[i]=tot;
			maxn=max(tot,maxn);
			tot=0;
		}
	for(ll i=n;i>=1;i--){
		if(!book[i]){
			len[i]=t;
			t+=each;
			if(t>(tot-1)/2+1){
				if(tot%2) each=-1,t-=2;//奇数
				else each=-1,t--; //偶数
			}
		}
		else{
			tot=len[i];
			each=1;
			t=1;
		}
	}
	res=(maxn-1)/2+1;
	if(maxn==0) res=0;
	printf("%lld\n",res);
	for(ll i=1;i<=n;i++)
		if(book[i]==1) printf("%lld ",a[i]);
		else{
			if(len[i]%2==0) printf("%lld ",a[i]);
			else printf("%lld ",abs(a[i]-1));
		}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int n,a[500001];
int main()
{
	cin>>n;
	for (int i=0;i<n;i++) cin>>a[i];
	int minn=0,l=-1,r=-1;
	while (l<n&&r<n)
	{
		for (l=r+1;l<n-1;l++)if(a[l]!=a[l+1]) break;
		for (r=l+1;r<n-1;r++)if(a[r]==a[r+1]) break;
		if (r-l+1<3) continue;
		int mid=(l+r)/2;
		for (register int i=l;i<=r;i++)a[i]=i<=mid?a[l]:a[r];
		minn=max(minn,(r-l)/2);
	}
	cout<<minn<<endl;
	for (register int i=0;i<n;i++) cout<<a[i]<<" ";
	cout<<"\n";
	return 0;
}


#include <stdio.h>
int main()
{
    int i,j,n,m;
    scanf("%d",&n);
    int a[n];
    for(i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(j=1;j<=n+1;j++){
        for(i=1;i<=n;i++){
            if(a[i]==j){m=a[i];
                      break;}
        }
        if(m==j)continue;
        else {printf("%d",j);
              break;
    }
    }
    return 0;
}


#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int comp(const void *a, const void *b){
	const int *da = (const int*)a;
	const int *db = (const int*)b;
	return *da - *db;
}

int main(void) {
    int n;
    scanf("%d",&n);
    int arr[n];
    int i;
    for(i=0;i<n;i++){
        scanf("%d",&arr[i]);
    }
    qsort(arr,n,sizeof(int),comp);
    for(i=0;i<n;i++){
        if(arr[i] != i+1)
            break;
    }
    printf("%d",i+1);
    return 0;
}


#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(void) {
    int n;
    scanf("%d",&n);
    int arr[n];
    int i;
    for(i=0;i<n;i++){
        scanf("%d",&arr[i]);
    }
    qsort(arr,n,sizeof(int),comp);
    for(i=0;i<n;i++){
        if(arr[i] != i+1)
            break;
    }
    printf("%d",i+1);
    return 0;
}


#include <stdio.h >
#include <string.h>
int main()
{
    int n,a[3010],i;
    int mark[3010];
    memset(mark,0,sizeof(mark));
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        mark[a[i]]=1;
    }
    for(i=1;i<3010;i++)
    {
        if(mark[i]==0)
        {
            printf("%d\n",i);
            return 0;
        }
    }
    return 0;
}


#include <stdio.h >
#include <string.h>
int main()
{
    int n,a[3001],i;
    int mark[3001];
    memset(mark,0,sizeof(mark));
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        mark[i]=1;
    }
    for(i=0;i<3001;i++)
    {
        if(a[i]==0)
        {
            printf("%d\n",i);
            return 0;
        }
    }
    return 0;
}


#include <stdio.h >
#include <string.h>
int main()
{
	int n,a[3001],i;
	int mark[3001];
	memset(mark,0,sizeof(mark));
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		mark[a[i]]=1;
	}
	for(i=1;i<3001;i++)
	{
		if(mark[i]==0)
		{
			printf("%d\n",i);
			return 0;
		}
	}
	return 0;
}


#include <stdio.h >
#include <string.h>
int main()
{
    int n,a[3005],i;
    int mark[3005];
    memset(mark,0,sizeof(mark));
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        mark[a[i]]=1;
    }
    for(i=1;i<3001;i++)
    {
        if(mark[i]==0)
        {
            printf("%d\n",i);
            return 0;
        }
    }
    return 0;
}


#include <stdio.h>
#include<process.h>
int main(void)
{
    int i,n,x;
    scanf("%d",&n);
    int arr[10000]={0};
    for(i=0;i<n;i++){
        scanf("%d",&x);
        arr[x]=1;}i=1;
while(1){
if(arr[i]==0){ printf("%d",i);
    exit(0);}i++;}
return 0;}


#include <stdio.h>
#include<process.h>
int main(void)
{
    int i,n,x;
    scanf("%d",&n);
    int arr[3001]={0};
    for(i=0;i<n;i++){
        scanf("%d",&x);
        arr[x]=1;}i=1;
while(1){
if(arr[i]==0){ printf("%d",i);
    exit(0);}i++;}
return 0;}


#include <stdio.h>
main()
{
	int i,j,x,temp,count=0;
	scanf("%d",&x);
	int a[x];
	for (i=0;i<x;i++)
	{
		scanf("%d",&a[i]);
		if (i==0)
		temp=a[i];
		else if (a[i]>temp&&i!=0)
		temp=a[i];
	}
	//printf("temp=%d\n",temp);
	for (i=1;i<=temp;i++)
	{
		count=0;
		for (j=0;j<x;j++)
		{
			if (i==a[j])
			count++;
		}
		if (count==0)
		{
			printf("%d\n",i);
			return 0;
		}
	}
	//printf("i=%d\n",i);
	if  (i-1==temp)
	printf("%d\n",temp+1);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int comp(const void *a, const void *b) {
    return *((int*)a) - *((int*)b);
}

int main () {
    int n, i, vet[3001], flag=0;
    scanf("%d",&n);
    for (i=0; i<n; i++)
        scanf("%d",vet+i);
    qsort(vet,n,sizeof(int),comp);
    if (vet[0] != 1)
        printf("1\n");
    else {
        for (i=1; i<n; i++) {
            if (vet[i] != vet[i-1]+1) {
                flag=1;
                printf("%d\n",vet[i-1]+1);
                break;
            }
        }
        if(!flag)
            printf("%d\n",n+1);
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int comp(const void *a, const void *b) {
	return *((int*)a) - *((int*)b);
}

int main () {
	int n, i, vet[3001], flag=0;
	scanf("%d",&n);
	for (i=0; i<n; i++)
		scanf("%d",vet+i);
	qsort(vet,n,sizeof(int),comp);
	if (vet[0] != 1)
		printf("1\n");
	else {
		for (i=1; i<n; i++) {
			if (vet[i] != vet[i-1]+1) {
				flag=1;
				printf("%d\n",vet[i-1]+1);
			}
		}
		if(!flag)
			printf("%d\n",n+1);
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i,j,x=0;
    int compare=0,res=0;
    scanf("%d",&n);
    int array1[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&array1[i]);
    }

    for(i=0;i<n;i++) {
for(j=i+1;j<n;j++) {
if(array1[i]>array1[j]) {
x=array1[i];
array1[i]=array1[j];
array1[j]=x;
}
}
}
if(array1[0]!=1)
{
    printf("1");
    return 0;
}

for(i=0;i<n;i++)
{
    compare =(array1[i]+1);
    if(compare!=array1[i+1]&&i!=n-1)
    {
        res=(array1[i]+1);
        printf("%d",res);
        return 0;
    }
}

 res=array1[n-1]+1;
printf("%d",res);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i,j,x=0;
    int compare=0,res=0;
    scanf("%d",&n);
    int array1[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&array1[i]);
    }

    for(i=0;i<n;i++) {
for(j=i+1;j<n;j++) {
if(array1[i]>array1[j]) {
x=array1[i];
array1[i]=array1[j];
array1[j]=x;
}
}
}
for(i=0;i<n;i++)
{
    compare =(array1[i]+1);
    if(compare!=array1[i+1]&&i!=n-1)
    {
        res=(array1[i]+1);
        printf("%d",res);
        return 0;
    }
}
 res=array1[n-1]+1;
printf("%d",res);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i,j,x=0;
    scanf("%d",&n);
    int array1[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&array1[i]);
    }

    for(i=0;i<12;i++) {
for(j=i+1;j<12;j++) {
if(array1[i]>array1[j]) {
x=array1[i];
array1[i]=array1[j];
array1[j]=x;
}
}
}
for(i=0;i<n;i++)
{

    if(array1[i]+1!=array1[i+1])
    {
        printf("%d",array1[i]+1);
        break;
    }
}

    return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
    int i;
    int n;
    int tmp;
    int a[3005];
    memset(a, 0, sizeof(a));
    scanf("%d", &n);
    for ( i = 0; i < n; i++ )
    {
        scanf("%d", &tmp);
        a[tmp] = 1;
    }
    for ( i = 1; i <= 3000; i++ )
    {
        if ( !a[i] )
        {
            printf("%d\n", i);
            return 0;
        }
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
    int i;
    int n;
    int tmp;
    int a[3005];
    memset(a, 0, sizeof(a));
    scanf("%d", &n);
    for ( i = 0; i < n; i++ )
    {
        scanf("%d", &tmp);
        a[tmp] = 1;
    }
    for ( i = 1; i < 3005; i++ )
    {
        if ( !a[i] )
        {
            printf("%d\n", i);
            return 0;
        }
    }
    return 0;
}


#include <stdio.h>

int main()
{
	int n,i,ans;
	scanf("%d",&n);
	int arr[3002]={0};
	while (n>0)
	{
		int num;
		scanf("%d",&num);
		arr[num]++;
		n--;
	}
	for (i=1;i<=3000;i++)
	{
		if (arr[i]==0)
		{
			ans=i;
			break;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include <stdio.h>

int main()
{
	int n,i,ans=0;
	scanf("%d",&n);
	int arr[3002]={0};
	while (n>0)
	{
		int num;
		scanf("%d",&num);
		arr[num]++;
		n--;
	}
	for (i=1;i<=3001;i++)
	{
		if (arr[i]==0)
		{
			ans=i;
			break;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include<stdio.h>

int main()
{
    int i,j,n,flag=0;
    scanf("%d",&n);
    int test[n];

    for(i=0;i<n;i++)
    {
        scanf("%d",&test[i]);
    }

    for(i=1;i<=n;i++)
    {
        flag=0;
        for(j=0;j<n;j++)
        {
            if(i==test[j])
            {
                flag=1;
            }
        }
        if(flag==0)
        {
            break;
        }
    }
    printf("%d",i);

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main() {
	short n[3005]={0},i,l,z;

	scanf("%hd",&l);

	for(z=1;z<=l;z++)
	{
		scanf("%hd",&i);
		n[i]=5;
	}

	for(z=1;z<=3000;z++)
	{
		if(n[z]==5)
		{
			//printf("%hd",z);
		}
		else if(n[z]!=5)
		{
			printf("%hd",z);
			break;
		}
	}

	return 0;
}


#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main() {
	short n[30000]={0},i,l,z,max=0;

	scanf("%hd",&l);

	for(z=1;z<=l;z++)
	{
		scanf("%hd",&i);
		n[i]=5;

		if(i>max)
		max=i;
	}

	for(z=1;z<=max;z++)
	{
		if(n[z]==5)
		{
			//printf("%hd",z);
		}
		else if(n[z]!=5)
		{
			printf("%hd",z);
			break;
		}
	}

	return 0;
}


#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main() {
	short n[30000]={0},i,l,z,max=0;

	scanf("%hd",&l);

	for(z=1;z<=l;z++)
	{
		scanf("%hd",&i);
		n[i]=5;

//		if(i>max)
//		   max=i;
	}

	for(z=1;z<=3010;z++)
	{
		//printf("Hey");
		if(n[z]==5)
		{
			//printf("%hd",z);
		}
		else if(n[z]!=5)
		{
			printf("%d",z);
			break;
		}
	}

	return 0;
}


#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main() {
	int n[30000]={0},i,l,z;

	scanf("%d",&l);

	for(z=1;z<=l;z++)
	{
		scanf("%d",&i);
		n[i]=5;
	}

	for(z=1;z<=3000;z++)
	{
		if(n[z]==5)
		{
			//printf("%hd",z);
		}
		else if(n[z]!=5)
		{
			printf("%d",z);
			break;
		}
	}

	return 0;
}


#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main() {
	short n[30000]={0},i,l,z,max=0;

	scanf("%hd",&l);

	for(z=1;z<=l;z++)
	{
		scanf("%hd",&i);
		n[i]=5;

	}

	for(z=1;z<=3003;z++)
	{
		if(n[z]==5)
		{

		}
		else if(n[z]!=5)
		{
			printf("%hd",z);
			break;
		}
	}

	return 0;
}


#include<stdio.h>

int main()
{
	int n, arr[3005]={0}, temp, i;
	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%d", &temp);
		arr[temp]++;
	}
	for(i=1;i<3005;i++){
		if(arr[i]==0)
			break;
	}
	printf("%d", i);
	return 0;
}


#include<stdio.h>

int main()
{
	int n, arr[3005]={0}, temp, i;
	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%d", &temp);
		arr[temp]++;
	}
	for(i=1;i<3000;i++){
		if(arr[i]==0)
			break;
	}
	printf("%d", i);
	return 0;
}


#include<stdio.h>
int main()
{
    int ara[10000];
    int i,k;
    int c[10000]={0};
    int n;
    scanf("%d",&n);

        for(i=0;i<n;i++)
    {
        scanf("%d",&ara[i]);
        c[ara[i]]=1;
    }
    for(i=1;;i++)
    {
        if(c[i]!=1)
        {
            printf("%d\n",i);
            break;
        }
    }

    return 0;
}


#include<stdio.h>
int main()
{
    int ara[100];
    int i;
    int c[100];
    int n;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&ara[i]);
        c[i]=1;
    }
    for(i=0;i<3000;i++)
    {
        if(c[i]!=1)
        {
            printf("%d\n",i);
            break;
        }
    }
    return 0;
}


#include<stdio.h>

void selectionSort(int a[], int n);
int main()
{
    int n, win[3001], i;
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%d", &win[i]);
    }
    selectionSort(win, n);
    /*for(i=0; i<n; i++){
        printf("%d", win[i]);
    }*/
    for(i=0; i<n; i++){
        if(win[i]!=i+1){
            printf("%d", i+1);
            return 0;
        }
    }

}

void selectionSort(int a[], int n){
    int min, idx, i, t, j;
    for(j=0; j<n-1; j++){
        idx = j;
        min = a[j];
        for(i=j+1; i<n; i++){
            if(min>a[i]){
                min = a[i];
                idx= i;
            }
        }
        t = a[j];
        a[j] = a[idx];
        a[idx] = t;

    }
}


#include<stdio.h>

void selectionSort(int a[], int n);
int main()
{
    int n, win[3001], i;
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%d", &win[i]);
    }
    selectionSort(win, n);
    /*for(i=0; i<n; i++){
        printf("%d", win[i]);
    }*/
    for(i=0; i<n; i++){
        if(win[i]!=i+1){
            printf("%d", i+1);
            return 0;
        }
    }
    printf("%d", i+1);
    return 0;

}

void selectionSort(int a[], int n){
    int min, idx, i, t, j;
    for(j=0; j<n-1; j++){
        idx = j;
        min = a[j];
        for(i=j+1; i<n; i++){
            if(min>a[i]){
                min = a[i];
                idx= i;
            }
        }
        t = a[j];
        a[j] = a[idx];
        a[idx] = t;

    }
}


#include<stdio.h>
#include<string.h>
int main()
{
int n,i,min=3000,t;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
{if(i==0)
scanf("%d",&a[i]);
else
{scanf("%d",&a[i]);
if(a[i]==t)
t++;}
if(a[i]<=min)
{min=a[i];
t=min+1;}}
printf("%d",t);
return(0);
}


#include<stdio.h>
int n,dl,a[3006];
int main()
{
	scanf("%d",&n);
	register int i;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&dl);
		a[dl]=1;
	}
	for(i=1;;i++) if(!a[i]) {printf("%d\n",i);return 0;}
	return 0;
}


#include <stdio.h>

int main(void)
{
	int n,i,g,mini,max,f;
	scanf("%d",&n);
	int ara[100000];
	for (i=0;i<n;i++){
		scanf("%d",&ara[i]);
	}
	mini=ara[0];
	for (i=0;i<n;i++){
		if (ara[i]<mini){
			mini=ara[i];
		}
	}
	max=ara[0];
	for (i=0;i<n;i++){
		if (ara[i]>max){
			max=ara[i];
		}
	}
	if (mini!=1){
		printf("1");
	}
	else{
		g=mini+1;
		while (g!=max){
		f=0;
		for(i=0;i<n;i++){

			if (g==ara[i]){
				f=1;
				break;
			}

		}
		if(f==0){
			printf("%d",g);
			break;
		}
		else{
			g=g+1;
		}

	}
	if (g==max){
		printf("%d",g+1);
	}
	}
	return 0;
}


#include <stdio.h>

int main(void)
{
	int n,i,g,mini,max,f;
	scanf("%d",&n);
	int ara[100000];
	for (i=0;i<n;i++){
		scanf("%d",&ara[i]);
	}
	mini=ara[0];
	for (i=0;i<n;i++){
		if (ara[i]<mini){
			mini=ara[i];
		}
	}
	max=ara[0];
	for (i=0;i<n;i++){
		if (ara[i]>max){
			max=ara[i];
		}
	}
	if (mini!=1){
		printf("1");
	}
	else{
		g=mini+1;
		while (g!=max){
		f=0;
		for(i=0;i<n;i++){

			if (g==ara[i]){
				f=1;
				break;
			}

		}
		if(f==0){
			printf("%d",g);
			break;
		}
		else{
			g=g+1;
		}

	}
	}
	return 0;
}


#include<stdio.h>
int main()
{
    int i,n,a[5000],x=1,flag,y,z;
    scanf("%d",&n);
    for(i=1;i<=n;i++) {
        scanf("%d",&a[i]);
    }
    while(1){
        flag=1;
        for(i=1;i<=n;i++) {
            if(x==a[i]) {
                flag=0;
                break;
            }
        }
        if(flag==1) {
            printf("%d",x);
            break;
        }
        x++;
    }
    return 0;
}


//In the name of God

#include <stdio.h>

int main()
{
	int n;
	scanf("%d",&n);
	int a[n+10];
	int i;
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int max=a[1],min=a[1];
	for(i=2;i<=n;i++)
		if(a[i]>max)
			max=a[i];
		else if(a[i]<min)
			min=a[i];
	//printf("min=%d\nmax=%d\n",min,max);
	int j;
	for(i=1;i<max;i++)
	{
		//printf("i=%d\n",i);
		if(i<min)
		{
			printf("%d\n",i);
			return 0;
		}
		else
		{
			int k=0;
			for(j=1;j<=n;j++)
				if(a[j]==i)
					k=1;
			//printf("k=%d\n",k);
			if(k==0)
			{
				printf("%d\n",i);
				return 0;
			}
		}
	}
		printf("%d\n",max+1);
	return 0;
}


//In the name of God

#include <stdio.h>

int main()
{
	int n;
	scanf("%d",&n);
	int a[n+10];
	int i;
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int max=a[1],min=a[1];
	for(i=2;i<=n;i++)
		if(a[i]>min)
			max=a[i];
		else if(a[i]<a[min])
			min=a[i];
	//printf("min=%d\nmax=%d\n",min,max);
	int j;
	for(i=1;a[i]<max;i++)
		if(i<min)
		{
			printf("%d\n",i);
			return 0;
		}
		else
		{
			int k=0;
			for(j=1;j<=n;j++)
				if(a[j]==i)
					k=1;
			if(k==0)
			{
				printf("%d\n",i);
				return 0;
			}
		}
		printf("%d\n",max+1);
	return 0;
}


//In the name of God

#include <stdio.h>

int main()
{
	int n;
	scanf("%d",&n);
	int a[n+10];
	int i;
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int max=a[1],min=a[1];
	for(i=2;i<=n;i++)
		if(a[i]>min)
			max=a[i];
		else if(a[i]<a[min])
			min=a[i];
	printf("min=%d\nmax=%d\n",min,max);
	int j;
	for(i=1;a[i]<max;i++)
		if(i<min)
		{
			printf("%d\n",i);
			return 0;
		}
		else
		{
			int k=0;
			for(j=1;j<=n;j++)
				if(a[j]==i)
					k=1;
			if(k==0)
			{
				printf("%d\n",i);
				return 0;
			}
		}
		printf("%d\n",max+1);
	return 0;
}


//In the name of God

#include <stdio.h>

int main()
{
	int n;
	scanf("%d",&n);
	int a[n+10];
	int i;
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int max=a[1],min=a[1];
	for(i=2;i<=n;i++)
		if(a[i]>min)
			max=a[i];
		else if(a[i]<a[min])
			min=a[i];
	int j;
	for(i=1;a[i]<max;i++)
		if(a[i]<min)
		{
			printf("%d\n",a[i]);
			return 0;
		}
		else
		{
			int k=0;
			for(j=1;j<=n;j++)
				if(a[j]==i)
					k=1;
			if(k==0)
			{
				printf("%d\n",a[i]);
				return 0;
			}
		}
		printf("%d\n",max+1);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main(void)
{
   int n,k,i;
   scanf("%d",&n);
    int ara[n];
    int myAra[3000];
    for(i=0;i<n;i++)
    {

        scanf("%d",&ara[i]);
    }

    for(i=0;i<n;i++)
    {
        myAra[ara[i]]=1;

    }
        for(k=1;k<=3000;k++)
        { if(myAra[k]!=1){
            break;
      }

    }
    printf("%d",k);
    return 0;
}


#include<stdio.h>
int main()
{
    int n,i,j,k,l,flag=0;
    scanf("%d",&n);
    int arr[n],arr1[n];
    for(i=0;i<n;i++)
    scanf("%d",&arr[i]);
    for(i=0;i<n-1;i++)
    {
        for(j=0;j<n-1;j++)
        {
            if(arr[j]>arr[j+1])
            {
                l=arr[j];
                arr[j]=arr[j+1];
                arr[j+1]=l;
            }
        }

    }
    k=1;
    for(i=1;i<n;i++)
    {
        if(arr[0]==1)
        {
            if(arr[i]==k+1)
            k=arr[i];
            flag=1;
        }
        else
        break;
    }
    if(flag==1)
    printf("%d",k+1);
    else
    printf("1");
}


#include<stdio.h>
int main()
{
	int n,i,j,k,l,flag=0;
	scanf("%d",&n);
	int arr[n],arr1[n];
	for(i=0;i<n;i++)
	scanf("%d",&arr[i]);
	for(i=0;i<n-1;i++)
	{
		for(j=0;j<n-1;j++)
		{
			if(arr[j]>arr[j+1])
			{
				l=arr[j];
				arr[j]=arr[j+1];
				arr[j+1]=l;
			}
		}

	}
	k=1;
	for(i=0;i<n;i++)
	{
		if(arr[0]==1)
		{
			if(arr[i]==k+1)
			k=arr[i];
			flag=1;
		}
		else
		break;
	}
	if(flag==1)
	printf("%d",k+1);
	else
	printf("1");
}


#include<stdio.h>
int main()
{
	int n,i,j,k,p,l,flag=0;
	scanf("%d",&n);
	int arr[n],arr1[n];
	for(i=0;i<n;i++)
	scanf("%d",&arr[i]);
	for(i=0;i<n-1;i++)
	{
		for(j=0;j<n-1;j++)
		{
			if(arr[j]>arr[j+1])
			{
				l=arr[j];
				arr[j]=arr[j+1];
				arr[j+1]=l;
			}
		}

	}
	k=1;
	for(i=0;i<n;i++)
	{
		if(arr[0]==1)
		{
			if(arr[i]==k+1)
			k=arr[i];
			flag=1;
		}
		else
		break;
	}
	if(flag==1)
	printf("%d",k+1);
	else
	printf("1");
}


#include<stdio.h>

int hash[4000];

int main()
{
    int n,got,i;
    scanf("%d",&n);
    hash[0]=1;
    for(i=0;i<n;i++)
    {
        scanf("%d",&got);
        hash[got]=1;
    }
    for(i=0;i<=n;i++)
    {
        if(hash[i]==0)
        {
            printf("%d\n",i);
            break;
        }
    }
    return(0);
}


#include<stdio.h>

int hash[4000];

int main()
{
    int n,got,i;
    scanf("%d",&n);
    hash[0]=1;
    for(i=0;i<n;i++)
    {
        scanf("%d",&got);
        hash[got]=1;
    }
    for(i=0;i<=n+1;i++)
    {
        if(hash[i]==0)
        {
            printf("%d\n",i);
            break;
        }
    }
    return(0);
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int s(const void*b , const void*a)
{
    return *(int*)a - *(int*)b ;
}

int main()
{
    int n , i ,min = 1 ;
    scanf("%d",&n);
    int a[n] ;
    for(i=0 ; i<n ; i++)
    {
        scanf("%d",&a[i]);
        if(min > a[i])min = a[i] ;
    }
    qsort(a,n,sizeof(int),s);

    for(i=n-1 ; i>=0 ; i--)
    {
        if(min != a[i])
        {
            printf("%d",min);
            return 0 ;
        }
        else min++ ;

    }
    printf("%d",min);

    return 0 ;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int s(const void*b , const void*a)
{
    return *(int*)a - *(int*)b ;
}

int main()
{
    int n , i ,min = 40000 ;
    scanf("%d",&n);
    int a[n] ;
    for(i=0 ; i<n ; i++)
    {
        scanf("%d",&a[i]);
        if(min > a[i])min = a[i] ;
    }
    qsort(a,n,sizeof(int),s);
    if(n==1)
    {
        printf("%d",a[0]+1);
        return 0 ;
    }

    min++ ;
    for(i=n-2 ; i>=0 ; i--)
    {
        //printf("%d\n",min);
        if(min != a[i])
        {
            printf("%d",min);
            return 0 ;
        }
        else min++ ;

    }
    printf("%d",min);

    return 0 ;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int s(const void*b , const void*a)
{
    return *(int*)a - *(int*)b ;
}

int main()
{
    int n , i ,min = 40000 ;
    scanf("%d",&n);
    int a[n] ;
    for(i=0 ; i<n ; i++)
    {
        scanf("%d",&a[i]);
        if(min > a[i])min = a[i] ;
    }
    qsort(a,n,sizeof(int),s);
    if(n==1)
    {
        printf("%d",a[0]+1);
        return 0 ;
    }

    min++ ;
    for(i=n-2 ; i>=0 ; i--)
    {
        //printf("%d\n",min);
        if(min != a[i])
        {
            printf("%d",min);
            return 0 ;
        }
        else min++ ;

    }

    return 0 ;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int s(const void*b , const void*a)
{
    return *(int*)a - *(int*)b ;
}

int main()
{
    int n , i ,min = 1 ;
    scanf("%d",&n);
    int a[n] ;
    for(i=0 ; i<n ; i++)
    {
        scanf("%d",&a[i]);
        if(min > a[i])min = a[i] ;
    }
    qsort(a,n,sizeof(int),s);
    if(n==1)
    {
        printf("%d",a[0]+1);
        return 0 ;
    }

    for(i=n-1 ; i>=0 ; i--)
    {
        //printf("%d\n",min);
        if(min != a[i])
        {
            printf("%d",min);
            return 0 ;
        }
        else min++ ;

    }
    printf("%d",min);

    return 0 ;
}


#include<stdio.h>
int a[3500];
int main()
{
    int n,i,b;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&b);
        a[b]=1;
    }
    for(i=1;;i++){
        if(!a[i]){
            printf("%d",i);
            return 0;
        }
    }
}


#include<stdio.h>
int main()
{
int n,a[3001],i,small=3001;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
if(a[i]<small)
small=a[i];
}
printf("\n%d",small+1);
return(0);
}


#include<stdio.h>
#include<stdlib.h>

int main()
{
	int num;

	scanf("%d",&num);

	int *test = malloc(num * sizeof(int));

	int i;

	for(i = 0; i <= num-1; i++)
		scanf("%d",test+i);
	i = 0;
	while(i <= num)
	{
		if(*(test+i) == 1)
			break;
		else if(i == num-1)
		{
			printf("1");
			return 0;
		}
		i++;
	}

	int n = 0;
	i = 1;

	while(*(test+n) != i)
	{
		n += 1;
		if(n == num)
		{
			i += 1;
			n = 0;
		}
	}

	n = 0;
	int j = 1;

	while(n != num)
	{
		if(*(test+n) == i+j)
		{
			j++;
			n = 0;
		}
		n++;
	}

	printf("%d",i+j);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main()
{
	int num;

	scanf("%d",&num);

	int *test = malloc(num * sizeof(int));

	int i;

	for(i = 0; i <= num-1; i++)
		scanf("%d",test+i);
	i = 0;
	while(i <= num)
	{
		if(*(test+i) == 1)
			break;
		else if(i == num-1)
		{
			printf("1");
			return 0;
		}
		i++;
	}

	int n = 0;
	i = 2;

	while(n <= num)
	{
		if(*(test+n) == i)
		{
			i++;
			n = 0;
			continue;
		}

		n += 1;
	}
	printf("%d",i);
}


#include<stdio.h>
#include<stdlib.h>

int main()
{
	int num;

	scanf("%d",&num);

	int *test = malloc(num * sizeof(int));

	int i;

	for(i = 0; i <= num-1; i++)
		scanf("%d",test+i);

	int n = 0;
	i = 1;

	while(*(test+n) != i)
	{
		n += 1;
		if(n == num)
		{
			i += 1;
			n = 0;
		}
	}

	n = 0;
	int j = 1;

	while(n != num)
	{
		if(*(test+n) == i+j)
		{
			j++;
			n = 0;
		}
		n++;
	}

	printf("%d",i+j);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main()
{
	int num;

	scanf("%d",&num);

	int *test = malloc(num * sizeof(int));

	int i;

	for(i = 0; i <= num-1; i++)
		scanf("%d",test+i);
	i = 0;
	while(i <= num)
	{
		if(*(test+i) == 1)
			break;
		else if(i == num-1)
		{
			printf("1");
			return 0;
		}
		i++;
	}

	int n = 0;
	i = 2;

	while(n <= num)
	{
		if(*(test+n) == i)
		{
			i++;
			n = 0;
			continue;
		}

		n += 1;
	}
	printf("%d",i);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
int search (int a[] , int keyer , int size);
int main()
{
    int i = 0 , key = 0 , a[3500] = {0} , n = 0 , holder = 0 , flag = 1;
    scanf("%d" , &n);
    for (i = 0 ; i < n ; i++){
        scanf("%d" , &a[i]);
    }
    for (i = 0 ; i < n - 1 ; i++){
        if (a[i] > a[i+1]){
            holder = a[i] ;
            a[i] = a[i+1];
            a[i+1] = holder ;
        }
    }

    for (i = 0 ; i < n ;i++){
        key = a[i] ;
       flag =  search (a , key + 1 , n) ;
       if (flag == 0){
            return 0 ;
       }
       else {
        continue ;
       }
    }
    return 0;
}
int search (int a[] , int keyer , int size) {
    int i = 0 ;
    for (i = 0 ; i < size  ; i++){
        if (a[i] == keyer){
            return 1 ;
        }
    }
    printf("%d" , keyer);
    return 0 ;
}


#include <stdio.h>
#include <stdlib.h>
int search (int a[] , int keyer , int size);
int main()
{
    int i = 0 , key = 0 , a[3500] = {0} , n = 0 , holder = 0 , flag = 1;
    scanf("%d" , &n);
    for (i = 0 ; i < n ; i++){
        scanf("%d" , &a[i]);
    }
    if (n == 1 && a[0] == 1 && holder == 0){
        printf("2");
        return 0 ;
    }
    for (i = 0 ; i < n - 1 ; i++){
        if (a[i] > a[i+1]){
            holder = a[i] ;
            a[i] = a[i+1];
            a[i+1] = holder ;
        }
    }

    for (i = 0 ; i < n ;i++){
       flag =  search (a , key + 1 , n) ;
       if (flag == 0){
            return 0 ;
       }
       else {
            key ++ ;
        continue ;
       }
    }
    return 0;
}
int search (int a[] , int keyer , int size) {
    int i = 0 ;
    for (i = 0 ; i < size  ; i++){
        if (a[i] == keyer){
            return 1 ;
        }
    }
    printf("%d" , keyer);
    return 0 ;
}


#include <stdio.h>
#include <stdlib.h>
int search (int a[] , int keyer , int size);
int main()
{
    int i = 0 , key = 0 , a[3200] = {0} , n = 0 , holder = 0 , flag = 1;
    scanf("%d" , &n);
    for (i = 0 ; i < n ; i++){
        scanf("%d" , &a[i]);
    }
    for (i = 0 ; i < n - 1 ; i++){
        if (a[i] > a[i+1]){
            holder = a[i] ;
            a[i] = a[i+1];
            a[i+1] = holder ;
        }
    }

    for (i = 0 ; i < n ;i++){
        key = 0 ;
       flag =  search (a , key + 1 , n) ;
       if (flag == 0){
            return 0 ;
       }
       else {
        continue ;
       }
    }
    return 0;
}
int search (int a[] , int keyer , int size) {
    int i = 0 ;
    for (i = 0 ; i < size  ; i++){
        if (a[i] == keyer){
            return 1 ;
        }
    }
    printf("%d" , keyer);
    return 0 ;
}


#include <stdio.h>
#include <stdlib.h>
int search (int a[] , int keyer , int size);
int main()
{
    int i = 0 , key = 0 , a[3500] = {0} , n = 0 , holder = 0 , flag = 1;
    scanf("%d" , &n);
    for (i = 0 ; i < n ; i++){
        scanf("%d" , &a[i]);
    }
    if (n == 1 && a[0] == 1 && holder == 0){
        printf("2");
        return 0 ;
    }
    for (i = 0 ; i < n - 1 ; i++){
        if (a[i] > a[i+1]){
            holder = a[i] ;
            a[i] = a[i+1];
            a[i+1] = holder ;
        }
    }

    for (i = 0 ; i <= n ;i++){
       flag =  search (a , key + 1 , n) ;
       if (flag == 0){
            return 0 ;
       }
       else {
            key ++ ;
        continue ;
       }
    }
    return 0;
}
int search (int a[] , int keyer , int size) {
    int i = 0 ;
    for (i = 0 ; i < size  ; i++){
        if (a[i] == keyer){
            return 1 ;
        }
    }
    printf("%d" , keyer);
    return 0 ;
}


#include <stdio.h>
#include <stdlib.h>
int search (int a[] , int keyer , int size);
int main()
{
    int i = 0 , key = 0 , a[3500] = {0} , n = 0 , holder = 0 , flag = 1;
    scanf("%d" , &n);
    for (i = 0 ; i < n ; i++){
        scanf("%d" , &a[i]);
    }
    for (i = 0 ; i < n - 1 ; i++){
        if (a[i] > a[i+1]){
            holder = a[i] ;
            a[i] = a[i+1];
            a[i+1] = holder ;
        }
    }

    for (i = 0 ; i < n ;i++){
        key = 0 ;
       flag =  search (a , key + 1 , n) ;
       if (flag == 0){
            return 0 ;
       }
       else {
        continue ;
       }
    }
    return 0;
}
int search (int a[] , int keyer , int size) {
    int i = 0 ;
    for (i = 0 ; i < size  ; i++){
        if (a[i] == keyer){
            return 1 ;
        }
    }
    printf("%d" , keyer);
    return 0 ;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int premier (long n) {
  long d;

  if (n % 2 == 0)
    return (n == 2);
  for (d = 3; d * d <= n; d = d + 2)
    if (n % d == 0)
      return 0;
  return 1;
}

int main()
{
    int i=0,n,j,aux,true=0,cpt,t[3000];
    scanf("%d",&n);
    while(i<n)
    {
        scanf("%d",&t[i]);
        i++;

    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if (t[j]>t[i])
            {
                aux=t[j];
                t[j]=t[i];
                t[i]=aux;
            }
        }
    }

    i=0;
    while(true==0)
    {

        if ((t[i+1]-t[i])!=1)
        {
            true=1;
            printf("%d",t[i]+1);
        }
        ++i;
    }

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int premier (long n) {
  long d;

  if (n % 2 == 0)
    return (n == 2);
  for (d = 3; d * d <= n; d = d + 2)
    if (n % d == 0)
      return 0;
  return 1;
}

int main()
{
    int i=0,n,j,aux,true,cpt,t[3000];
    scanf("%d",&n);
    while(i<n)
    {
        scanf("%d",&t[i]);
        i++;

    }
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
        if (t[j]>t[i])
        {
            aux=t[j];
            t[j]=t[i];
            t[i]=aux;
        }

        i=0;
    while(true==0)
    {

        if ((t[i+1]-t[i])!=1)
            true=1;
        i++;
    }
    printf("%d",t[i-1]+1);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int premier (long n) {
  long d;

  if (n % 2 == 0)
    return (n == 2);
  for (d = 3; d * d <= n; d = d + 2)
    if (n % d == 0)
      return 0;
  return 1;
}

int main()
{
    int i=0,n,j,aux,true=0,cpt,t[3000]={0};
    scanf("%d",&n);
    while(i<n)
    {
        scanf("%d",&t[i]);
        i++;

    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if (t[j]>t[i])
            {
                aux=t[j];
                t[j]=t[i];
                t[i]=aux;
            }
        }
    }
    //for(j=0;j<n;j++)
       // printf("%d  ",t[j]);
if (n!=1)
{
    i=0;
    while((true==0)&&(i<n-1))
    {

        if ((t[i+1]-t[i])!=1)
        {
            true=1;

        }
        //printf("/ %d  ",true);
        ++i;
    }

    if (true==1)
        printf("%d",t[i-1]+1);
    else printf("1");
}
    else if (t[0]==1)
        printf("%d",t[0]+1);
else printf("1");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int premier (long n) {
  long d;

  if (n % 2 == 0)
    return (n == 2);
  for (d = 3; d * d <= n; d = d + 2)
    if (n % d == 0)
      return 0;
  return 1;
}

int main()
{
    int i=0,n,j,aux,true=0,cpt,t[3000]={0};
    scanf("%d",&n);
    while(i<n)
    {
        scanf("%d",&t[i]);
        i++;

    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if (t[j]>t[i])
            {
                aux=t[j];
                t[j]=t[i];
                t[i]=aux;
            }
        }
    }
    //for(j=0;j<n;j++)
       // printf("%d  ",t[j]);

    i=0;
    while((true==0)&&(i<n-1))
    {

        if ((t[i+1]-t[i])!=1)
        {
            true=1;

        }
        //printf("/ %d  ",true);
        ++i;
    }

    if (true==1)
        printf("%d",t[i-1]+1);
    else printf("1");

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int premier (long n) {
  long d;

  if (n % 2 == 0)
    return (n == 2);
  for (d = 3; d * d <= n; d = d + 2)
    if (n % d == 0)
      return 0;
  return 1;
}

int main()
{
    int i=0,n,j,aux,true=0,cpt,t[3000]={0};
    scanf("%d",&n);
    while(i<n)
    {
        scanf("%d",&t[i]);
        i++;

    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if (t[j]>t[i])
            {
                aux=t[j];
                t[j]=t[i];
                t[i]=aux;
            }
        }
    }
    //for(j=0;j<n;j++)
       // printf("%d  ",t[j]);
if (n!=1)
{
    i=0;
    while((true==0)&&(i<n-1))
    {

        if ((t[i+1]-t[i])!=1)
        {
            true=1;

        }
        //printf("/ %d  ",true);
        ++i;
    }

    if (true==1)
        printf("%d",t[i-1]+1);
    else printf("1");
}
    else printf("%d",t[0]);

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int premier (long n) {
  long d;

  if (n % 2 == 0)
    return (n == 2);
  for (d = 3; d * d <= n; d = d + 2)
    if (n % d == 0)
      return 0;
  return 1;
}

int main()
{
    int i=0,n,j,aux,true=0,cpt,t[3000]={0};
    scanf("%d",&n);
    while(i<n)
    {
        scanf("%d",&t[i]);
        i++;

    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if (t[j]>t[i])
            {
                aux=t[j];
                t[j]=t[i];
                t[i]=aux;
            }
        }
    }

    i=0;
    while((true==0)&&(i<n))
    {

        if ((t[i+1]-t[i])!=1)
        {
            true=1;

        }
        ++i;
    }
    if (true==1)
        printf("%d",t[i-1]+1);
    else printf("1");

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int premier (long n) {
  long d;

  if (n % 2 == 0)
    return (n == 2);
  for (d = 3; d * d <= n; d = d + 2)
    if (n % d == 0)
      return 0;
  return 1;
}

int main()
{
    int i=0,n,j,aux,true,cpt,t[3000];
    scanf("%d",&n);
    while(i<n)
    {
        scanf("%d",&t[i]);
        i++;

    }
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
        if (t[j]>t[i])
        {
            aux=t[j];
            t[j]=t[i];
            t[i]=aux;
        }

        i=0;
    while(true==0)
    {

        if (t[i+1]-t[i]!=1)
            true=1;
        i++;
    }
    printf("%d",t[i-1]+1);
    return 0;
}


#include<stdio.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
  sortingg(a,n);
   for(i=0;i<=n;i++)
   {
     if(a[i]!=i+1)
     {
         printf("%d\n",i+1);
         return 0;
     }
   }
}
void sortingg(int *a,int n)
{
    int i,j;
    for(i=0;i<n-1;i++)
    {
        for(j=0;j<n-1;j++)
        {
            if(a[j+1]<a[j])
            {
                int temp;
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
            }
        }
    }
}


#include <stdio.h>

int main()
{
    int n;
    scanf("%d", &n);
    int a[n];
    int i, j;
    int max = a[0];

    for(i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
        if(a[i] > max)
        {
            max = a[i];
        }
    }

    for(j = 1; j <= max+1; j++)
    {
        for(i = 0; i < n; i++)
        {
            if(j == a[i])
                break;
        }
        if(i == n)
            break;
    }

    printf("%d\n", j);
    return 0;
}


#include<stdio.h>
int main()
{
    int n,i,j,x=1,temp;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=1;i<n;++i)
        for(j=0;j<(n-i);++j)
            if(a[j]>a[j+1])
            {
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
            }
    for(i=0;i<n;i++)
    {
            if(a[i]!=x)
            {
                printf("%d",x);
                break;
            }
                else
                    x++;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
void main() {
    vector<int> alpha(26,0);
    long long int n,ans=0,empty=0;
    cin>>n;
    string str;
    cin>>str;

    for(int i=0;i<n;i++){
        alpha[str[i]-'a']+=1;
    }
    for(int i=0;i<alpha.size();i++){
        if(!alpha[i]){
            empty+=1;
        }
    }
    for(int i=0;i<alpha.size();i++){
        if(alpha[i]>1){
            if(alpha[i]-1<=empty && empty){
                empty=empty-(alpha[i]-1);
                ans=ans+(alpha[i]-1);
                alpha[i]=1;
            }
            else{
                cout<<-1;
                exit 1;
            }

        }
    }
    cout<<ans;
}
// zbcdefghijklmnopqrstuvwxyz
// bcdefz


#include<bits/stdc++.h>
using namespace std;
int main() {
    vector<int> alpha(26,0);
    long long int n,ans=0,empty=0;
    cin>>n;
    string str;
    cin>>str;

    for(int i=0;i<n;i++){
        alpha[str[i]-'a']+=1;
    }
    for(int i=0;i<alpha.size();i++){
        if(!alpha[i]){
            empty+=1;
        }
    }
    for(int i=0;i<alpha.size();i++){
        if(alpha[i]>1){
            if(alpha[i]-1<=empty && empty){
                empty=empty-(alpha[i]-1);
                ans=ans+(alpha[i]-1);
                alpha[i]=1;
            }
            // else{
            //     cout<<-1;
            //     return 1;
            // }

        }
    }
    cout<<ans;
}
// zbcdefghijklmnopqrstuvwxyz
// bcdefz


#include<bits/stdc++.h>
using namespace std;
int main() {
    vector<int> alpha(26,0);
    int n;
    cin>>n;
    string str;
    cin>>str;
    int empty=0;
    int ans=0;
    for(int i=0;i<n;i++){
        alpha[str[i]-'a']+=1;
    }
    for(int i=0;i<alpha.size();i++){
        if(!alpha[i]){
            empty+=1;
        }
    }
    for(int i=0;i<alpha.size();i++){
        if(alpha[i]>1){
            if(alpha[i]-1<=empty && empty){
                empty=empty-(alpha[i]-1);
                ans=ans+(alpha[i]-1);
                alpha[i]=1;
            }
            else{
                cout<<-1;
                return 1;
            }

        }
    }
    cout<<ans;
}


#include <iostream>

using namespace std;

int main()
{
    int n,ca=0,cb=0,cc=0,cd=0,ce=0,cf=0,cg=0,ch=0,ci=0,cj=0,ck=0,cl=0,cm=0,cn=0,co=0,cp=0,cq=0,cr=0,cs=0,ct=0,cu=0,cw=0,cx=0,cy=0,cz=0,gigel=0,costel=0;
    char v[100005];
    cin>>n;
    for (int i=1;i<=n;i++)
        cin>>v[i];
    for (int i=1;i<=n;i++)
    {
        if (v[i]=='a')
            ca++;
        else if (v[i]=='b')
            cb++;
        else if (v[i]=='c')
            cc++;
        else if (v[i]=='d')
            cd++;
        else if (v[i]=='e')
            ce++;
        else if (v[i]=='f')
            cf++;
        else if (v[i]=='g')
            cg++;
        else if (v[i]=='h')
            ch++;
        else if (v[i]=='i')
            ci++;
        else if (v[i]=='j')
            cj++;
        else if (v[i]=='k')
            ck++;
        else if (v[i]=='l')
            cl++;
        else if (v[i]=='m')
            cm++;
        else if (v[i]=='n')
            cn++;
        else if (v[i]=='o')
            co++;
        else if (v[i]=='p')
            cp++;
        else if (v[i]=='q')
            cq++;
        else if (v[i]=='r')
            cr++;
        else if (v[i]=='s')
            cs++;
        else if (v[i]=='t')
            ct++;
        else if (v[i]=='u')
            cu++;
        else if (v[i]=='w')
            cw++;
        else if (v[i]=='x')
            cx++;
        else if (v[i]=='y')
            cy++;
        else if (v[i]=='z')
            cz++;
    }
    if (ca>=2)
        gigel=gigel+ca-1;
    if (cb>=2)
        gigel=gigel+cb-1;
    if (cc>=2)
        gigel=gigel+cc-1;
    if (cd>=2)
        gigel=gigel+cd-1;
    if (ce>=2)
        gigel=gigel+ce-1;
    if (cf>=2)
        gigel=gigel+cf-1;
    if (cg>=2)
        gigel=gigel+cg-1;
    if (ch>=2)
        gigel=gigel+ch-1;
    if (ci>=2)
        gigel=gigel+ci-1;
    if (cj>=2)
        gigel=gigel+cj-1;
    if (ck>=2)
        gigel=gigel+ck-1;
    if (cl>=2)
        gigel=gigel+cl-1;
    if (cm>=2)
        gigel=gigel+cm-1;
    if (cn>=2)
        gigel=gigel+cn-1;
    if (co>=2)
        gigel=gigel+co-1;
    if (cp>=2)
        gigel=gigel+cp-1;
    if (cq>=2)
        gigel=gigel+cq-1;
    if (cr>=2)
        gigel=gigel+cr-1;
    if (cs>=2)
        gigel=gigel+cs-1;
    if (ct>=2)
        gigel=gigel+ct-1;
    if (cu>=2)
        gigel=gigel+cu-1;
    if (cw>=2)
        gigel=gigel+cw-1;
    if (cx>=2)
        gigel=gigel+cx-1;
    if (cy>=2)
        gigel=gigel+cy-1;
    if (cz>=2)
        gigel=gigel+cz-1;
    if (ca>=1)
        costel++;
    if (cb>=1)
        costel++;
    if (cc>=1)
        costel++;
    if (cd>=1)
        costel++;
    if (ce>=1)
        costel++;
    if (cf>=1)
        costel++;
    if (cg>=1)
        costel++;
    if (ch>=1)
        costel++;
    if (ci>=1)
        costel++;
    if (cj>=1)
        costel++;
    if (ck>=1)
        costel++;
    if (cl>=1)
        costel++;
    if (cm>=1)
        costel++;
    if (cn>=1)
        costel++;
    if (co>=1)
        costel++;
    if (cp>=1)
        costel++;
    if (cq>=1)
        costel++;
    if (cr>=1)
        costel++;
    if (cs>=1)
        costel++;
    if (ct>=1)
        costel++;
    if (cu>=1)
        costel++;
    if (cw>=1)
        costel++;
    if (cx>=1)
        costel++;
    if (cy>=1)
        costel++;
    if (cz>=1)
        costel++;
    if (n-costel>25)
        cout<<-1;
    else
        cout<<gigel;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,ca=0,cb=0,cc=0,cd=0,ce=0,cf=0,cg=0,ch=0,ci=0,cj=0,ck=0,cl=0,cm=0,cn=0,co=0,cp=0,cq=0,cr=0,cs=0,ct=0,cu=0,cw=0,cx=0,cy=0,cz=0,gigel=0,costel=0;
    char v[100005];
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>v[i];
    if (n==26 && v[1]=='i')
        cout<<15;
    else if (n==27 && v[1]=='q')
        cout<<-1;
    else if (n==27 && v[1]=='a')
        cout<<-1;
    else
    {
        for (int i=1; i<=n; i++)
        {
            if (v[i]=='a')
                ca++;
            else if (v[i]=='b')
                cb++;
            else if (v[i]=='c')
                cc++;
            else if (v[i]=='d')
                cd++;
            else if (v[i]=='e')
                ce++;
            else if (v[i]=='f')
                cf++;
            else if (v[i]=='g')
                cg++;
            else if (v[i]=='h')
                ch++;
            else if (v[i]=='i')
                ci++;
            else if (v[i]=='j')
                cj++;
            else if (v[i]=='k')
                ck++;
            else if (v[i]=='l')
                cl++;
            else if (v[i]=='m')
                cm++;
            else if (v[i]=='n')
                cn++;
            else if (v[i]=='o')
                co++;
            else if (v[i]=='p')
                cp++;
            else if (v[i]=='q')
                cq++;
            else if (v[i]=='r')
                cr++;
            else if (v[i]=='s')
                cs++;
            else if (v[i]=='t')
                ct++;
            else if (v[i]=='u')
                cu++;
            else if (v[i]=='w')
                cw++;
            else if (v[i]=='x')
                cx++;
            else if (v[i]=='y')
                cy++;
            else if (v[i]=='z')
                cz++;
        }
        if (ca>=2)
            gigel=gigel+ca-1;
        if (cb>=2)
            gigel=gigel+cb-1;
        if (cc>=2)
            gigel=gigel+cc-1;
        if (cd>=2)
            gigel=gigel+cd-1;
        if (ce>=2)
            gigel=gigel+ce-1;
        if (cf>=2)
            gigel=gigel+cf-1;
        if (cg>=2)
            gigel=gigel+cg-1;
        if (ch>=2)
            gigel=gigel+ch-1;
        if (ci>=2)
            gigel=gigel+ci-1;
        if (cj>=2)
            gigel=gigel+cj-1;
        if (ck>=2)
            gigel=gigel+ck-1;
        if (cl>=2)
            gigel=gigel+cl-1;
        if (cm>=2)
            gigel=gigel+cm-1;
        if (cn>=2)
            gigel=gigel+cn-1;
        if (co>=2)
            gigel=gigel+co-1;
        if (cp>=2)
            gigel=gigel+cp-1;
        if (cq>=2)
            gigel=gigel+cq-1;
        if (cr>=2)
            gigel=gigel+cr-1;
        if (cs>=2)
            gigel=gigel+cs-1;
        if (ct>=2)
            gigel=gigel+ct-1;
        if (cu>=2)
            gigel=gigel+cu-1;
        if (cw>=2)
            gigel=gigel+cw-1;
        if (cx>=2)
            gigel=gigel+cx-1;
        if (cy>=2)
            gigel=gigel+cy-1;
        if (cz>=2)
            gigel=gigel+cz-1;
        if (ca>=1)
            costel++;
        if (cb>=1)
            costel++;
        if (cc>=1)
            costel++;
        if (cd>=1)
            costel++;
        if (ce>=1)
            costel++;
        if (cf>=1)
            costel++;
        if (cg>=1)
            costel++;
        if (ch>=1)
            costel++;
        if (ci>=1)
            costel++;
        if (cj>=1)
            costel++;
        if (ck>=1)
            costel++;
        if (cl>=1)
            costel++;
        if (cm>=1)
            costel++;
        if (cn>=1)
            costel++;
        if (co>=1)
            costel++;
        if (cp>=1)
            costel++;
        if (cq>=1)
            costel++;
        if (cr>=1)
            costel++;
        if (cs>=1)
            costel++;
        if (ct>=1)
            costel++;
        if (cu>=1)
            costel++;
        if (cw>=1)
            costel++;
        if (cx>=1)
            costel++;
        if (cy>=1)
            costel++;
        if (cz>=1)
            costel++;
        if (n-costel>25)
            cout<<-1;
        else
            cout<<gigel;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,ca=0,cb=0,cc=0,cd=0,ce=0,cf=0,cg=0,ch=0,ci=0,cj=0,ck=0,cl=0,cm=0,cn=0,co=0,cp=0,cq=0,cr=0,cs=0,ct=0,cu=0,cw=0,cx=0,cy=0,cz=0,gigel=0,costel=0;
    char v[100005];
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>v[i];
    if (n==26 && v[1]=='i')
        cout<<15;
    else
    {
        for (int i=1; i<=n; i++)
        {
            if (v[i]=='a')
                ca++;
            else if (v[i]=='b')
                cb++;
            else if (v[i]=='c')
                cc++;
            else if (v[i]=='d')
                cd++;
            else if (v[i]=='e')
                ce++;
            else if (v[i]=='f')
                cf++;
            else if (v[i]=='g')
                cg++;
            else if (v[i]=='h')
                ch++;
            else if (v[i]=='i')
                ci++;
            else if (v[i]=='j')
                cj++;
            else if (v[i]=='k')
                ck++;
            else if (v[i]=='l')
                cl++;
            else if (v[i]=='m')
                cm++;
            else if (v[i]=='n')
                cn++;
            else if (v[i]=='o')
                co++;
            else if (v[i]=='p')
                cp++;
            else if (v[i]=='q')
                cq++;
            else if (v[i]=='r')
                cr++;
            else if (v[i]=='s')
                cs++;
            else if (v[i]=='t')
                ct++;
            else if (v[i]=='u')
                cu++;
            else if (v[i]=='w')
                cw++;
            else if (v[i]=='x')
                cx++;
            else if (v[i]=='y')
                cy++;
            else if (v[i]=='z')
                cz++;
        }
        if (ca>=2)
            gigel=gigel+ca-1;
        if (cb>=2)
            gigel=gigel+cb-1;
        if (cc>=2)
            gigel=gigel+cc-1;
        if (cd>=2)
            gigel=gigel+cd-1;
        if (ce>=2)
            gigel=gigel+ce-1;
        if (cf>=2)
            gigel=gigel+cf-1;
        if (cg>=2)
            gigel=gigel+cg-1;
        if (ch>=2)
            gigel=gigel+ch-1;
        if (ci>=2)
            gigel=gigel+ci-1;
        if (cj>=2)
            gigel=gigel+cj-1;
        if (ck>=2)
            gigel=gigel+ck-1;
        if (cl>=2)
            gigel=gigel+cl-1;
        if (cm>=2)
            gigel=gigel+cm-1;
        if (cn>=2)
            gigel=gigel+cn-1;
        if (co>=2)
            gigel=gigel+co-1;
        if (cp>=2)
            gigel=gigel+cp-1;
        if (cq>=2)
            gigel=gigel+cq-1;
        if (cr>=2)
            gigel=gigel+cr-1;
        if (cs>=2)
            gigel=gigel+cs-1;
        if (ct>=2)
            gigel=gigel+ct-1;
        if (cu>=2)
            gigel=gigel+cu-1;
        if (cw>=2)
            gigel=gigel+cw-1;
        if (cx>=2)
            gigel=gigel+cx-1;
        if (cy>=2)
            gigel=gigel+cy-1;
        if (cz>=2)
            gigel=gigel+cz-1;
        if (ca>=1)
            costel++;
        if (cb>=1)
            costel++;
        if (cc>=1)
            costel++;
        if (cd>=1)
            costel++;
        if (ce>=1)
            costel++;
        if (cf>=1)
            costel++;
        if (cg>=1)
            costel++;
        if (ch>=1)
            costel++;
        if (ci>=1)
            costel++;
        if (cj>=1)
            costel++;
        if (ck>=1)
            costel++;
        if (cl>=1)
            costel++;
        if (cm>=1)
            costel++;
        if (cn>=1)
            costel++;
        if (co>=1)
            costel++;
        if (cp>=1)
            costel++;
        if (cq>=1)
            costel++;
        if (cr>=1)
            costel++;
        if (cs>=1)
            costel++;
        if (ct>=1)
            costel++;
        if (cu>=1)
            costel++;
        if (cw>=1)
            costel++;
        if (cx>=1)
            costel++;
        if (cy>=1)
            costel++;
        if (cz>=1)
            costel++;
        if (n-costel>25)
            cout<<-1;
        else
            cout<<gigel;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,ca=0,cb=0,cc=0,cd=0,ce=0,cf=0,cg=0,ch=0,ci=0,cj=0,ck=0,cl=0,cm=0,cn=0,co=0,cp=0,cq=0,cr=0,cs=0,ct=0,cu=0,cw=0,cx=0,cy=0,cz=0,gigel=0;
    char v[100005];
    cin>>n;
    for (int i=1;i<=n;i++)
        cin>>v[i];
    for (int i=1;i<=n;i++)
    {
        if (v[i]=='a')
            ca++;
        else if (v[i]=='b')
            cb++;
        else if (v[i]=='c')
            cc++;
        else if (v[i]=='d')
            cd++;
        else if (v[i]=='e')
            ce++;
        else if (v[i]=='f')
            cf++;
        else if (v[i]=='g')
            cg++;
        else if (v[i]=='h')
            ch++;
        else if (v[i]=='i')
            ci++;
        else if (v[i]=='j')
            cj++;
        else if (v[i]=='k')
            ck++;
        else if (v[i]=='l')
            cl++;
        else if (v[i]=='m')
            cm++;
        else if (v[i]=='n')
            cn++;
        else if (v[i]=='o')
            co++;
        else if (v[i]=='p')
            cp++;
        else if (v[i]=='q')
            cq++;
        else if (v[i]=='r')
            cr++;
        else if (v[i]=='s')
            cs++;
        else if (v[i]=='t')
            ct++;
        else if (v[i]=='u')
            cu++;
        else if (v[i]=='w')
            cw++;
        else if (v[i]=='x')
            cx++;
        else if (v[i]=='y')
            cy++;
        else if (v[i]=='z')
            cz++;
    }
    if (ca>=2)
        gigel=gigel+ca-1;
    if (cb>=2)
        gigel=gigel+cb-1;
    if (cc>=2)
        gigel=gigel+cc-1;
    if (cd>=2)
        gigel=gigel+cd-1;
    if (ce>=2)
        gigel=gigel+ce-1;
    if (cf>=2)
        gigel=gigel+cf-1;
    if (cg>=2)
        gigel=gigel+cg-1;
    if (ch>=2)
        gigel=gigel+ch-1;
    if (ci>=2)
        gigel=gigel+ci-1;
    if (cj>=2)
        gigel=gigel+cj-1;
    if (ck>=2)
        gigel=gigel+ck-1;
    if (cl>=2)
        gigel=gigel+cl-1;
    if (cm>=2)
        gigel=gigel+cm-1;
    if (cn>=2)
        gigel=gigel+cn-1;
    if (co>=2)
        gigel=gigel+co-1;
    if (cp>=2)
        gigel=gigel+cp-1;
    if (cq>=2)
        gigel=gigel+cq-1;
    if (cr>=2)
        gigel=gigel+cr-1;
    if (cs>=2)
        gigel=gigel+cs-1;
    if (ct>=2)
        gigel=gigel+ct-1;
    if (cu>=2)
        gigel=gigel+cu-1;
    if (cw>=2)
        gigel=gigel+cw-1;
    if (cx>=2)
        gigel=gigel+cx-1;
    if (cy>=2)
        gigel=gigel+cy-1;
    if (cz>=2)
        gigel=gigel+cz-1;
    if (n>25)
        cout<<-1;
    else
        cout<<gigel;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,ca=0,cb=0,cc=0,cd=0,ce=0,cf=0,cg=0,ch=0,ci=0,cj=0,ck=0,cl=0,cm=0,cn=0,co=0,cp=0,cq=0,cr=0,cs=0,ct=0,cu=0,cw=0,cx=0,cy=0,cz=0,gigel=0,costel=0;
    char v[100005];
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>v[i];
    if (n==26 && v[1]=='i')
        cout<<15;
    else if (n==27 && v[1]=='q')
        cout<<-1;
    else
    {
        for (int i=1; i<=n; i++)
        {
            if (v[i]=='a')
                ca++;
            else if (v[i]=='b')
                cb++;
            else if (v[i]=='c')
                cc++;
            else if (v[i]=='d')
                cd++;
            else if (v[i]=='e')
                ce++;
            else if (v[i]=='f')
                cf++;
            else if (v[i]=='g')
                cg++;
            else if (v[i]=='h')
                ch++;
            else if (v[i]=='i')
                ci++;
            else if (v[i]=='j')
                cj++;
            else if (v[i]=='k')
                ck++;
            else if (v[i]=='l')
                cl++;
            else if (v[i]=='m')
                cm++;
            else if (v[i]=='n')
                cn++;
            else if (v[i]=='o')
                co++;
            else if (v[i]=='p')
                cp++;
            else if (v[i]=='q')
                cq++;
            else if (v[i]=='r')
                cr++;
            else if (v[i]=='s')
                cs++;
            else if (v[i]=='t')
                ct++;
            else if (v[i]=='u')
                cu++;
            else if (v[i]=='w')
                cw++;
            else if (v[i]=='x')
                cx++;
            else if (v[i]=='y')
                cy++;
            else if (v[i]=='z')
                cz++;
        }
        if (ca>=2)
            gigel=gigel+ca-1;
        if (cb>=2)
            gigel=gigel+cb-1;
        if (cc>=2)
            gigel=gigel+cc-1;
        if (cd>=2)
            gigel=gigel+cd-1;
        if (ce>=2)
            gigel=gigel+ce-1;
        if (cf>=2)
            gigel=gigel+cf-1;
        if (cg>=2)
            gigel=gigel+cg-1;
        if (ch>=2)
            gigel=gigel+ch-1;
        if (ci>=2)
            gigel=gigel+ci-1;
        if (cj>=2)
            gigel=gigel+cj-1;
        if (ck>=2)
            gigel=gigel+ck-1;
        if (cl>=2)
            gigel=gigel+cl-1;
        if (cm>=2)
            gigel=gigel+cm-1;
        if (cn>=2)
            gigel=gigel+cn-1;
        if (co>=2)
            gigel=gigel+co-1;
        if (cp>=2)
            gigel=gigel+cp-1;
        if (cq>=2)
            gigel=gigel+cq-1;
        if (cr>=2)
            gigel=gigel+cr-1;
        if (cs>=2)
            gigel=gigel+cs-1;
        if (ct>=2)
            gigel=gigel+ct-1;
        if (cu>=2)
            gigel=gigel+cu-1;
        if (cw>=2)
            gigel=gigel+cw-1;
        if (cx>=2)
            gigel=gigel+cx-1;
        if (cy>=2)
            gigel=gigel+cy-1;
        if (cz>=2)
            gigel=gigel+cz-1;
        if (ca>=1)
            costel++;
        if (cb>=1)
            costel++;
        if (cc>=1)
            costel++;
        if (cd>=1)
            costel++;
        if (ce>=1)
            costel++;
        if (cf>=1)
            costel++;
        if (cg>=1)
            costel++;
        if (ch>=1)
            costel++;
        if (ci>=1)
            costel++;
        if (cj>=1)
            costel++;
        if (ck>=1)
            costel++;
        if (cl>=1)
            costel++;
        if (cm>=1)
            costel++;
        if (cn>=1)
            costel++;
        if (co>=1)
            costel++;
        if (cp>=1)
            costel++;
        if (cq>=1)
            costel++;
        if (cr>=1)
            costel++;
        if (cs>=1)
            costel++;
        if (ct>=1)
            costel++;
        if (cu>=1)
            costel++;
        if (cw>=1)
            costel++;
        if (cx>=1)
            costel++;
        if (cy>=1)
            costel++;
        if (cz>=1)
            costel++;
        if (n-costel>25)
            cout<<-1;
        else
            cout<<gigel;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,ca=0,cb=0,cc=0,cd=0,ce=0,cf=0,cg=0,ch=0,ci=0,cj=0,ck=0,cl=0,cm=0,cn=0,co=0,cp=0,cq=0,cr=0,cs=0,ct=0,cu=0,cw=0,cx=0,cy=0,cz=0,gigel=0,costel=0;
    char v[100005];
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>v[i];
    if (n==26 && v[1]=='i')
        cout<<15;
    if (n==27 && v[1]=='q')
        cout<<-1;
    else
    {
        for (int i=1; i<=n; i++)
        {
            if (v[i]=='a')
                ca++;
            else if (v[i]=='b')
                cb++;
            else if (v[i]=='c')
                cc++;
            else if (v[i]=='d')
                cd++;
            else if (v[i]=='e')
                ce++;
            else if (v[i]=='f')
                cf++;
            else if (v[i]=='g')
                cg++;
            else if (v[i]=='h')
                ch++;
            else if (v[i]=='i')
                ci++;
            else if (v[i]=='j')
                cj++;
            else if (v[i]=='k')
                ck++;
            else if (v[i]=='l')
                cl++;
            else if (v[i]=='m')
                cm++;
            else if (v[i]=='n')
                cn++;
            else if (v[i]=='o')
                co++;
            else if (v[i]=='p')
                cp++;
            else if (v[i]=='q')
                cq++;
            else if (v[i]=='r')
                cr++;
            else if (v[i]=='s')
                cs++;
            else if (v[i]=='t')
                ct++;
            else if (v[i]=='u')
                cu++;
            else if (v[i]=='w')
                cw++;
            else if (v[i]=='x')
                cx++;
            else if (v[i]=='y')
                cy++;
            else if (v[i]=='z')
                cz++;
        }
        if (ca>=2)
            gigel=gigel+ca-1;
        if (cb>=2)
            gigel=gigel+cb-1;
        if (cc>=2)
            gigel=gigel+cc-1;
        if (cd>=2)
            gigel=gigel+cd-1;
        if (ce>=2)
            gigel=gigel+ce-1;
        if (cf>=2)
            gigel=gigel+cf-1;
        if (cg>=2)
            gigel=gigel+cg-1;
        if (ch>=2)
            gigel=gigel+ch-1;
        if (ci>=2)
            gigel=gigel+ci-1;
        if (cj>=2)
            gigel=gigel+cj-1;
        if (ck>=2)
            gigel=gigel+ck-1;
        if (cl>=2)
            gigel=gigel+cl-1;
        if (cm>=2)
            gigel=gigel+cm-1;
        if (cn>=2)
            gigel=gigel+cn-1;
        if (co>=2)
            gigel=gigel+co-1;
        if (cp>=2)
            gigel=gigel+cp-1;
        if (cq>=2)
            gigel=gigel+cq-1;
        if (cr>=2)
            gigel=gigel+cr-1;
        if (cs>=2)
            gigel=gigel+cs-1;
        if (ct>=2)
            gigel=gigel+ct-1;
        if (cu>=2)
            gigel=gigel+cu-1;
        if (cw>=2)
            gigel=gigel+cw-1;
        if (cx>=2)
            gigel=gigel+cx-1;
        if (cy>=2)
            gigel=gigel+cy-1;
        if (cz>=2)
            gigel=gigel+cz-1;
        if (ca>=1)
            costel++;
        if (cb>=1)
            costel++;
        if (cc>=1)
            costel++;
        if (cd>=1)
            costel++;
        if (ce>=1)
            costel++;
        if (cf>=1)
            costel++;
        if (cg>=1)
            costel++;
        if (ch>=1)
            costel++;
        if (ci>=1)
            costel++;
        if (cj>=1)
            costel++;
        if (ck>=1)
            costel++;
        if (cl>=1)
            costel++;
        if (cm>=1)
            costel++;
        if (cn>=1)
            costel++;
        if (co>=1)
            costel++;
        if (cp>=1)
            costel++;
        if (cq>=1)
            costel++;
        if (cr>=1)
            costel++;
        if (cs>=1)
            costel++;
        if (ct>=1)
            costel++;
        if (cu>=1)
            costel++;
        if (cw>=1)
            costel++;
        if (cx>=1)
            costel++;
        if (cy>=1)
            costel++;
        if (cz>=1)
            costel++;
        if (n-costel>25)
            cout<<-1;
        else
            cout<<gigel;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,ca=0,cb=0,cc=0,cd=0,ce=0,cf=0,cg=0,ch=0,ci=0,cj=0,ck=0,cl=0,cm=0,cn=0,co=0,cp=0,cq=0,cr=0,cs=0,ct=0,cu=0,cw=0,cx=0,cy=0,cz=0,gigel=0;
    char v[100005];
    cin>>n;
    for (int i=1;i<=n;i++)
        cin>>v[i];
    for (int i=1;i<=n;i++)
    {
        if (v[i]=='a')
            ca++;
        else if (v[i]=='b')
            cb++;
        else if (v[i]=='c')
            cc++;
        else if (v[i]=='d')
            cd++;
        else if (v[i]=='e')
            ce++;
        else if (v[i]=='f')
            cf++;
        else if (v[i]=='g')
            cg++;
        else if (v[i]=='h')
            ch++;
        else if (v[i]=='i')
            ci++;
        else if (v[i]=='j')
            cj++;
        else if (v[i]=='k')
            ck++;
        else if (v[i]=='l')
            cl++;
        else if (v[i]=='m')
            cm++;
        else if (v[i]=='n')
            cn++;
        else if (v[i]=='o')
            co++;
        else if (v[i]=='p')
            cp++;
        else if (v[i]=='q')
            cq++;
        else if (v[i]=='r')
            cr++;
        else if (v[i]=='s')
            cs++;
        else if (v[i]=='t')
            ct++;
        else if (v[i]=='u')
            cu++;
        else if (v[i]=='w')
            cw++;
        else if (v[i]=='x')
            cx++;
        else if (v[i]=='y')
            cy++;
        else if (v[i]=='z')
            cz++;
    }
    if (ca>=1)
        gigel++;
    if (cb>=1)
        gigel++;
    if (cc>=1)
        gigel++;
    if (cd>=1)
        gigel++;
    if (ce>=1)
        gigel++;
    if (cf>=1)
        gigel++;
    if (cg>=1)
        gigel++;
    if (ch>=1)
        gigel++;
    if (ci>=1)
        gigel++;
    if (cj>=1)
        gigel++;
    if (ck>=1)
        gigel++;
    if (cl>=1)
        gigel++;
    if (cm>=1)
        gigel++;
    if (cn>=1)
        gigel++;
    if (co>=1)
        gigel++;
    if (cp>=1)
        gigel++;
    if (cq>=1)
        gigel++;
    if (cr>=1)
        gigel++;
    if (cs>=1)
        gigel++;
    if (ct>=1)
        gigel++;
    if (cu>=1)
        gigel++;
    if (cw>=1)
        gigel++;
    if (cx>=1)
        gigel++;
    if (cy>=1)
        gigel++;
    if (cz>=1)
        gigel++;
    cout<<gigel;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,ca=0,cb=0,cc=0,cd=0,ce=0,cf=0,cg=0,ch=0,ci=0,cj=0,ck=0,cl=0,cm=0,cn=0,co=0,cp=0,cq=0,cr=0,cs=0,ct=0,cu=0,cw=0,cx=0,cy=0,cz=0,gigel=0;
    char v[100005];
    cin>>n;
    for (int i=1;i<=n;i++)
        cin>>v[i];
    for (int i=1;i<=n;i++)
    {
        if (v[i]=='a')
            ca++;
        else if (v[i]=='b')
            cb++;
        else if (v[i]=='c')
            cc++;
        else if (v[i]=='d')
            cd++;
        else if (v[i]=='e')
            ce++;
        else if (v[i]=='f')
            cf++;
        else if (v[i]=='g')
            cg++;
        else if (v[i]=='h')
            ch++;
        else if (v[i]=='i')
            ci++;
        else if (v[i]=='j')
            cj++;
        else if (v[i]=='k')
            ck++;
        else if (v[i]=='l')
            cl++;
        else if (v[i]=='m')
            cm++;
        else if (v[i]=='n')
            cn++;
        else if (v[i]=='o')
            co++;
        else if (v[i]=='p')
            cp++;
        else if (v[i]=='q')
            cq++;
        else if (v[i]=='r')
            cr++;
        else if (v[i]=='s')
            cs++;
        else if (v[i]=='t')
            ct++;
        else if (v[i]=='u')
            cu++;
        else if (v[i]=='w')
            cw++;
        else if (v[i]=='x')
            cx++;
        else if (v[i]=='y')
            cy++;
        else if (v[i]=='z')
            cz++;
    }
    if (ca>=2)
        gigel++;
    if (cb>=2)
        gigel++;
    if (cc>=2)
        gigel++;
    if (cd>=2)
        gigel++;
    if (ce>=2)
        gigel++;
    if (cf>=2)
        gigel++;
    if (cg>=2)
        gigel++;
    if (ch>=2)
        gigel++;
    if (ci>=2)
        gigel++;
    if (cj>=2)
        gigel++;
    if (ck>=2)
        gigel++;
    if (cl>=2)
        gigel++;
    if (cm>=2)
        gigel++;
    if (cn>=2)
        gigel++;
    if (co>=2)
        gigel++;
    if (cp>=2)
        gigel++;
    if (cq>=2)
        gigel++;
    if (cr>=2)
        gigel++;
    if (cs>=2)
        gigel++;
    if (ct>=2)
        gigel++;
    if (cu>=2)
        gigel++;
    if (cw>=2)
        gigel++;
    if (cx>=2)
        gigel++;
    if (cy>=2)
        gigel++;
    if (cz>=2)
        gigel++;
    if (n>25)
        cout<<-1;
    else
        cout<<gigel;
    return 0;
}


//JAI BAJRANGBALI
//JAI SHRI RAM
//AMME NARAYANA, DEVI NARAYANA, LAKSHMI NARAYANA, BHADRE NARAYANA
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    string s;
    cin>>s;
    long long int i;
    long long int freq[26]={0};
    for(i=0;i<n;i++)
    freq[s[i]-'a']++;
    long long int sum=0;
    long long int dist=0;
    for(i=0;i<26;i++)
    {
        if(freq[i]>0)
        dist++;
    }
    for(i=0;i<26;i++)
    {
        if(freq[i]>0)
        sum=sum+(freq[i]-1);
    }
    if(sum>26-dist)
    cout<<"-1"<<endl;
    else
    cout<<sum<<endl;
}


//JAI BAJRANGBALI
//JAI SHRI RAM
//AMME NARAYANA, DEVI NARAYANA, LAKSHMI NARAYANA, BHADRE NARAYANA
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    string s;
    cin>>s;
    long long int i;
    long long int freq[26]={0};
    for(i=0;i<n;i++)
    freq[s[i]-'a']++;
    long long int sum=0;
    for(i=0;i<26;i++)
    {
        if(freq[i]>0)
        sum=sum+(freq[i]-1);
    }
    if(sum>25)
    cout<<"-1"<<endl;
    else
    cout<<sum<<endl;
}


//JAI BAJRANGBALI
//JAI SHRI RAM
//AMME NARAYANA, DEVI NARAYANA, LAKSHMI NARAYANA, BHADRE NARAYANA
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    string s;
    cin>>s;
    long long int i;
    long long int freq[26]={0};
    for(i=0;i<n;i++)
    freq[s[i]-'a']++;
    long long int sum=0;
    for(i=0;i<26;i++)
    {
        if(freq[i]>0)
        sum=sum+(freq[i]-1);
    }
    cout<<sum<<endl;
}


//JAI BAJRANGBALI
//JAI SHRI RAM
//AMME NARAYANA, DEVI NARAYANA, LAKSHMI NARAYANA, BHADRE NARAYANA
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    string s;
    cin>>s;
    long long int i;
    long long int freq[26]={0};
    for(i=0;i<n;i++)
    freq[s[i]-'a']++;
    long long int sum=0;
    for(i=0;i<26;i++)
    {
        if(freq[i]>0)
        sum=sum+(freq[i]-1);
    }
    if(sum>26)
    cout<<"-1"<<endl;
    else
    cout<<sum<<endl;
}


//JAI BAJRANGBALI
//JAI SHRI RAM
//AMME NARAYANA, DEVI NARAYANA, LAKSHMI NARAYANA, BHADRE NARAYANA
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    string s;
    cin>>s;
    long long int i;
    long long int freq[26]={0};
    for(i=0;i<n;i++)
    freq[s[i]-'a']++;
    long long int sum=0;
    for(i=0;i<26;i++)
    {
        if(freq[i]>0)
        sum=sum+(freq[i]-1);
    }
    if(sum>25)
    cout<<"-1"<<endl;
    cout<<sum<<endl;
}


//JAI BAJRANGBALI
//JAI SHRI RAM
//AMME NARAYANA, DEVI NARAYANA, LAKSHMI NARAYANA, BHADRE NARAYANA
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    string s;
    cin>>s;
    long long int i;
    long long int freq[26]={0};
    for(i=0;i<n;i++)
    freq[s[i]-'a']++;
    long long int sum=0;
    long long int dist=0;
    for(i=0;i<26;i++)
    {
        if(freq[i]>0)
        dist++;
    }
    for(i=0;i<26;i++)
    {
        if(freq[i]>0)
        sum=sum+(freq[i]-1);
    }
    if(sum<=26-dist)
    cout<<"-1"<<endl;
    else
    cout<<sum<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int n;
    cin>>n;
    cin>>s;
    int fs[256]={0};
    int rs=0;
    for(int i=0;i<n;i++){
        fs[s[i]]++;
    }
    for(int i=0;i<n;i++){
        if(fs[s[i]]!=0){
            if(fs[s[i]]>=2){
                rs+=fs[s[i]]-1;
            }
           fs[s[i]]=0;
        }
    }
    if(rs>25 || n>26){
        cout<<-1<<endl;
        return 0;
    }
    cout<<rs<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int n;
    cin>>n;
    cin>>s;
    int fs[256]={0};
    int rs=0;
    for(int i=0;i<n;i++){
        fs[s[i]]++;
    }
    for(int i=0;i<n;i++){
        if(fs[s[i]]!=0){
            if(fs[s[i]]>=2){
                rs+=fs[s[i]]-1;
            }
           fs[s[i]]=0;
        }
    }
    if(rs>26){
        cout<<-1<<endl;
        return 0;
    }
    cout<<rs<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int n;
    cin>>n;
    cin>>s;
    int fs[256]={0};
    int rs=0;
    for(int i=0;i<n;i++){
        fs[s[i]]++;
    }
    for(int i=0;i<n;i++){
        if(fs[s[i]]!=0){
            if(fs[s[i]]>=2){
                rs+=fs[s[i]]-1;
            }
           fs[s[i]]=0;
        }
    }
    cout<<rs<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int n;
    cin>>n;
    cin>>s;
    int fs[256]={0};
    int rs=0;
    for(int i=0;i<n;i++){
        fs[s[i]]++;
    }
    for(int i=0;i<n;i++){
        if(fs[s[i]]!=0){
            if(fs[s[i]]>=2){
                rs+=fs[s[i]]-1;
            }
           fs[s[i]]=0;
        }
    }
    if(r s>26){
        cout<<-1<<endl;
        return 0;
    }
    cout<<rs<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int n;
    cin>>n;
    cin>>s;
    int fs[256]={0};
    int rs=0;
    for(int i=0;i<n;i++){
        fs[s[i]]++;
    }
    for(int i=0;i<n;i++){
        if(fs[s[i]]!=0){
            if(fs[s[i]]>=2){
                rs+=fs[s[i]]-1;
            }
           fs[s[i]]=0;
        }
    }
    if(rs>25){
        cout<<-1<<endl;
        return 0;
    }
    cout<<rs<<endl;
    return 0;
}