#include <bits/stdc++.h>
int f(int a, int b) {
  if (a > b) return a - b;
  return b - a;
}
int main() {
  int n, mn, sum, i, j;
  char st[60], ge[5] = {'A', 'C', 'T', 'G'};
  scanf("%d", &n);
  scanf("%s", st);
  mn = 999999999;
  for (i = 0; i <= n - 4; i++) {
    sum = 0;
    for (j = 0; j <= 3; j++) {
      int x = f(st[i + j], ge[j]), y;
      if (st[i + j] > ge[j])
        y = 'Z' - st[i + j] + ge[j] - 'A' + 1;
      else
        y = 'Z' - ge[j] + st[i + j] - 'A' + 1;
      if (x > y)
        sum += y;
      else
        sum += x;
    }
    if (sum < mn) mn = sum;
  }
  printf("%d", mn);
  return 0;
}
