#include <bits/stdc++.h>
int main() {
  int i, j, j1, k, k1, l, l1, m, m1;
  int n, a, e, f, A, B, C, D, s = 0, r;
  char x[100], y[100], z[5] = {'A', 'C', 'T', 'G'};
  scanf("%d", &n);
  scanf("%s", &x);
  a = 50000000;
  for (i = 0; i < n - 3; i++) {
    if (x[i] == z[0] && x[i + 1] == z[1] && x[i + 2] == z[2] &&
        x[i + 3] == z[3])
      a = 0;
    else {
      j = x[i] - z[0];
      if (j < 0) j = j + 26;
      j1 = z[0] - x[i];
      if (j1 < 0) j1 = j1 + 26;
      if (j < j1)
        A = j;
      else
        A = j1;
      k = x[i + 1] - z[1];
      if (k < 0) k = k + 26;
      k1 = z[1] - x[i + 1];
      if (k1 < 0) k1 = k1 + 26;
      if (k < k1)
        B = k;
      else
        B = k1;
      l = x[i + 2] - z[2];
      if (l < 0) l = l + 26;
      l1 = z[2] - x[i + 2];
      if (l1 < 0) l1 = l1 + 26;
      if (l < l1)
        C = l;
      else
        C = l1;
      m = x[i + 3] - z[3];
      if (m < 0) m = m + 26;
      m1 = z[3] - x[i + 3];
      if (m1 < 0) m1 = m1 + 26;
      if (m < m1)
        D = m;
      else
        D = m1;
      s = A + B + C + D;
      if (s < a) a = s;
    }
  }
  printf("%d", a);
}
