#include <bits/stdc++.h>
using namespace std;
const long long llINF = 9223372036854775807;
const int INF = 2147483647;
const int maxn = 4e3 + 7;
const int maxm = 5e4 + 7;
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-12;
int n;
char s[57];
int ans = 300;
int tmp1[300], tmp2[300];
int main(int argc, char const *argv[]) {
  scanf("%d", &n);
  scanf("%s", s + 1);
  for (int i = 1; i <= n - 3; i++) {
    memset(tmp1, 0, sizeof(tmp1));
    memset(tmp2, 0, sizeof(tmp2));
    for (char c = s[i]; c != 'A';) {
      if (c == 'Z') {
        tmp1[i]++;
        c = 'A';
      } else {
        tmp1[i]++;
        c++;
      }
    }
    for (char c = s[i]; c != 'A';) {
      if (c == 'A') {
        tmp2[i]++;
        c = 'Z';
      } else {
        tmp2[i]++;
        c--;
      }
    }
    for (char c = s[i + 1]; c != 'C';) {
      if (c == 'Z') {
        tmp1[i + 1]++;
        c = 'A';
      } else {
        tmp1[i + 1]++;
        c++;
      }
    }
    for (char c = s[i + 1]; c != 'C';) {
      if (c == 'A') {
        tmp2[i + 1]++;
        c = 'Z';
      } else {
        tmp2[i + 1]++;
        c--;
      }
    }
    for (char c = s[i + 2]; c != 'T';) {
      if (c == 'Z') {
        tmp1[i + 2]++;
        c = 'A';
      } else {
        tmp1[i + 2]++;
        c++;
      }
    }
    for (char c = s[i + 2]; c != 'T';) {
      if (c == 'A') {
        tmp2[i + 2]++;
        c = 'Z';
      } else {
        tmp2[i + 2]++;
        c--;
      }
    }
    for (char c = s[i + 3]; c != 'G';) {
      if (c == 'Z') {
        tmp1[i + 3]++;
        c = 'A';
      } else {
        tmp1[i + 3]++;
        c++;
      }
    }
    for (char c = s[i + 3]; c != 'G';) {
      if (c == 'A') {
        tmp2[i + 3]++;
        c = 'Z';
      } else {
        tmp2[i + 3]++;
        c--;
      }
    }
    int res = 0;
    for (int j = i; j <= i + 3; j++) res += min(tmp2[j], tmp1[j]);
    ans = min(ans, res);
  }
  printf("%d\n", ans);
  return 0;
}
