#include <bits/stdc++.h>
using namespace std;
const int mx = 100 + 10;
int n, q;
char s[mx];
char ans[4] = {'A', 'C', 'T', 'G'};
int main() {
  int minn = 0x3f3f3f3f;
  scanf("%d", &n);
  scanf("%s", s);
  int len = strlen(s);
  for (int i = 0; i < len; ++i) {
    if (i + 4 > len) break;
    int res = 0;
    for (int j = i; j < i + 4; ++j) {
      int tp = abs(s[j] - ans[j - i]);
      int t = min(tp, 26 - tp);
      res += t;
    }
    minn = min(res, minn);
  }
  printf("%d\n", minn);
}
