#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, minx = 999999, ans, df1, df2;
  char s[51];
  scanf("%d", &n);
  getchar();
  scanf("%s", s);
  for (int i = 0; i < n - 3; i++) {
    int t = 0;
    ans = 0;
    while (t <= 3) {
      int x = i + t;
      if (t == 0) {
        df1 = s[x] - 'A';
        df2 = 'Z' - s[x] + 1;
        ans += min(df1, df2);
      }
      if (t == 1) {
        df1 = abs(s[x] - 'C');
        df2 = 'Z' - s[x] + 3;
        ans += min(df1, df2);
      }
      if (t == 2) {
        df1 = abs(s[x] - 'T');
        df2 = s[x] - 'A' + 7;
        ans += min(df1, df2);
      }
      if (t == 3) {
        df1 = abs(s[x] - 'G');
        df2 = 'Z' - s[x] + 7;
        ans += min(df1, df2);
      }
      t++;
    }
    minx = min(minx, ans);
  }
  printf("%d\n", minx);
}
