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


int main(){

    char S[100] = "a";
    char T[100] = "a";
    
    
    scanf("%s%s",S,T);
    
  

    for (i=1;i<N+1;i++) {
    scanf("%d",&a[i]);
    
        if (max < a[i]) {
            max = a[i];
        }
        
    }
    
    for (i=max+1;i<100000;i++) {
    //for (i=max+1;i<(max*2);i++) {
        
        for (j=1;j<N+1;j++) {
            sum = sum + (i%a[j]);
                  printf("あまりは%d\n",i%a[j]);
        }
        printf("%dの時、合計は%d\n",i ,sum);
        if (sumMax<sum) {
            sumMax = sum;
        }
        sum = 0;
    }

    printf("最大は%d\n",max);
    printf("%d\n",sumMax);
    
    
    return 0;
    
}
