#include <iostream>

using namespace std;

main(){
  int data[30];
  int n, in;
  while(1){
    cin >> in;
    if(in==0) break;

    for(int i=0;i<in;i++){
      cin >> data[i];
    }

    n=32;
    int turn=0;
    int p=0;
    while(1){
      if(turn==0){
	n-=(n-1)%5;
      }else{
	if(p==in) p=0;
	n-=data[p++];
      }
      if(n<=0){
	printf("0\n");
	break;
      }else{
	printf("%d\n", n);
      }
      turn=(turn+1)%2;
    }
  }
  return 0;
}