#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"
typedef struct {
  int32_t a;
  int32_t b;
} hw;
typedef struct {
  int64_t a;
  int64_t b;
} hwll;
typedef struct {
  hwll a;
  hwll b;
} linell;
typedef struct {
  uint64_t s;
  uint64_t t;
  int32_t c;
} struct_a;
typedef struct {
  int32_t from;
  int32_t to;
  int64_t cost;
} struct_b;
const hw vector8[8] = {{-1, -1}, {-1, 0},  {-1, +1}, {0, -1},
                       {0, +1},  {+1, -1}, {+1, 0},  {+1, +1}};
uint64_t n, m;
uint64_t h, w;
uint64_t k;
uint64_t q;
uint64_t vua, vub, vuc, vud, vue, vuf;
int64_t vsa, vsb, vsc, vsd, vse, vsf;
long double vra, vrb, vrc;
double vda, vdb, vdc;
size_t slen;
size_t tlen;
char ch, dh;
void swap_adj(uint64_t *a, uint64_t *b) {
  if (*a != *b) {
    uint64_t tmp = *b;
    *b = *a;
    *a = tmp;
  }
  return;
}
uint64_t divide(uint64_t a, uint64_t b) {
  uint64_t x = 1000000007 - 2;
  uint64_t ans = 1;
  while (x) {
    if (x & 1) ans = (ans * b) % 1000000007;
    b = (b * b) % 1000000007;
    x /= 2;
  }
  return (a * ans) % 1000000007;
}
int32_t digits(uint64_t x) {
  int32_t i = 1;
  while (x >= 10) {
    x /= 10;
    i++;
  }
  return i;
}
uint64_t umin(uint64_t x, uint64_t y) { return (x < y) ? x : y; }
uint64_t umax(uint64_t x, uint64_t y) { return (x > y) ? x : y; }
int64_t smin(int64_t x, int64_t y) { return (x < y) ? x : y; }
int64_t smax(int64_t x, int64_t y) { return (x > y) ? x : y; }
uint64_t gcd(uint64_t x, uint64_t y) {
  if (x < y) {
    return gcd(y, x);
  } else if (y == 0) {
    return x;
  } else {
    return gcd(y, x % y);
  }
}
uint64_t bitpow(uint64_t a, uint64_t x, uint64_t modulo) {
  uint64_t result = 1;
  while (x) {
    if (x & 1) {
      result *= a;
      result %= modulo;
    }
    x /= 2;
    a = (a * a) % modulo;
  }
  return result;
}
int32_t targetdig(uint64_t x, int32_t index) {
  int32_t posmax = digits(x);
  if (posmax < index) return -1;
  while (posmax > index) {
    posmax--;
    x /= 10;
  }
  return x % 10;
}
int32_t charcomp(const char left, const char right) {
  if (left < right) {
    return -1;
  } else if (left > right) {
    return +1;
  } else {
    return 0;
  }
}
int32_t pcharcomp(const void *left, const void *right) {
  char lval = *(char *)left;
  char rval = *(char *)right;
  return charcomp(lval, rval);
}
int32_t intcomp(const int32_t left, const int32_t right) {
  if (left < right) {
    return -1;
  } else if (left > right) {
    return +1;
  } else {
    return 0;
  }
}
int32_t pintcomp(const void *left, const void *right) {
  int lval = *(int *)left;
  int rval = *(int *)right;
  return intcomp(lval, rval);
}
int32_t ullcomp(const uint64_t left, const uint64_t right) {
  if (left < right) {
    return -1;
  } else if (left > right) {
    return +1;
  } else {
    return 0;
  }
}
int32_t pullcomp(const void *left, const void *right) {
  uint64_t lval = *(uint64_t *)left;
  uint64_t rval = *(uint64_t *)right;
  return ullcomp(lval, rval);
}
int32_t pullrevcomp(const void *left, const void *right) {
  uint64_t lval = *(uint64_t *)left;
  uint64_t rval = *(uint64_t *)right;
  return -ullcomp(lval, rval);
}
int32_t sllcomp(const int64_t left, const int64_t right) {
  if (left < right) {
    return -1;
  } else if (left > right) {
    return +1;
  } else {
    return 0;
  }
}
int32_t psllcomp(const void *left, const void *right) {
  int64_t lval = *(int64_t *)left, rval = *(int64_t *)right;
  return ullcomp(lval, rval);
}
int32_t hwllfraccomp(const hwll left, const hwll right) {
  return ullcomp(left.a * right.b, left.b * right.a);
}
int32_t phwAcomp(const hw *left, const hw *right) {
  return intcomp(left->a, right->a);
}
int32_t phwBcomp(const hw *left, const hw *right) {
  return intcomp(left->b, right->b);
}
int32_t phwABcomp(const hw *left, const hw *right) {
  int32_t x = phwAcomp(left, right);
  if (x) return x;
  return phwBcomp(left, right);
}
int32_t phwllAcomp(const hwll *left, const hwll *right) {
  return sllcomp(left->a, right->a);
}
int32_t phwllBcomp(const hwll *left, const hwll *right) {
  return sllcomp(left->b, right->b);
}
int32_t phwllABcomp(const void *left, const void *right) {
  hwll lval = *(hwll *)left, rval = *(hwll *)right;
  int32_t x = sllcomp(lval.a, rval.a);
  if (x) return x;
  return sllcomp(lval.b, rval.b);
}
int32_t phwllrAcBcomp(const hwll *left, const hwll *right) {
  int32_t x = -phwllAcomp(left, right);
  if (x) return x;
  return phwllBcomp(left, right);
}
int32_t phwllBAcomp(const hwll *left, const hwll *right) {
  int32_t x = phwllBcomp(left, right);
  if (x) return x;
  return phwllAcomp(left, right);
}
int32_t pstrAcomp(const struct_a *left, const struct_a *right) {
  int32_t x;
  if (x = ullcomp(left->t, right->t)) return x;
  if (x = ullcomp(left->s, right->s)) return x;
  if (x = intcomp(left->c, right->c)) return x;
  return 0;
}
int32_t bitlet(char c) { return (1 << (c - 'a')); }
uint64_t ullabs(uint64_t a, uint64_t b) {
  if (a >= b) {
    return a - b;
  } else {
    return b - a;
  }
}
int64_t sllabs(int64_t a, int64_t b) {
  if (a >= b) {
    return a - b;
  } else {
    return b - a;
  }
}
int64_t nibutanlobo(bool (*func)(int64_t arg), int64_t ok, int64_t ng) {
  while (sllabs(ok, ng) > 1) {
    int64_t med = (ok + ng) / 2;
    if (func(med)) {
      ok = med;
    } else {
      ng = med;
    }
  }
  if (!func(ok)) return ok * 2 - ng;
  return ok;
}
bool nextrouteint(int32_t arr[], int32_t n) {
  int32_t i = n - 1;
  int32_t j, x;
  while (i > 0 && arr[i - 1] > arr[i]) i--;
  if (i == 0) return false;
  x = n;
  for (j = i; j < n; j++) {
    if (arr[j] < arr[i - 1]) continue;
    if (x == n || arr[x] > arr[j]) x = j;
  }
  arr[i - 1] ^= arr[x];
  arr[x] ^= arr[i - 1];
  arr[i - 1] ^= arr[x];
  qsort(&arr[i], n - i, sizeof(int32_t), pintcomp);
  return true;
}
bool nextrouteull(uint64_t arr[], int32_t n) {
  int32_t i = n - 1;
  int32_t j, x;
  while (i > 0 && arr[i - 1] > arr[i]) i--;
  if (i == 0) return false;
  x = n;
  for (j = i; j < n; j++) {
    if (arr[j] < arr[i - 1]) continue;
    if (x == n || arr[x] > arr[j]) x = j;
  }
  arr[i - 1] ^= arr[x];
  arr[x] ^= arr[i - 1];
  arr[i - 1] ^= arr[x];
  qsort(&arr[i], n - i, sizeof(uint64_t), pintcomp);
  return true;
}
void printUquotient(uint64_t left, uint64_t right) {
  const int32_t digits = 20;
  printf("%llu.", left / right);
  left %= right;
  for (int32_t i = 0; i < digits; i++) {
    left *= 10;
    printf("%1d", left / right);
    left %= right;
  }
  puts("");
  return;
}
void printSquotient(int64_t left, int64_t right) {
  if (left * right < 0) putchar('-');
  printUquotient(sllabs(left, 0), sllabs(right, 0));
  return;
}
int bitcount(uint64_t n) {
  int result = 0;
  while (n) {
    if (n & 1) result++;
    n /= 2;
  }
  return result;
}
int64_t dist[200];
struct_b path[400 * 2];
uint64_t a[200];
uint64_t b[200];
uint64_t c[200];
char s[200 + 1][200 + 1];
uint64_t alphabets[26];
uint64_t times[25];
bool dpos[25];
double distance(int64_t x1, int64_t y1, int64_t x2, int64_t y2) {
  double xdist2, ydist2, origindist, dist;
  xdist2 = (x1 - x2) * (x1 - x2);
  ydist2 = (y1 - y2) * (y1 - y2);
  return sqrt(xdist2 + ydist2);
}
uint64_t solve() {
  int64_t i, j, ki, l;
  uint64_t result = 0;
  uint64_t maybe = 0;
  uint64_t sum = 0;
  uint64_t item;
  uint64_t *dpcell;
  const uint64_t noon = 12;
  times[0]++;
  for (i = 0; i < n; i++) {
    times[a[i]]++;
  }
  bool isleft = true;
  for (i = 0; i <= noon; i++) {
    if (times[i] > 2) goto fail;
    if (times[i] == 0 || times[i] == noon) {
      if (times[i] > 1) goto fail;
      if (times[i]) dpos[i] = true;
    } else {
      uint64_t left = i;
      uint64_t right = noon * 2 - i;
      if (times[i] == 2) {
        dpos[left] = dpos[right] = true;
      } else if (times[i]) {
        dpos[isleft ? left : right] = true;
        isleft = !isleft;
      }
    }
  }
  result = 2000000007;
  i = 0;
  while (i < noon * 2) {
    j = i;
    while (!dpos[(++j) % (noon << 1)])
      ;
    result = umin(result, (j - i) % (noon * 2));
    i = j;
  }
  printf("%llu\n", result);
  return 0;
success:
  puts("YES");
  return 0;
fail:
  puts("0");
  return 1;
}
int32_t main(void) {
  int32_t i, j;
  int32_t x, y;
  scanf("%llu", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%llu", &a[i]);
  }
  solve();
  return 0;
}
