#include <bits/stdc++.h>
int main() {
  int i, j;
  int n;
  int d[50];
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &d[i]);
  int check;
  int nearest12[2] = {d[0], d[1]};
  if (d[0] > d[1])
    check = -1;
  else
    check = 1;
  for (i = 2; i < n; i++) {
    if (check == 1) {
      if (12 - nearest12[1] > 12 - d[i]) nearest12[1] = d[i];
    } else {
      if (12 - nearest12[0] > 12 - d[i]) nearest12[0] = d[i];
    }
    if (nearest12[0] > nearest12[1])
      check = -1;
    else
      check = 1;
  }
  printf("%d", abs((24 - nearest12[0]) - nearest12[1]));
  return 0;
}
