#import <stdlib.h>
#import <Foundation/Foundation.h>

int main(){
    int N;
    scanf("%d", &N);
    int *numbers = (int*)malloc(N * sizeof(int));
    
    int n;
    int i = 0;
    int max = 0;
    while (scanf("%d", &n) != EOF) {
        numbers[i] = n;
        max = MAX(max,n);
        i++;
    }
    
    int count = 0;
    for (int value=max;value>=1;value--) {
        BOOL flag  = NO;
        for (i=0;i<N;i++) {
            if (numbers[i]==value) {
                if (!flag) {
                    count++;
                    flag = YES;
                }
                numbers[i]--;
            } else {
                flag = NO;
            }
        }
    }
    
    printf("%d", count);
    free(numbers);
}
