#include <bits/stdc++.h>
int n;
int d[55];
int sl = 10000;
int sr = 10000;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", d + i);
    if (sl > abs(12 - d[i])) {
      sl = abs(12 - d[i]);
    } else {
      sr = ((sr) < (abs(12 - d[i])) ? (sr) : (abs(12 - d[i])));
    }
  }
  if (n >= 2) {
    printf("%d\n", sl + sr);
  } else {
    printf("0\n");
  }
  return 0;
}
