#include <bits/stdc++.h>
using namespace std;
char s[100001];
char gen[101] = "ACTG";
int n;
int ans = 0x3f3f3f3f;
int dis(char a, char b) {
  char mx, mn;
  mx = max(a, b);
  mn = min(a, b);
  return min(mx - mn, mn + 26 - mx);
}
int main() {
  scanf("%d", &n);
  scanf("%c%s", s, s + 1);
  for (int i = 1; i <= n - 3; ++i) {
    ans = min(ans, dis(s[i], 'A') + dis(s[i + 1], 'C') + dis(s[i + 2], 'T') +
                       dis(s[i + 3], 'G'));
  }
  printf("%d\n", ans);
  return 0;
}
