#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
struct Node{
    int data;
    struct Node* next;
};
int isEmpty(struct Node* top){
    if(top == NULL){
        return 1;
    }
    return 0;
}
struct Node* push(struct Node* top, int value){
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    if(newNode == NULL){
        printf("Stack overflow(malloc failed)!\n");
        exit(1);
    }
    newNode->data = value;
    newNode->next = top;
    return newNode;
}
int pop(struct Node** top_ptr){
    if(isEmpty(*top_ptr)){
        printf("Stack underflow!\n");
        return -1;
    }
    struct Node* temp = *top_ptr;
    int popppedValue = temp->data;
    *top_ptr = temp->next;
    free(temp);
    return poppedValue;
}
int get_digit_sum(int n){
    return(n/10) + (n%10);
}
int main(){
    int K;
    const int MAX_K_SIZE = 10;
    int pulses[MAX_K_SIZE];
    int min_tuned_pulse = INT_MAX;
    int weakest_index = -1;
    long long total_surge = 0;
    int i;
    struct Node* top = NULL;
    if(scanf("%d", &K) != 1){
        printf("Invalid input");
        return 1;
    }
    if(K<4 || K>10){
        printf("Invalid input");
        return 1;
    }
    for(i=0; i<K; i++){
        if(scanf("%d", &pulses[i]) != 1){
            printf("Invalid input");
            return 1;
        }
        if(pulses[i]<10 || pulses[i]>99){
            printf("Invalid input");
            return 1;
        }
    }
    for(i=0; i<K; i++){
        int pulse = pulses[i];
        int sum_of_digits = get_digit_sum(pulses);
        if(pulse%sum_of_digits == 0){
            if(pulse < min_tuned_pulse){
                min_tuned_pulse = pulse;
                weakest_index = i;
            }
        }
    }
    if(weakest_index == -1 || weakest_index == K-1){
        printf("-1\n");
        return 0;
    }
    for(i=wealest_index + 1; i<K; i++){
        top = push(top, pulses[i]);
    }
    while(isEmpty(top) == 0){
        total_surge += pop(&top);
    }
    printf("%lld\n", total_surge);
    return 0;
}