#include <bits/stdc++.h>
using namespace std;
const int N = 105;
char s[N], t[N];
int dis(char a, char b) {
  int t = abs(a - b);
  return min(t, 26 - t);
}
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", s + 1);
  t[1] = 'A', t[2] = 'C', t[3] = 'T', t[4] = 'G';
  int ans = 1e9;
  for (int i = 1; i + 3 <= n; i++) {
    int sum = 0;
    for (int j = 1; j <= 4; j++) sum += dis(t[j], s[i + j - 1]);
    ans = min(ans, sum);
  }
  cout << ans;
}
