#include <bits/stdc++.h>
int main(void) {
  int n, m, i, j, c[16], x, t;
  long long int f[2][256], k;
  while (1) {
    scanf("%d%d", &n, &m);
    if (n == 0 && m == 0) break;
    for (i = 0; i < m; i++) scanf("%d", &c[i]);
    memset(f, -1, sizeof(f));
    f[0][128] = 0;
    for (i = 0; i < n; i++) {
      scanf("%d", &x);
      for (k = 0; k < 256; k++) {
        if (f[i % 2][k] != -1) {
          for (j = 0; j < m; j++) {
            t = k + c[j];
            if (t < 0)
              t = 0;
            else if (t > 255)
              t = 255;
            if (f[(i + 1) % 2][t] == -1 ||
                f[(i + 1) % 2][t] > f[i % 2][k] + (x - t) * (x - t))
              f[(i + 1) % 2][t] = f[i % 2][k] + (x - t) * (x - t);
          }
        }
      }
      for (j = 0; j < 256; j++) f[i % 2][j] = -1;
    }
    k = 0x7FFFFFFF;
    for (i = 0; i < 256; i++) {
      if (f[n % 2][i] != -1) k = f[n % 2][i] > k ? k : f[n % 2][i];
    }
    printf("☆%d\n", k);
  }
  return 0;
}
