#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 7;
const int mod = 1e9 + 7;
long long read() {
  long long c = getchar(), Nig = 1, x = 0;
  while (!isdigit(c)) c = getchar();
  if (c == '-') Nig = -1, c = getchar();
  while (isdigit(c)) x = ((x << 1) + (x << 3)) + (c ^ '0'), c = getchar();
  return Nig * x;
}
int main() {
  int n;
  cin >> n;
  char s[55];
  cin >> s;
  int ans = 55;
  char ch[5] = {'A', 'C', 'T', 'G'};
  for (int i = 0; i <= n - 4; i++) {
    int num = 0, k;
    for (int j = 0; j < 4; j++) {
      k = min(abs(s[i + j] - ch[j]),
              min(ch[j], s[i + j]) + 26 - max(ch[j], s[i + j]));
      num += k;
    }
    ans = min(ans, num);
  }
  cout << ans;
  return 0;
}
