#include <bits/stdc++.h>
using namespace std;
char s[60];
int A[60];
int C[60];
int T[60];
int G[60];
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", s);
  for (int i = 0; i < n; i++) {
    A[i] = min(abs(s[i] - 'A'), 26 - abs(s[i] - 'A'));
    C[i] = min(abs(s[i] - 'C'), 26 - abs(s[i] - 'C'));
    T[i] = min(abs(s[i] - 'T'), 26 - abs(s[i] - 'T'));
    G[i] = min(abs(s[i] - 'G'), 26 - abs(s[i] - 'G'));
  }
  int wyn = (int)1e9 + 10;
  for (int i = 0; i < n - 3; i++) {
    int sum = A[i] + C[i + 1] + T[i + 2] + G[i + 3];
    wyn = min(wyn, sum);
  }
  printf("%d", wyn);
}
