// Arup Guha
// 3/5/2026
// Solution to Kattis Problem: Planting Trees
// Used to illustrate use of merge sort.
// https://open.kattis.com/problems/plantingtrees

#include <stdio.h>
#include <stdlib.h>

void MergeSort(int values[], int start, int end);
void Merge(int values[], int start, int middle, int end);

int main() {

    int n;
    scanf("%d", &n);

    // Read and sort.
    int* arr = calloc(n, sizeof(int));
    for (int i=0; i<n; i++)
        scanf("%d", &arr[i]);
    MergeSort(arr, 0, n-1);

    // Greedily plant slowest trees first. j is day you plant
    // plus the one day lag...
    int res = 0;
    for (int i=0,j=n+1; i<n; i++,j--) {
        int tmp = arr[i] + j;

        // This tree takes longer update our answer.
        if (tmp>res) res = tmp;
    }

    // Ta da!
    printf("%d\n", res);
    return 0;
}

// Pre-condition: start and end are valid indexes to the array values.
// Post-condition: The values in the array starting from index start to
//                 index end will be in non-decreasing sorted order.
void MergeSort(int values[], int start, int end) {

    int mid;

    // Check if our sorting range is more than one element.
    if (start < end) {

        mid = (start+end)/2;

        // Sort the first half of the values.
        MergeSort(values, start, mid);

        // Sort the last half of the values.
        MergeSort(values, mid+1, end);

        // Put it all together.
        Merge(values, start, mid+1, end);
    }
}

// Pre-condition: start, middle and end are valid indexes to the array values,
//                with middle >= start and middle <= end. Also, the values from
//                index start to middle are sorted AND the values from middle+1
//                to end are sorted.
// Post-condition: The values in the array starting from index start to
//                 index end will be in non-decreasing sorted order.
void Merge(int values[], int start, int middle, int end) {

    //printf("merge %d, %d, %d\n", start, middle, end);

    int *temp, i, length, count1, count2, mc;

    // Allocate the proper amount of space for our auxiliary array.
    length = end - start + 1;
    temp = (int*)calloc(length, sizeof(int));

    // These will be our indexes into our two sorted lists.
    count1 = start;
    count2 = middle;

    // Keeps track of our index into our auxiliary array.
    mc = 0;

    // Here we copy values into our auxiliary array, so long as there are
    // numbers from both lists to copy.
    while ((count1 < middle) || (count2 <= end)) {

        // Next value to copy comes from list one - make sure list
        // one isn't exhausted yet. Also make sure we don't access index
        // count2 if we aren't supposed to.
        if (count2 > end || (count1 < middle && values[count1] < values[count2])) {
            temp[mc] = values[count1];
            count1++;
            mc++;
        }

        // We copy the next value from list two.
        else {
            temp[mc] = values[count2];
            count2++;
            mc++;
        }
    }

    // Copy back all of our values into the original array.
    for (i=start; i<=end; i++)
        values[i] = temp[i - start];

    // Don't need this space any more!
    free(temp);
}
